Skip to content

TypeError: schemaObject.required?.includes is not a function #1931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
gamell opened this issue Sep 26, 2024 · 7 comments
Closed
1 of 2 tasks

TypeError: schemaObject.required?.includes is not a function #1931

gamell opened this issue Sep 26, 2024 · 7 comments
Assignees
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@gamell
Copy link

gamell commented Sep 26, 2024

Description

Getting TypeError: schemaObject.required?.includes is not a function when trying to generate types from a json OpenAPI 3.0 spec

joan.gamell@joangamell-MacBook-Pro ~/s/node-sdk (master) [1]> npx openapi-typescript https://docs.moov.io/openapi/openapi.json -o ./lib/_generated-types/types.ts
✨ openapi-typescript 7.4.1
(node:50364) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:292
                let optional = schemaObject.required?.includes(k) ||
                                                      ^

TypeError: schemaObject.required?.includes is not a function
    at transformSchemaObjectCore (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:292:55)
    at transformSchemaObjectWithComposition (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:112:28)
    at transformSchemaObject (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:6:18)
    at transformSchemaObjectCore (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:303:23)
    at transformSchemaObjectWithComposition (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:112:28)
    at transformSchemaObject (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/schema-object.js:6:18)
    at transformMediaTypeObject (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/media-type-object.js:7:12)
    at transformRequestBodyObject (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/request-body-object.js:15:15)
    at transformOperationObject (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/operation-object.js:13:15)
    at injectOperationObject (file:///Users/joan.gamell/src/node-sdk/node_modules/openapi-typescript/dist/transform/operation-object.js:38:18)

Node.js v22.1.0
Name Version
openapi-typescript 7.4.1
Node.js 22.1.0
OS + version macOS 14.4.1

Reproduction

npx openapi-typescript https://docs.moov.io/openapi/openapi.json -o ./lib/_generated-types/types.ts

Expected result

No errors, .ts file generated under lib/_generated-types

Checklist

@gamell gamell added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Sep 26, 2024
@lucasmcht
Copy link

I'm having the same issue, any news on this ?

@valerijmedvid
Copy link
Contributor

Same here

@dkacha
Copy link

dkacha commented Nov 22, 2024

I have the same problem with the same Node.js version.

(node:15420) [DEP0040] DeprecationWarning: The `punycode` 
module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:399:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:338:10)
    at loadBuiltinModule (node:internal/modules/helpers:114:7)
    at Function._load (node:internal/modules/cjs/loader:1100:17)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)     
    at Object.<anonymous> (D:\....\node_modules\whatwg-url\lib\url-state-machine.js:2:18)

@NDSo
Copy link

NDSo commented Nov 25, 2024

Make sure all of your schemas are defined correctly.

https://swagger.io/docs/specification/v3_0/data-models/data-types/#objects

Note the Required Properties section, it is very natural to write this incorrectly as shown in the example.

type: object
properties:
  id:
    type: integer
    required: true # Wrong!

required: # Correct
  - id

@dkacha
Copy link

dkacha commented Nov 26, 2024

@NDSo The schemas are correctly defined, and the issue seems to be specific to the Node.js version. It works as expected with Node.js 20.11.1 but does not work with Node.js 22.11.0.

This might be related to the use of whatwg-url, as discussed here:
Stack Overflow: Punycode is deprecated in npm - what should I replace it with?

Here’s the dependency tree for whatwg-url in my setup:

npm ls whatwg-url
[email protected] D:\Users\992393p\Documents\Modra\foms
└─┬ [email protected]
  └─┬ @redocly/[email protected]
    └─┬ [email protected]
      └── [email protected]

@valerijmedvid
Copy link
Contributor

No more errors after the release of the new version 7.6.1 with the updated redocly library.

@gzm0
Copy link
Contributor

gzm0 commented Feb 19, 2025

Fixed in #2131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
Development

No branches or pull requests

6 participants