If an ENUM is modeled as a reference, the SwaggerModeler loses the information that it is actually a required type.
searchMode does not have its schema definition inline. Its referenced from another place. In such a scenario, the SwaggerObject in the modeler looses the fact that searchMode is a required property on the Suggester. Hence, instead of making searchMode a constant, it makes it an Enum with one value. Although the behavior of making it a constant v/s an Enum with one value is debatable. The main issue is that when the object of primary type is modeled as a reference the Modeler loses the information that it is actually a required type.
"Suggester": {
"properties": {
"name": {
"type": "string",
"description": "Gets or sets the name of the suggester."
},
"searchMode": {
"$ref": "#/definitions/SuggesterSearchMode",
"description": "Gets or sets a value indicating the capabilities of the suggester."
},
"sourceFields": {
"type": "array",
"items": {
"type": "string"
},
"description": "Gets the list of field names to which the suggester applies. Each field must be searchable."
}
},
"required": [
"name", "searchMode", "sourceFields"
],
"description": "Defines how the Suggest API should apply to a group of fields in the index.",
"x-ms-external": true
},
"SuggesterSearchMode": {
"type": "string",
"enum": [
"analyzingInfixMatching"
],
"x-ms-enum": { "name": "SuggesterSearchMode" },
"description": "Describes the type of suggester to use."
}
The following method returns false, instead of true because swaggerObject.IsRequired is false.
private static bool IsSwaggerObjectConstant(SwaggerObject swaggerObject)
{
return (swaggerObject.Enum != null && swaggerObject.Enum.Count == 1 && swaggerObject.IsRequired);
}
Related (sort of): https://github.com/Azure/autorest/issues/783
The above issue is how we found this issue.