openapi-contrib / openapi-schema-to-json-schema

Due to the OpenAPI v3.0 and JSON Schema discrepancy, you can use this JS library to convert OpenAPI Schema objects to proper JSON Schema.
https://www.npmjs.com/package/@openapi-contrib/openapi-schema-to-json-schema
MIT License
242 stars 20 forks source link

3.3.0 causing ts compilation to fail #54

Closed steve-baldwin closed 1 year ago

steve-baldwin commented 1 year ago

We tried to upgrade from 3.2.0 to 3.3.0 and now have typescript compilation issues. For example:

[~/git/unsullied] yarn ts-node
yarn run v1.22.19
$ /Users/stbaldwin/git/unsullied/node_modules/.bin/ts-node
> const toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema');
/Users/stbaldwin/git/unsullied/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js:851
undefined
                   ^

Uncaught:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/stbaldwin/git/unsullied/node_modules/lodash-es/lodash.js from /Users/stbaldwin/git/unsullied/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js not supported.
Instead change the require of lodash.js in /Users/stbaldwin/git/unsullied/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js to a dynamic import() which is available in all CommonJS modules.
:

Our tsconfig.json:

{
    "compilerOptions": {
        "allowJs": false,
        "module": "commonjs",
        "declaration": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "strict": true,
        "suppressImplicitAnyIndexErrors": true,
        "ignoreDeprecations": "5.0",
        "target": "es2020",
        "lib": ["es2020"],
        "sourceMap": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "paths": {
            "@/*": ["src/*"],
            "*": ["src/typings/*"]
        }
    },
    "exclude": ["node_modules", "aurora", "build", "dist", "dev-tools"]
}

Thanks,

Steve

fidgi commented 1 year ago

@steve-baldwin Add "overrides": { "@openapi-contrib/openapi-schema-to-json-schema": "3.2.0" }, to your package.json as a temporary workaround

thomaswmanion commented 1 year ago

This breaking change is causing @asyncapi/cli to fail, too, FYI

Duvier-Reinosa commented 1 year ago

I.m using @loop/rest and it require openapi-contrib/openapi-schema-to-json-schema but with ultimate version i have this error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /srv/api-stage.techfitds.com/node_modules/lodash-es/lodash.js from /srv/api-stage.techfitds.com/node_modules/@loopback/rest/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js not supported. 0|. | Instead change the require of lodash.js in /srv/api-stage.techfitds.com/node_modules/@loopback/rest/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js to a dynamic import() which is available in all CommonJS modules.

shubhamp-sf commented 1 year ago

Dear maintainers, This is critical issue; dozens of packages depending on this will fail. Can you guys revert this please?

cc: @philsturgeon @jonluca

jonluca commented 1 year ago

Looking into this now, will push a fix soon