swagger-api / swagger-api/swagger-codegen

openapi yaml file having callback not generating the callback code

Open
#11,257 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I am trying to generate API & Model classes (java files) from OpenAPI (3.0.x) yaml file through swagger code generator (Server side). I am using suggestions from the swagger official website below:

https://swagger.io/docs/specification/callbacks/

First time I generated spring java classes (API & Models) without callback and then I generated the java classes with callback. But both are giving me same API and Model java files. Nowhere I am seeing any extra lines of code generated for adding callback in the yaml file. I am using https://editor.swagger.io/ (Swagger Smartbear) to generate the spring server side code. Please help.

Without callback :

openapi: 3.0.0
info:
  version: 0.0.0
  title: test
paths:
  /subscribe:
    post:
      summary: Subscribe to a webhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                callbackUrl:   # Callback URL
                  type: string
                  format: uri
                  example: https://myserver.com/send/callback/here
              required:
                - callbackUrl
      responses:
        '201':
          description: Webhook created

With Callback :

openapi: 3.0.0
info:
  version: 0.0.0
  title: test
paths:
  /subscribe:
    post:
      summary: Subscribe to a webhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                callbackUrl:   # Callback URL
                  type: string
                  format: uri
                  example: https://myserver.com/send/callback/here
              required:
                - callbackUrl
      responses:
        '201':
          description: Webhook created
      callbacks:   # Callback definition
        myEvent:   # Event name
          '{$request.body#/callbackUrl}':   # The callback URL,
                                            # Refers to the passed URL
            post:
              requestBody:   # Contents of the callback message
                required: true
                content:
                  application/json:
                    schema:
                      type: object
                      properties:
                        message:
                          type: string
                          example: Some event happened
                      required:
                        - message
              responses:   # Expected responses to the callback message
                '200':
                  description: Your server returns this code if it accepts the callback

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

Reproduce the issue in editor.swagger.io using the supplied OpenAPI 3.0 YAML examples and compare the generated Spring server API and model classes. Start by tracing callback handling in swagger-codegen's OpenAPI parser and template-driven generation flow; done means callback behavior is correctly reflected in generated output or its unsupported status is clearly established with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.