swagger-api / swagger-api/swagger-codegen
additionalProperties using ref to file does not generate correctly
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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