You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parsing OpenAPI Schema exported from Stoplight fails for a valid schema. The maybeTypes uses include which only works for array or string inputs. Failed if the input is number (e.g. maybeTypes = [ 2, 4, 5 ] or maybeTypes = [ 'Record<string, never>', 1, 2, 3, 4, 5, 6, 7, 8, 9 ]).
$ npx openapi-typescript schema.yaml
file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/schema-object.js:55
if (maybeTypes.some((t) => t.includes("{")))
^
TypeError: t.includes is not a function
at file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/schema-object.js:55:63
at Array.some (<anonymous>)
at defaultSchemaObjectTransform (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/schema-object.js:55:49)
at transformSchemaObject (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/schema-object.js:3:20)
at defaultSchemaObjectTransform (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/schema-object.js:116:45)
at transformSchemaObject (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/schema-object.js:3:20)
at transformMediaTypeObject (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/media-type-object.js:5:12)
at transformRequestBodyObject (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/request-body-object.js:26:31)
at transformOperationObject (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/operation-object.js:79:37)
at transformPathItemObject (file:///Users/myuser/.npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/dist/transform/path-item-object.js:19:35)
Name
Version
openapi-typescript
6.2.0
Node.js
16.14.0
OS + version
macOS 13.1
Reproduction
Did not investigate which part exactly it was in the input. However, I could fix it locally by editing the code in dist/transform/schema-object.js: Original:
Exact, I ran the same issue and had the same conclusion. Another problem is if your oneOf have a const value which is 0 because of the condition if (schemaObject.const) which will be falsy even if it should not.
The diagnosis is the exact line of code failing, but we’d still need either the whole schema, or a small, individual schema object that throws this error. These kind of errors are obtuse, but they either stem from a) an invalid schema (most of the time) or b) an unexpected edge-case in the valid spec
The original message said the schema passed a validator. But we’d still need the failing schema object to fix the error properly (checking for string or array from your proposed solution may fix your individual issue, but likely wouldn’t fix any of the myriad other issues this would cause).
Closing this issue, but if you could provide the schema this erred on I’ll take a look. I’m 99% sure though this is from an error in your schema, and openapi-typescript just doesn’t provide a helpful error on the specific invalid bit. I’d suggest Redoc’s linter on the strictest settings to find the issue.
Description
Parsing OpenAPI Schema exported from Stoplight fails for a valid schema. The maybeTypes uses
include
which only works for array or string inputs. Failed if the input is number (e.g.maybeTypes = [ 2, 4, 5 ]
ormaybeTypes = [ 'Record<string, never>', 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
).openapi-typescript
6.2.0
16.14.0
macOS 13.1
Reproduction
Did not investigate which part exactly it was in the input. However, I could fix it locally by editing the code in
dist/transform/schema-object.js
:Original:
Fix:
Expected result
Runs without error.
Checklist
The text was updated successfully, but these errors were encountered: