We are using the latest swagger-codegen-cli (currently v2.4.28) to generate a python client from a swagger yaml file. We use allOf throughout our specification to re-use definitions across multiple types of response objects. When generating a python client we notice that model classes generated seem to be missing any attributes defined in the first allOf reference.
The specification is valid, and there are no errors or warnings generated that would indicate a problem so I am not sure if this is a bug or if we've misunderstood the intended usage.
Here is a minimal example that illustrates the problem.
swagger: '2.0'
info:
version: "0.1.0"
title: Sample
host: localhost:8080
schemes:
- https
basePath: /sample/v1
paths:
/info:
get:
summary: Get Info
operationId: getInfo
produces:
- application/json
tags:
- Info
responses:
200:
description: Information Response
schema:
$ref: "#/definitions/InfoResponse"
default:
description: Unexpected error
definitions:
InfoResponse:
type: object
allOf:
- $ref: "#/definitions/Part1"
- $ref: "#/definitions/Part2"
- $ref: "#/definitions/Part3"
Part1:
type: object
properties:
a:
type: integer
b:
type: integer
Part2:
type: object
properties:
c:
type: string
d:
type: string
Part3:
type: object
properties:
e:
type: string
f:
type: string
We use the following command to generate the python client.
java -jar swagger-codegen-cli-2.4.28.jar generate -l python -i api-specification.yaml -o codegen
The python model class for the InfoResponse object has the following swagger_types and attribute_map values.
swagger_types = {
'c': 'str',
'd': 'str',
'e': 'str',
'f': 'str'
}
attribute_map = {
'c': 'c',
'd': 'd',
'e': 'e',
'f': 'f'
}
As you can see, the two attributes from the Part1 reference are missing (i.e., "a", and "b"). If I reorder the references so that Part2 is first then "c" and "d" go missing and "a" and "b" are present. Like this:
InfoResponse:
type: object
allOf:
- $ref: "#/definitions/Part2"
- $ref: "#/definitions/Part1"
- $ref: "#/definitions/Part3"
It would appear as though the first reference in the list is always ignored. Is this a bug, a template problem, are the definitions not specified correctly, or am I not understanding how this is supposed to work?