@let-aurn/swagger-client
v0.1.0
Published
Generate typed Angular and React clients from OpenAPI JSON files.
Maintainers
Readme
Swagger Client
Generate typed Angular and React clients from OpenAPI JSON files.
npx swagger-client generate
npx swagger-client generate --config=swagger-client.jsonConfig
{
"client": "angular",
"swaggers-directory": "path/to/swaggers",
"endpoint-name-strategy": "operationId",
"output": {
"api-models.ts": "src/app/api/generated/api-models.ts",
"api-endpoints.ts": "src/app/api/generated/api-endpoints.ts",
"client.ts": "src/app/api/generated/swagger-client.ts"
}
}client can be angular or react.
endpoint-name-strategy is optional:
operationIduses the OpenAPIoperationIdas-is. This is the default.tagAndOperationIdprefixes endpoint exports with the first OpenAPI tag, unless theoperationIdalready starts with that tag.
With tagAndOperationId, an operation tagged SomeController with operationId: "someEndpoint" is generated as:
ApiEndpoints.SomeController_someEndpointAngular
bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(),
provideSwaggerClient({
baseUrl: 'https://api.example.com'
})
]
});Custom HTTP implementations are supported:
provideSwaggerClient({
baseUrl: 'https://api.example.com',
httpClient: MySwaggerHttpClient
});React
const client = useSwaggerClient(ApiEndpoints.PostsController_getPost, {
baseUrl: 'https://api.example.com'
});
const post = await client.request({
pathVariables: { id: 123 }
});