Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

[BUG] Null pointer exception thrown when openapi doc has no components #259

Closed
6 tasks
spacether opened this issue Oct 24, 2023 · 2 comments · Fixed by #260
Closed
6 tasks

[BUG] Null pointer exception thrown when openapi doc has no components #259

spacether opened this issue Oct 24, 2023 · 2 comments · Fixed by #260

Comments

@spacether
Copy link
Contributor

spacether commented Oct 24, 2023

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request
Description

Opening this issue per: #237 (comment)

Reported by @robin-nitrokey

Thanks! I tried to use 3.2.0 but it does not work for me:

  • On the nethsm-sdk-py codebase, it does not generate path parameters.
  • On the example from this issue, it causes a NullPointerException.
  • On Example 1, it does not generate the path parameters either.
  • On Example 2, I again get a NullPointerException.

Am I missing something?

Example 1
openapi: 3.0.0
info:
  title: NetHSM
  version: v1
servers:
  - url: https://{host}/api/{version}
    variables:
      host:
        default: localhost:8443
      version:
        default: v1
paths:
  /users/{UserID}:
    parameters:
      - name: UserID
        in: path
        required: true
        schema:
          type: string
    get:
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                type: string
      description: "Get user info: name and role."
components:
  securitySchemes:
    basic:
      description: |
        NetHSM supports Basic Authentication.
      type: http
      scheme: basic
Example 2
openapi: 3.0.0
info:
  title: NetHSM
  version: v1
servers:
  - url: https://{host}/api/{version}
    variables:
      host:
        default: localhost:8443
      version:
        default: v1
paths:
  /users/{UserID}:
    parameters:
      - name: UserID
        in: path
        required: true
        schema:
          type: string
    get:
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                type: string
      description: "Get user info: name and role."

NPE:

Exception in thread "main" java.lang.NullPointerException
        at org.openapijsonschematools.codegen.generatorrunner.DefaultGeneratorRunner.generateRequestBodies(DefaultGeneratorRunner.java:775)
        at org.openapijsonschematools.codegen.generatorrunner.DefaultGeneratorRunner.generate(DefaultGeneratorRunner.java:1456)
        at org.openapijsonschematools.codegen.clicommands.Generate.execute(Generate.java:441)
        at org.openapijsonschematools.codegen.clicommands.AbstractCommand.run(AbstractCommand.java:34)
        at org.openapijsonschematools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:76)
##### openapi-json-schema-generator version

3.2.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
@spacether
Copy link
Contributor Author

This is caused by final Map<String, RequestBody> specRequestBodies = this.openAPI.getComponents().getRequestBodies(); throwing a npe because there are no components in your openapi document. I will post a PR to fix that issue.

@spacether spacether linked a pull request Oct 25, 2023 that will close this issue
3 tasks
@spacether
Copy link
Contributor Author

The above PR ensures that components exist before accessing them

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant