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

Examples with same ID causes error #773

Closed
HairyMike opened this issue Nov 23, 2022 · 3 comments
Closed

Examples with same ID causes error #773

HairyMike opened this issue Nov 23, 2022 · 3 comments

Comments

@HairyMike
Copy link
Contributor

HairyMike commented Nov 23, 2022

Describe the bug
Seems like examples rely on an internal 'id' field to identify them within the express-openapi-validator lib. If you have multiple examples, and they share the same ID - requests to your API error out.

Example open-api doc here: https://github.com/HairyMike/bug-express-openapi-validator/blob/master/openapi.yaml

You will get a response like this:

Error: reference "1234" resolves to more than one schema

To Reproduce

git clone git@github.com:HairyMike/bug-express-openapi-validator.git
cd bug-express-openapi-validator.git & npm i & node index.js &
curl http://localhost:3000/v1/test

Actual behavior
I get the following message:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: reference &quot;1234&quot; resolves to more than one schema<br> &nbsp; &nbsp;at ambiguos (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/ajv/dist/compile/resolve.js:151:16)<br> &nbsp; &nbsp;at Ajv.addRef (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/ajv/dist/compile/resolve.js:118:23)<br> &nbsp; &nbsp;at /Users/michael.eller/nodejs/bug-open-api-validator/node_modules/ajv/dist/compile/resolve.js:109:29<br> &nbsp; &nbsp;at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:69:5)<br> &nbsp; &nbsp;at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)<br> &nbsp; &nbsp;at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)<br> &nbsp; &nbsp;at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)<br> &nbsp; &nbsp;at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)<br> &nbsp; &nbsp;at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)<br> &nbsp; &nbsp;at module.exports (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:14:3)</pre>
</body>
</html>
Error: reference "1234" resolves to more than one schema
    at ambiguos (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/ajv/dist/compile/resolve.js:151:16)
    at Ajv.addRef (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/ajv/dist/compile/resolve.js:118:23)
    at /Users/michael.eller/nodejs/bug-open-api-validator/node_modules/ajv/dist/compile/resolve.js:109:29
    at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:69:5)
    at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)
    at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)
    at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)
    at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)
    at _traverse (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:83:9)
    at module.exports (/Users/michael.eller/nodejs/bug-open-api-validator/node_modules/json-schema-traverse/index.js:14:3)

Expected behavior
Should see:

hello world

Examples and context
This is the open-api snippet that is causing the issue. Note the identical IDs:

components:
  schemas:
    ExampleResponse:
      type: object
  examples:
    FirstExample:
      value:
        title: Bug Example
        description: Error example (same ID as other example), but valid open-api document
        content:
          id: '1234'
    SecondExample:
      value:
        title: Bug Example
        description: Error example (same ID as other example), but valid open-api document
        content:
          id: '1234'
@HairyMike
Copy link
Contributor Author

@javier-sierra-sngular
Copy link

The problem still keeps occurring. Is there any chance that some maintainer could apply the idea from the PR to all examples?

As mentioned in this comment , the PR only remove top level examples under components.

Thanks

@cdimascio
Copy link
Owner

fixed by #890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants