https://github.com/workleap/wl-openapi-typescript
Code generator for OpenAPI schemas
https://github.com/workleap/wl-openapi-typescript
Last synced: about 1 year ago
JSON representation
Code generator for OpenAPI schemas
- Host: GitHub
- URL: https://github.com/workleap/wl-openapi-typescript
- Owner: workleap
- License: apache-2.0
- Created: 2024-06-03T19:36:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-07T02:46:15.000Z (about 1 year ago)
- Last Synced: 2025-04-07T03:30:29.392Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://workleap.github.io/wl-openapi-typescript/
- Size: 1.58 MB
- Stars: 2
- Watchers: 29
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# wl-openapi-typescript
[](./LICENSE)
[](https://github.com/gsoft-inc/wl-openapi-typescript/actions/workflows/ci.yml)
Tools to generate TypeScript schemas from OpenAPI. It leverage [openapi-typescript](https://github.com/drwpow/openapi-typescript) and re-export types in a more user friendly way.
## Packages
| Package | Version |
|-------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------|
| [@workleap/create-schemas](https://www.npmjs.org/package/@workleap/create-schemas)| [](https://www.npmjs.org/package/@workleap/create-schemas) |
## Usages
Add a script in package.json to call `@workleap/create-schemas`
```json
"scripts": {
"create-schemas": "create-schemas [path_or_public_url_to_openapi_document] -o [output_path] [optional_addition_flags]"
},
"devDependencies": {
"@workleap/create-schemas": "0.1.0"
}
```
It is also fowarding all the [flags of openapi-typescript](https://openapi-ts.pages.dev/cli#flags) for more customization. Note that not all flags are supported correctly.
If you plan to lookup paths with route parameters we recommend using the `--path-params-as-types` flag
### Example
Given this OpenAPI document:
```yaml
openapi: 3.0.1
info:
title: WebApi
version: '1.0'
paths:
/good-vibes-points:
get:
tags:
- GoodVibesBank
summary: Get the current number of good vibe for a user
operationId: GetGoodVibesPoint
parameters:
- name: userId
in: query
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/GetGoodVibePointsResult'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
components:
schemas:
GetGoodVibePointsResult:
required:
- point
type: object
properties:
point:
type: integer
format: int32
additionalProperties: false
ProblemDetails:
type: object
properties:
type:
type: string
nullable: true
title:
type: string
nullable: true
status:
type: integer
format: int32
nullable: true
detail:
type: string
nullable: true
instance:
type: string
nullable: true
additionalProperties: { }
```
It will generate this schema file:
```ts
// From openapi-typescript
export interface paths {
"/good-vibes-points": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Get the current number of good vibe for a user */
get: operations["GetGoodVibesPoint"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
}
export type webhooks = Record;
export interface components {
schemas: {
GetGoodVibePointsResult: {
/** Format: int32 */
point: number;
};
ProblemDetails: {
type?: string | null;
title?: string | null;
/** Format: int32 */
status?: number | null;
detail?: string | null;
instance?: string | null;
[key: string]: unknown;
};
};
responses: never;
parameters: never;
requestBodies: never;
headers: never;
pathItems: never;
}
export type $defs = Record;
export interface operations {
GetGoodVibesPoint: {
parameters: {
query: {
userId: string;
};
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Success */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["GetGoodVibePointsResult"];
};
};
/** @description Bad Request */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ProblemDetails"];
};
};
};
};
}
// From wl-openapi-typescript
export type GetGoodVibePointsResult = components["schemas"]["GetGoodVibePointsResult"];
export type ProblemDetails = components["schemas"]["ProblemDetails"];
export type Endpoints = keyof paths;
```
For more details on how to use see [openapi-typescript documentation](https://openapi-ts.pages.dev/introduction)
## Documentation
For documentations, please visit [our website](https://gsoft-inc.github.io/wl-openapi-typescript/).
The documentation is automatically generated on each release from the files in the docs directory.
## 🤝 Contributing
View the [contributor's documentation](./CONTRIBUTING.md).