Notice that if I don’t type cast the operation to OperationObject, the code works. However, when I cast it, it fails with the following error:
test.ts:33:1 - error TS2322: Type 'OperationObject<{}>' is not assignable to type '({ tags?: string[] | undefined; summary?: string | undefined; description?: string | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 7 more ...; servers?: ServerObject[] | undefined; } & Omit<...> & { ...; }) | undefined'.
Type 'OperationObject<{}>' is not assignable to type '{ tags?: string[] | undefined; summary?: string | undefined; description?: string | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 7 more ...; servers?: ServerObject[] | undefined; } & Omit<...> & { ...; }'.
Type 'OperationObject<{}>' is not assignable to type '{ tags?: string[] | undefined; summary?: string | undefined; description?: string | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 7 more ...; servers?: ServerObject[] | undefined; }'.
Types of property 'requestBody' are incompatible.
Type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.ReferenceObject | import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.RequestBodyObje...' is not assignable to type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3.ReferenceObject | import("project/node_modules/openapi-types/dist/index").OpenAPIV3.RequestBodyObject |...'.
Type 'RequestBodyObject' is not assignable to type 'ReferenceObject | RequestBodyObject | undefined'.
Type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.RequestBodyObject' is not assignable to type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3.RequestBodyObject'.
Types of property 'content' are incompatible.
Type '{ [media: string]: import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.MediaTypeObject; }' is not assignable to type '{ [media: string]: import("project/node_modules/openapi-types/dist/index").OpenAPIV3.MediaTypeObject; }'.
'string' index signatures are incompatible.
Type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.MediaTypeObject' is not assignable to type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3.MediaTypeObject'.
Types of property 'schema' are incompatible.
Type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.ReferenceObject | import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.SchemaObject | ...' is not assignable to type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3.ReferenceObject | import("project/node_modules/openapi-types/dist/index").OpenAPIV3.SchemaObject | unde...'.
Type 'ArraySchemaObject' is not assignable to type 'ReferenceObject | SchemaObject | undefined'.
Type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.ArraySchemaObject' is not assignable to type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3.ArraySchemaObject'.
Types of property 'items' are incompatible.
Type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.ReferenceObject | import("project/node_modules/openapi-types/dist/index").OpenAPIV3_1.SchemaObject' is not assignable to type 'import("project/node_modules/openapi-types/dist/index").OpenAPIV3.ReferenceObject | import("project/node_modules/openapi-types/dist/index").OpenAPIV3.SchemaObject'.
Type 'ArraySchemaObject' is not assignable to type 'ReferenceObject | SchemaObject'.
33 schema.paths['/hello']['get'] = operation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The error is somewhat hard to read, but I believe the relevant part is:
Type 'OpenAPIV3_1.ReferenceObject OpenAPIV3_1.RequestBodyObje' is not assignable to type 'OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject |...'.
It seems to think that my Document is a 3.0 API spec environment, even though it was defined as a 3.1 document.
I am unable to assign an OperationObject to a PathItem. This is a minimal reproducible example:
Notice that if I don’t type cast the operation to OperationObject, the code works. However, when I cast it, it fails with the following error:
The error is somewhat hard to read, but I believe the relevant part is:
It seems to think that my Document is a 3.0 API spec environment, even though it was defined as a 3.1 document.
The example works with a 3.0 document: