OpenAPITools / OpenAPITools/openapi-generator

[BUG] Resolve Fully does not work?

Open
#6,238 1 comment 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

Hi folks,

I am new in OpenAPI,

I have the following yaml file:

openapi: 3.0.1
info:
  title: ping test
  version: '1.0'
servers:
  - url: 'http://localhost:888888/'
paths:
  /some/ping:
    get:
      operationId: AAAAA
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                $ref: 'some-swagger-response.yaml'
components:
  schemas: {}

What I want is to get an String output, containing all the output above and resolving the "$ref".

This is my code snippet:

String inputSpec = "./src/main/java/swagger-reference-response.yaml";
        OpenAPIParser openApiParser = new OpenAPIParser();
        ParseOptions options = new ParseOptions();
        options.setResolveFully(true);
        options.setFlatten(false);

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

        System.out.println(string);

The output of the String is:

`openapi: 3.0.1
info:
  title: ping test
  version: "1.0"
servers:
- url: http://localhost:888888/
paths:
  /some/ping:
    get:
      operationId: AAAAA
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
components:
  schemas:
    some-swagger-response:
      type: object`

How can I get the full content of this file inside the String? $ref: 'some-swagger-response.yaml'

Thank you very much

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 by reproducing the example with OpenAPIParser, ParseOptions.setResolveFully(true), and Yaml.mapper(), using swagger-reference-response.yaml and the external some-swagger-response.yaml reference. Compare the parsed model with the serialized YAML and inspect parser tests or entry points for external-reference resolution; done means the expected referenced content is either emitted or the behavior is clearly documented.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.