Skip to content

Callback with $ref is not working #879

@jmini

Description

@jmini

Consider this input file:

openapi: 3.0.0
info:
  title: Callback with ref Example
  version: 1.0.0
paths:
  /register:
    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:
        '200':
          description: subscription successfully created
          content:
            application/json:
              schema:
                type: object
                description: subscription information
                required:
                  - subscriptionId
                properties:
                  subscriptionId:
                    description: unique identifier
                    type: string
                    example: 2531329f-fb09-4ef7-887e-84e648214436
      callbacks:
        myEvent:
          $ref: '#/components/callbacks/callbackEvent'
components:
  callbacks:
    callbackEvent:
      '{$request.body#/callbackUrl}':
        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:
            '200':
              description: ok

Test code:

final String inputSpec = /* path */;

OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, options).getOpenAPI();

String ref = openAPI.getPaths()
                       .get("/register")
                       .getPost()
                       .getCallbacks()
                       .get("myEvent")
                       .get$ref();
System.out.println(ref);

ref should contain: #/components/callbacks/callbackEvent

current result is null.

Tested with:

<dependency>
  <groupId>io.swagger.parser.v3</groupId>
  <artifactId>swagger-parser</artifactId>
  <version>2.0.5</version>
</dependency>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions