Skip to content

$ref in external file in requestBody with resolve option true #768

@philippwinter

Description

@philippwinter

Similar to Issue #749, JSON references inside the requestBody's schema property are not properly resolved.


Main OAS 3.0 file:

openapi: 3.0.0
info:
  title: ref test
  version: '1.0'
servers:
  - url: 'http://localhost:8000/'
paths:
  /user/login:
    post:
      summary: Login
      operationId: loginUser
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "schemas.yaml#/User"
components:
  schemas: {}

Additional schema file:

User:
  type: "object"
  properties:
    Name:
      type: "string"
    Password:
      type: "string"
      format: "password"

Run this code:

    OpenAPIParser openApiParser = new OpenAPIParser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);

    String inputSpec = "main.yaml";

    OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, options).getOpenAPI();
    String string = Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);

    System.out.println(string);

Current Value:

openapi: "3.0.0"
info:
  title: "ping test"
  version: "1.0"
servers:
- url: "http://localhost:8000/"
paths:
  /user/login:
    post:
      summary: "Login"
      operationId: "loginUser"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "schemas.yaml#/User"
        required: true
components:
  schemas: {}
  extensions: {}

Expected Value:

openapi: "3.0.0"
info:
  title: "ping test"
  version: "1.0"
servers:
- url: "http://localhost:8000/"
paths:
  /user/login:
    post:
      summary: "Login"
      operationId: "loginUser"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#components/schemas/User"
        required: true
components:
  schemas:
      User:
        type: "object"
        properties:
          Name:
            type: "string"
          Password:
            type: "string"
            format: "password"
  extensions: {}

Tested with version 2.0.0-SNAPSHOT from Sonatype OSS

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