Skip to content
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

openapi-parser: Unsupported OpenAPI version: 3.0.4 #923

Open
jnv opened this issue Jan 8, 2025 · 0 comments
Open

openapi-parser: Unsupported OpenAPI version: 3.0.4 #923

jnv opened this issue Jan 8, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@jnv
Copy link

jnv commented Jan 8, 2025

Ideally I'd raise this issue against openapi-parser repo, but it doesn't have issues enabled, so I report it here.

Steps to reproduce

Create the following files:

package.json

{
  "name": "repro",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "oas": "^25.2.1",
    "oas-normalize": "^12.0.0"
  }
}
// index.js
import OASNormalize from 'oas-normalize';

const yaml = `
openapi: 3.0.4
info:
  version: 1.0.0
  title: Petstore simple w/o tags
servers:
  - url: https://httpbin.org
paths:
  '/pet/{id}':
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
    get:
      summary: Find a pet
      description: This operation will find a pet in the database.
      responses:
        '400':
          description: Invalid status value
      security: []
`;

const oas = new OASNormalize(yaml);
const definition = await oas.validate();

Install and run:

npm install
node index.js

Expected result

The script would run without any issues.

Actual result

The script crashes with error:

SyntaxError: Unsupported OpenAPI version: 3.0.4. Swagger Parser only supports versions 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0
    at OpenAPIParser.parse (/path/to/repro/node_modules/@readme/openapi-parser/lib/index.js:95:19)
    at async OpenAPIParser.resolve (/path/to/repro/node_modules/@readme/json-schema-ref-parser/lib/index.js:189:5)
    at async OpenAPIParser.dereference (/path/to/repro/node_modules/@readme/json-schema-ref-parser/lib/index.js:271:5)
    at async OpenAPIParser.validate (/path/to/repro/node_modules/@readme/openapi-parser/lib/index.js:152:5)
    at async file:///path/to/repro/repro.js:28:20 {
  toJSON: [Function: toJSON],
  [Symbol(nodejs.util.inspect.custom)]: [Function: inspect]
}

Node.js v23.5.0

Notes

Support for the latest minor versions of OAS was quite recently fixed in the upstream openapi-parser: APIDevTools/swagger-parser#264

Since there are no functional changes in the latest versions, it's really only about adding support for the newer versions.

As a very ugly workaround, I can (sometimes) modify the OAS before parsing, e.g. for the example above:

// yaml = ...
const fixedYaml = yaml.replace(/^openapi:\s*3\.0\.4/m, 'openapi: 3.0.3');

const oas = new OASNormalize(fixedYaml);
const definition = await oas.validate();
@erunion erunion self-assigned this Jan 8, 2025
@erunion erunion added the enhancement New feature or request label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants