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

[BUG] Using $ref for schema definition for server sent event (SEE) though spring-boot generator raise null pointer exception #17271

Open
5 of 6 tasks
axel7083 opened this issue Dec 1, 2023 · 1 comment · May be fixed by #20658

Comments

@axel7083
Copy link

axel7083 commented Dec 1, 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 (example)
Description
openapi-generator version

We are using gradle plugin version 7.1.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: apis
  version: 1.0.0
  title: debug-apis

paths:
  /stream:
    get:
      summary: Get the notifications stream
      operationId: getNotificationsStream
      responses:
        "200":
          $ref: "#/components/responses/NotificationStream"

components:
  schemas:
    Notification:
      type: object
      properties:
        message:
          type: string

    NotificationArray:
      type: array
      format: event-stream
      items:
        $ref: '#/components/schemas/Notification'

  responses:
    NotificationStream:
      description: notification stream
      content:
        text/event-stream:
          schema:
            $ref: '#/components/schemas/NotificationArray'
Generation Details

The configuration file used, you can make the generation work by changing serverSentEvents from true to false.

{
  "library": "spring-boot",
  "apiPackage": "com.example.api",
  "invokerPackage": "com.example.invoker",
  "modelPackage": "com.example.model",
  "hideGenerationTimestamp": "true",
  "generatePom": "false",
  "title": "debug-title",
  "interfaceOnly": "true",
  "serverSentEvents": "true",
  "delegatePattern": "true",
  "reactive": "true",
  "unhandledException": "true",
  "dateLibrary": "java8",
  "useSpringBoot3": "true"
}
Steps to reproduce

See #17273 for test use case failing

Schemas leading to issue

The schema above produces

Exception: element cannot be mapped to a null key
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1269)
at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1160)
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:609)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:994)
at org.openapitools.generator.gradle.plugin.tasks.GenerateTask.doWork(GenerateTask.kt:925)
... 122 more
Caused by: java.lang.NullPointerException: element cannot be mapped to a null key
at org.openapitools.codegen.languages.SpringCodegen.fromOperation(SpringCodegen.java:1288)
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1237)
... 126 more

Related issues/PRs

#16543

Suggest a fix

If we place the schema definition directly in the response it works.

....
  responses:
    NotificationStream:
      description: notification stream
      content:
        text/event-stream:
          schema:
            type: array
            format: event-stream
            items:
              $ref: '#/components/schemas/Notification'
@axel7083
Copy link
Author

axel7083 commented Dec 1, 2023

CC @krasv @wing328

The issue is not bounded to only text/event-stream content, any content is concerned. When setting the option serverSentEvents we cannot use ref in responses object.

@axel7083 axel7083 changed the title [BUG] Using $ref for schema definition for server sent event (SEE) [BUG] Using $ref for schema definition for server sent event (SEE) though spring-boot generator raise null pointer exception Dec 1, 2023
kgeilmann pushed a commit to kgeilmann/openapi-generator that referenced this issue Feb 11, 2025
kgeilmann added a commit to kgeilmann/openapi-generator that referenced this issue Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment