swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
780 stars 525 forks source link

RequestBody and Response Examples with relativePath are not resolved #2091

Open ramahmoo opened 4 months ago

ramahmoo commented 4 months ago

We have OpenAPI 3.0.1 spec with examples on relative path, we want to generate a single API file while creating API spec artifact.

Our API Looks like as specified in OpenAPI spec https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.1.md#media-type-object

as spec stats that examples could be a map of example/reference values image

{
  "application/json": {
    "schema": {
         "$ref": "#/components/schemas/Pet"
    },
    "examples": {
      "cat" : {
        "$ref": "./examples/pet/cat.json"
      },
      "dog": {
        "$ref": "./examples/pet/dog.json"
        },
      "frog": {
        "$ref": "./examples/pet/dog.json"
        }
      }
    }
  }
}

Source code to generate the single API

ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true); // not resolving relative path examples as expected, even with resolveFully
parseOptions.setValidateExternalRefs(true);

SwaggerParseResult result  = new OpenAPIV3Parser().readLocation(inputSpec, null, parseOptions);
result.getMessages().forEach(System.out::println);

Debugging in Intellij shows that ResolverCache.java was able to load the example ref but your code not assigning this as value to your Example.java, hence we see a lot of

attribute ..xxx is unexpected

At the end generated API does not have those example values.

Could you please check if it is a bug or we are missing something in our understanding?