swagger-api / swagger-api/swagger-codegen

$ref does not work with allOf

Open
#7,477 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Combining $ref with allOf will cause the property to be ignored, the following will not work:

  Some_Def:
    type: string

  Some_Object:
    properties:
      foo:
        allOf: [$ref: "#/definitions/Some_Def"]
      bar:
        type: string

The resulting OAS specification will only contain bar but not foo. However simply omitting the allOf like the following will cause it to work fine:

  Some_Def:
    type: string

  Some_Object:
    properties:
      foo:
        $ref: "#/definitions/Some_Def"
      bar:
        type: string

The problem of course is that it becomes impossible to extend an external schema now.

Edit:

swagger-codegen will output the following warnings:

[main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}, MULTIPLE_OF=null}

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

Reproduce the YAML example through swagger-codegen and inspect the PropertyDeserializer warning shown in the issue. Trace how properties using allOf and $ref are parsed, then verify that foo is retained and can be extended while bar remains present.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.