-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to omit redundant ID parameter on generated PUT methods #382
Comments
Following implementation of InputParameterTransformations we have all the necessary hooks to add this functionality. We just need to come up with an extension and update swagger modeler. Please feel free to contribute ideas and/or PRs. |
Tracking via: https://www.pivotaltracker.com/story/show/107070408 |
…hods This is a workaround for the following AutoRest issue: Azure/autorest#382 Unfortunately there is no way to work around this without modifying the generated code.
This functionality is now available via #687 |
If I understand "/indexes('{indexName}')": {
"put": {
"operationId": "Indexes_CreateOrUpdate",
"parameters": [
{
"name": "indexName",
"in": "path",
"required": true,
"type": "string",
"description": "The definition of the index to create or update."
},
{
"name": "index",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Index"
},
"description": "The definition of the index to create or update."
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/Index"
}
},
"201": {
"description": "",
"schema": {
"$ref": "#/definitions/Index"
}
}
}
}, Becomes this: public static Index CreateOrUpdate(this IIndexesOperations operations, Index index)
// Generated code internally does: string indexName = index.Name; Am I missing something? |
You can take a look at this test swagger. |
I see. That sort of works, but it's a shame that it has to duplicate the model class like that. A while ago you mentioned this possibility:
Whatever became of that? |
The thing is, if we add a property to the same model that is used on the wire, we will need to have a way to remove it from both send and receive payloads. We will also need logic to generate a duplicate model in case the payload is used in GET method. This current approach seems like the most flexible way of achieving this functionality. |
In my example, the |
I see. Why do you have the same value in the body and in the path though? What if the values provided by the user are different? That seems like an odd REST API design. |
Normally you wouldn't have the value in both places, but it can potentially be in both places because the body of a PUT is modeled with the same type as a POST or a GET. I notice a lot of the Management SDK Swaggers have a separate type for PUT (e.g. -- Our API takes the value from the path for PUT, but it also checks for a value in the body and returns 400 if there is one there that doesn't match. |
OK, I can see an argument here. Will return the issue to keep it on the radar. |
Thanks! |
@devigned @stankovski Any further thoughts on this? Other folks who might have opinions? I'm willing to take it on if we can agree on an approach. |
I thought of a scenario where it makes sense for It would still be nice if AutoRest could also auto-generate a second set of |
This is related to the following issue: Azure/autorest#382 Azure Search doesn't support renaming resources, so strictly speaking the overloads that take an extra name parameter are not required, but it doesn't hurt anything to have them there in case we support rename in the future. At least by moving our preferred overloads of CreateOrUpdate to custom code, we can stop fighting the code generator.
Howdy! In our planning for driving towards a stable '1.0' release, I'm marking this issue as 'deferred' 💤 and we're going to review it during the post-1.0 planning cycle. It's not to say that we're not going to work on it, or that this isn't not important, but at the moment, we're picking and choosing the stuff we must do before 1.0. 🏇 🏇 🏇 We'll make sure we pick this back up at that point. 🎉 |
Consider an operation like this one that creates or updates a resource via HTTP PUT (omitting some parts of the Swagger for clarity):
Currently AutoRest will generate signatures like this (using C# as an example):
It would be much cleaner for users of the client library if the generated code could populate the resource ID in the URL path from the resource object itself (in this example, grabbing the indexName from the Index). If it could do that, the method signature would omit the redundant parameter:
Unfortunately there is no way to use expressions in Swagger to bind parts of a model object to a parameter. Maybe we can add an extension for this?
The text was updated successfully, but these errors were encountered: