OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][SPRING] Not able to generate code from spec file with webhooks definition

Open
#20,175 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 (example)
Description

While trying to generate code from the yaml file using gradle (openApiGenerate), the task fails with the following error:
Cannot invoke "java.util.Map.get(Object)" because the return value of "io.swagger.v3.oas.models.Operation.getExtensions()" is null
it happens for the files that contain webhooks definition (check OpenApi declaration file section).

openapi-generator version

'org.openapi.generator' version '7.10.0'

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Webhook Example
  version: 1.0.0
  description: >
    Easy example of documentation with a single webhook,
    provided by OpenAPI Initiative.

webhooks:
  newPet:
    post:
      description: A new pet is born, let's come and discover it in Petstore.
      requestBody:
        description: Information about a new pet in the system
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Pet"
      responses:
        "200":
          description: Return a 200 status to indicate that the data was received successfully
Generation Details

Just run any specification file that contains webhooks: definition with the gradle setup above.

Steps to reproduce
  1. use openApi spec file with webhooks definition,
  2. setup gradle task for codegen, like this:
openApiGenerate {
    generatorName.set("spring")
    library.set("spring-boot")

    inputSpec.set(specFile)
    outputDir.set(generatedSourcesOutputDir)

    apiPackage.set("dev.api")
    invokerPackage.set("dev.invoker")
    modelPackage.set("dev.model")

    additionalProperties.set([
            basePackage: "dev.integration", 
            useTags: true, 
            dateLibrary: "java8"
    ])
}
  1. run the task
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/13103

Suggest a fix

Implement null check here for extensions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java around line 992, then reproduce with the provided OpenAPI 3.1 webhook spec and Gradle openApiGenerate configuration. Check how extensions are handled when Operation.getExtensions() is null. Done means Spring generation completes successfully for a specification containing a webhooks definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend, build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.