swagger-api / swagger-api/swagger-codegen

Swagger ignores vendorextention for $ref type properties

Open
#2,219 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi @wing328 ,

Swagger ignores vendorextention for $ref type properties. For e.g.
If there is a property as follows in yaml

  myObject:
       properties:
               myid:
                  type: int
                  x-app-extensions: {"aaid" : "bb", "ccid" : "dd"}
errors:
                   x-app-extensions: {"aaerr" : "bb", "ccerr" : "dd"}
    $ref: "#/definitions/errorModel"

Then, swagger model ignores vendorextensions for errors, and only has only $ref property in the parsed json node, and same in reflected in created java model.
But, vendorextenion is correctly picked up for myid.
The ignorance of vendor extension is due to an issue in following snippet of the code of io.swagger.util.PropertyDeserializer.propertyFromNode(JsonNode) method.

   JsonNode detailNode = node.get("$ref");
  if (detailNode != null) {
      return new RefProperty(detailNode.asText()).description(description);
  }

Is it expected that, $ref type nodes are not supposed to have any other properties?

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 with io.swagger.util.PropertyDeserializer.propertyFromNode(JsonNode) and the shown $ref branch, then inspect RefProperty and the resulting Java model representation. Reproduce the YAML case with vendor extensions on a $ref property and verify that the parsed node and generated model retain those extensions alongside the reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
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.