Describe the bug
swagger-typescript-api crashes when the OpenAPI schema contains not: {}.
This works in 13.0.28, but fails in 13.12.2.
Minimal repro
Repro spec:
{
"openapi": "3.0.3",
"info": {
"title": "swagger-typescript-api not repro",
"version": "1.0.0"
},
"paths": {},
"components": {
"schemas": {
"RelatedProductVariant": {
"type": "object",
"properties": {
"variantId": {
"type": "integer"
},
"variantReferenceKey": {
"type": "string"
},
"isMainVariant": {
"type": "boolean"
}
}
},
"ProductVariant": {
"type": "object",
"properties": {
"relatedVariants": {
"oneOf": [
{
"type": "array",
"minItems": 1,
"items": {
"allOf": [
{
"$ref": "#/components/schemas/RelatedProductVariant"
},
{
"type": "object",
"required": [
"variantId",
"isMainVariant"
],
"properties": {
"variantId": {
"type": "integer"
},
"variantReferenceKey": {
"not": {}
}
}
}
]
}
},
{
"type": "array",
"minItems": 1,
"items": {
"allOf": [
{
"$ref": "#/components/schemas/RelatedProductVariant"
},
{
"type": "object",
"required": [
"variantReferenceKey",
"isMainVariant"
],
"properties": {
"variantReferenceKey": {
"type": "string"
},
"variantId": {
"not": {}
}
}
}
]
}
}
]
}
}
}
}
}
}
Command:
swagger-typescript-api generate \
--axios \
-p ./docs/swagger-typescript-api-not-repro.json \
-o ./tmp/generated \
-n api.ts
Current behavior
13.12.2 throws:
TypeError: (this.schema[complexType] || []).map is not a function
at ComplexSchemaParser.parse (...)
Expected behavior
The generator should not crash on not: {}.
If this schema shape is unsupported, a clear validation error would still be much better than a runtime exception.
Version info
Fails:
swagger-typescript-api@13.12.2
Works:
swagger-typescript-api@13.0.28
Suspected cause
It looks like ComplexSchemaParser handles not as a complex schema, but later assumes the complex schema value is array-like when building the description.
13.0.28 uses Lodash:
lodash.map(this.schema[complexType], "description")
That safely returns [] for not: {}.
13.12.2 uses native .map(...):
(this.schema[complexType] || []).map((item) => item?.description)
For not: {}, that becomes {} and throws because {} does not have .map.
Additional context
In a larger real-world spec, removing only the two not: {} entries made generation succeed, which seems to confirm this is the direct trigger.
Relevant source
Describe the bug
swagger-typescript-apicrashes when the OpenAPI schema containsnot: {}.This works in
13.0.28, but fails in13.12.2.Minimal repro
Repro spec:
{ "openapi": "3.0.3", "info": { "title": "swagger-typescript-api not repro", "version": "1.0.0" }, "paths": {}, "components": { "schemas": { "RelatedProductVariant": { "type": "object", "properties": { "variantId": { "type": "integer" }, "variantReferenceKey": { "type": "string" }, "isMainVariant": { "type": "boolean" } } }, "ProductVariant": { "type": "object", "properties": { "relatedVariants": { "oneOf": [ { "type": "array", "minItems": 1, "items": { "allOf": [ { "$ref": "#/components/schemas/RelatedProductVariant" }, { "type": "object", "required": [ "variantId", "isMainVariant" ], "properties": { "variantId": { "type": "integer" }, "variantReferenceKey": { "not": {} } } } ] } }, { "type": "array", "minItems": 1, "items": { "allOf": [ { "$ref": "#/components/schemas/RelatedProductVariant" }, { "type": "object", "required": [ "variantReferenceKey", "isMainVariant" ], "properties": { "variantReferenceKey": { "type": "string" }, "variantId": { "not": {} } } } ] } } ] } } } } } }Command:
Current behavior
13.12.2throws:Expected behavior
The generator should not crash on
not: {}.If this schema shape is unsupported, a clear validation error would still be much better than a runtime exception.
Version info
Fails:
swagger-typescript-api@13.12.2Works:
swagger-typescript-api@13.0.28Suspected cause
It looks like
ComplexSchemaParserhandlesnotas a complex schema, but later assumes the complex schema value is array-like when building the description.13.0.28uses Lodash:That safely returns
[]fornot: {}.13.12.2uses native.map(...):For
not: {}, that becomes{}and throws because{}does not have.map.Additional context
In a larger real-world spec, removing only the two
not: {}entries made generation succeed, which seems to confirm this is the direct trigger.Relevant source
13.0.28: https://raw.githubusercontent.com/acacode/swagger-typescript-api/13.0.28/src/schema-parser/base-schema-parsers/complex.ts13.12.2: https://raw.githubusercontent.com/acacode/swagger-typescript-api/v13.12.2/src/schema-parser/base-schema-parsers/complex.ts