Derived class constructors are missing parameters for base class properties
Given this Swagger:
"ScoringFunction": {
"discriminator": "type",
"properties": {
"type": {
"type": "string"
},
"fieldName": {
"type": "string"
},
"boost": {
"type": "number",
"format": "double"
},
"interpolation": {
"$ref": "#/definitions/ScoringFunctionInterpolation"
}
},
"required": [
"type"
]
},
"DistanceScoringFunction": {
"allOf": [
{
"$ref": "#/definitions/ScoringFunction"
},
{
"properties": {
"distance": {
"$ref": "#/definitions/DistanceScoringParameters"
}
}
}
]
},
AutoRest generates the following non-default constructors in C#.
For ScoringFunction:
public ScoringFunction(string fieldName = default(string), double? boost = default(double?), ScoringFunctionInterpolation? interpolation = default(ScoringFunctionInterpolation?))
{
FieldName = fieldName;
Boost = boost;
Interpolation = interpolation;
}
For DistanceScoringFunction:
public DistanceScoringFunction(DistanceScoringParameters distance = default(DistanceScoringParameters))
{
Distance = distance;
}
The DistanceScoringFunction constructor ought to include the parameters from its base class counterpart in ScoringFunction.
Further to this, if you mark the derived class properties as required in the Swagger spec, AutoRest does not emit non-defaulted parameters for those properties in the constructor. It does for required base class properties.
EDIT
This particular symptom turned out to be my fault. The "requires" element was misplaced in the Swagger spec. If you do this:
"shark": {
"allOf": [
{
"$ref": "#/definitions/Fish"
}
],
"required": [ "birthday" ],
"properties": {
"birthday": {
"type": "string",
"format": "date-time"
}
}
}
You get correct generated code. But, if you do this:
"shark": {
"allOf": [
{
"$ref": "#/definitions/Fish"
},
{
"required": [ "birthday" ],
"properties": {
"birthday": {
"type": "string",
"format": "date-time"
}
}
}
]
}
You get an optional parameter for "birthday" instead of a required one.
I'm going to try to fix this.