swagger-api / swagger-api/swagger-codegen

additionalProperties using ref to file does not generate correctly

Open
#4,688 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Generating a map type in swagger where additionalProperties references a file results in the resulting simplified swagger file being wrong:

Result of the yaml generator

definitions:
  FabricControllerMap:
    type: "object"
    additionalProperties:
      $ref: "./definitions/FabricController.yaml#/FabricController"
  FabricController:
    allOf:
    - $ref: "#/definitions/PlexxiObject"
    - properties:
        apiVersion:
          type: "string"
        connectionFailedCount:
          type: "integer"
          format: "int64"
          readOnly: true
        # Ect.....

Result of the spring code generator

/**
 * FabricControllerMap
 */
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2017-01-31T13:48:25.402-05:00")

public class FabricControllerMap extends HashMap<String, DefinitionsFabricControllerYamlFabricController>  {
    // ....
Swagger-codegen version

Latest master

Swagger declaration file content or url

./definitions/FabricController.yaml

FabricController:
  type: object
  description: |
    The abstract representation of all types of Ports.
  allOf:
  - $ref: './definitions/PlexxiObject.yaml#/PlexxiObject'
  - properties:
      apiVersion:
        type: string
      connectionFailedCount:
        type: integer
        format: int64
        readOnly: true
     # ect.....

./definitions/FabricControllerMap.yaml

FabricControllerMap:
  type: object
  additionalProperties:
    $ref: './definitions/FabricController.yaml#/FabricController'

./swagger.yaml

# More above
parameters:
  FabricControllerListBody:
    name: fabricController
    in: body
    required: true
    schema:
      type: array
      items:
        $ref: './definitions/FabricControllerMap.yaml#/FabricControllerMap'
Command line used for generation

lang = "io.swagger.codegen.languages.SwaggerYamlGenerator"

Steps to reproduce

Try to create a map that makes reference to a type declared in a different file.

Related issues
Suggest a Fix

Whatever type resolution for $ref that happens on properties in objects needs to also happen in additionalProperties.

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 the SwaggerYamlGenerator entry point and reproduce the case using FabricController.yaml, FabricControllerMap.yaml, and swagger.yaml. Compare how the generator resolves the $ref under object properties with the $ref under additionalProperties; done when the simplified Swagger and generated Spring type refer to FabricController correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.