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

Fails to parse openapi schema #11

Open
alexspurling opened this issue Nov 16, 2021 · 6 comments
Open

Fails to parse openapi schema #11

alexspurling opened this issue Nov 16, 2021 · 6 comments

Comments

@alexspurling
Copy link

alexspurling commented Nov 16, 2021

I have the following dummy openapi schema adapted from a json schema generated by a real API. This schema cannot be parsed by openapi-fuzzer 0.1.3 (built from master commit 7da1471)

Schema:

{
  "openapi": "3.0.2",
  "info": {
    "title": "Example",
    "description": "Example",
    "version": "0.0.1"
  },
  "paths": {
    "/foo": {
      "get": {
        "operationId": "getFoo",
        "summary": "Get list of foo",
        "description": "Returns all the foo",
        "produces": [
          "application/json"
        ]
      }
    }
  }
}

Error:

$ openapi-fuzzer -s ~/code/openapi.json -u http://localhost
Error: Failed to parse schema

Caused by:
    paths: data did not match any variant of untagged enum ReferenceOr at line 8 column 12
@matusf
Copy link
Owner

matusf commented Nov 16, 2021

Hi, I checked the schema with https://editor.swagger.io/ and according to it, the schema is not valid.
image

@alexspurling
Copy link
Author

alexspurling commented Nov 16, 2021

Thanks. I stripped out the responses field because I got the same error with or without it. It appears that the produces field was the actual cause of the parse failure. Unfortunately, the error message does not give any hints as to the reason for the parse failure.

This modified example does work:

{
  "openapi": "3.0.2",
  "info": {
    "title": "Example",
    "description": "Example",
    "version": "0.0.1"
  },
  "paths": {
    "/foo": {
      "get": {
        "operationId": "getFoo",
        "summary": "Get list of foo",
        "description": "Returns all the foo",
        "responses": {
          "200": {
            "description": "foo",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  }
}

@leofvo
Copy link

leofvo commented Mar 6, 2023

Hey, as shown in the code the openApi file should be in yaml...

We should improve the error handling and maybe support json format.

@matusf
Copy link
Owner

matusf commented Mar 6, 2023

JSON format is not the issue. YAML is a superset of JSON.

@leofvo
Copy link

leofvo commented Mar 6, 2023

JSON format is not the issue. YAML is a superset of JSON.

Damn, didn't know about that. Thanks for this tips :)

@qarmin
Copy link

qarmin commented Jul 31, 2023

Can this error be ignored by using less restrictive openapi parser?

According to https://editor.swagger.io/ looks that fastapi produces invalid openapi.json, but still usable locally on my pc(swagger-ui not shows any errors).

Fixing errors manually would take too much time.

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

4 participants