x-ms-parameter-grouping can't share a type across operations
I’m trying to use the x-ms-parameter-grouping extension and I’ve run into a problem.
The scenario is that I’d like to add a new optional parameter to every one of my operations called SearchRequestOptions that gathers up cross-cutting concerns so they don’t pollute the parameter list. For starters, I’d like to put client-request-id in this parameter group. The problem is that when I try to use the group across operations, it seems like AutoRest is trying to define a new type each time, and running into name conflicts as a result:
Finished generating Azure.CSharp code for D:\azure-rest-api-specs\search\2015-02-28\swagger\searchservice.json.
WARNING: Schema definition with name 'SearchRequestOptions' was renamed to 'SearchRequestOptionsModel' because it conflicts with following entities:
SearchRequestOptions (already used in Schema definition)
Please consider changing your swagger specification to avoid naming conflicts.
WARNING: Schema definition with name 'SearchRequestOptionsModel' was renamed to 'SearchRequestOptionsModelModel' because it conflicts with following entities:
SearchRequestOptionsModel (already used in Schema definition)
Please consider changing your swagger specification to avoid naming conflicts.
WARNING: Schema definition with name 'SearchRequestOptionsModelModel' was renamed to 'SearchRequestOptionsModelModelModel' because it conflicts with following entities:
SearchRequestOptionsModelModel (already used in Schema definition)
Please consider changing your swagger specification to avoid naming conflicts.
Etc.
This actually goes on so long that the final name it settles on is “SearchRequestOptionsModelModelModelModelModelModelModelModelModelModelModelModelModelModelModelModelModelModel”
Here are the relevant parts of my Swagger spec:
At the end of the spec:
"parameters": {
"ApiVersionParameter": {
"name": "api-version",
"in": "query",
"required": true,
"type": "string",
"description": "Client Api Version."
},
"ClientRequestIdParameter": {
"name": "client-request-id",
"in": "header",
"required": false,
"type": "string",
"format": "uuid",
"description": "Tracking ID sent with the request to help with debugging.",
"x-ms-client-request-id": { "value": "true" },
"x-ms-parameter-grouping": { "name": "SearchRequestOptions" }
}
}
In each operation:
"parameters": [
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/ClientRequestIdParameter"
}
],
It would be great if AutoRest could be smart enough to use the same parameter group type across operations.
@matthchr says the right place to fix this is probably AddParameterGroups in https://github.com/Azure/autorest/blob/master/AutoRest/Generators/Azure.Common/Azure.Common/AzureCodeGenerator.cs
This PR should fix this issue: https://github.com/Azure/autorest/pull/464
I'll validate it when I get a chance.
Confirmed that this is now fixed.