Closed jiuyun01 closed 1 year ago
able to fix it by changing from:
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
to
type NonArraySchemaObjectType = boolean | object | number | string | integer;
But we also run into another similar issue:
Type '{ type: string; scheme: string; bearerFormat: string; }' is not assignable to type 'HttpSecurityScheme'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"http"'.
if we try to add securitySchemes
to components
:
securitySchemes: {
ClientAuthorizer: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT"
},
ClientAccountOwnerAuthorizer: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT"
}
},
Swagger 2.0 version has type defined to be:
type?: string | string[];
While openapi 3.0 one has type defined to be:
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
type?: NonArraySchemaObjectType;
That's why json version works for Swagger but not for Openapi one.
import apiDoc from "./api/api-doc";
...
async function initializeAPIs() {
await initialize({
apiDoc: apiDoc, //not working for openapi 3.0, but works for swagger 2.0
//apiDoc: resolve(__dirname, "./api/api-doc.yml"), //working for api-doc.yml
got it fixed in a simple way. We just explicitly declare it with the right type, instead of relying on compiling time type inference. Instead of
const apiDoc = {
we should do:
import { OpenAPIV3 } from 'openapi-types'
const apiDoc: OpenAPIV3.Document = {
with the following apiDoc for OAS 3.