swagger-typescript-api
swagger-typescript-api copied to clipboard
Unsupported swagger/OpenAPI version: 3.0
)
In node, can not support
I ran into the same issue. I found out that openapi version 3.0 is indeed supported, but the types don't reflect this.
However, simply passing an openapi3 spec works just fine. (I generate mine with @nestjs/swagger's SwaggerModule.createDocument) I just pass it and have to ts-expect-error on the spec property not matching.
The problematic definition is in generateApi's GenerateApiParamsFromSpecLiteral. This points only at a swagger-schema-official.Spec type, not allowing any openapi spec definitions:

Here's a snippet of my code:
// See https://docs.nestjs.com/openapi/introduction
const mySpec: OpenAPIObject = await SwaggerModule.createDocument(app, obj);
// Generate the API with the resulting spec
await generateApi({
output: `path/to/my/output/folder`,
// @ts-expect-error swagger-typescript-api has incorrect types for Spec. It DOES support
// an openapi v3 spec object (instead of swagger 2.0), but that is not reflected in the types.
spec: mySpec,
// and all the other options...
httpClientType: "axios",
defaultResponseAsSuccess: false,
// ...
});
@wardds hi, can you share example of spec property value?
Hey, my example at first was maybe not so clear, I updated it now. The resulting mySpec object follows the openapi 3.0.0 spec and is typed by nestjs as the following:
export interface OpenAPIObject {
openapi: string;
info: InfoObject;
servers?: ServerObject[];
paths: PathsObject;
components?: ComponentsObject;
security?: SecurityRequirementObject[];
tags?: TagObject[];
externalDocs?: ExternalDocumentationObject;
}
still the case
still the case in 13.0.3
@inomn try to rename "swagger" field to "openapi"
spec: {
// @ts-expect-error wrong library types for spec field with openapi 3
openapi: "3.0.0",
// ...
}
Looks like type error, spec can be objects OpenAPI 2 or OpenAPI 3. And they got different required fields.
Field swagger doesn't exist in Open API 3