-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[ALL] [3.0] Body param is now first in parameters list, used to be last #9103
Comments
It should be noted that this only happens for "none-form-data" bodies - as form-data bodies are "exploded" into individual parameters. |
The cause of this problem is that in "Unfortunately", the class |
you're right @skrysmanski about why body params are placed as first parameters. i could fix this, but would like to discuss if this is really a problem. |
In principle, I agree with @ivan-gomes that the parameter order should not change between v2 and v3, if possible. Unfortunately, we also have to look at reality here and there may already be projects out there that expect the body param to be the first. Changing this would be a breaking change for them. The most sensible solution would be to make this configurable; however I'm not sure whether the amount of work required to implement something like this would be justified. |
@skrysmanski , i like the idea to make this configurable, we could add an option on codegen or use a vendor extension for that. This last would be quicker for me. |
There might be a misunderstanding with the generated code?
|
+1 for this. in cases where the query param specifies the resource upon which to act and the requestBody contains information about what to do to it... it just makes more sense to put the query params first. Also, this was the previous behaviour. Also +1 to @cricketer comment above, you used to be able to name the 'body' parameter and now it appears we are stuck with 'body' as the parameter name. This is poor because it is allowing the implementation (http) to leak into the code api |
In scope of the question of parameters ordering -- right now with generator version 2.2.2 we have parameters of the generated method listed in exactly the same order they go in the source specification. With upgrade to version 3.x.x it doesn't work that way anymore. And I don't see they way to fix this: when conversion to @HugoMario could you take a look & confirm if this is right interpretation? And, probably, propose a way to have same behavior as 2.2.2 version |
Is there any update on this issue? Will it be made as configurable in future release? It is affecting the users who is migrating from older versions |
Hey, any update on this one? Can we at least get a programmatic workaround to get back to the previous ordering? It's breaking all our existing consumers of the generated library :( |
+1 Is there any workaround for this? |
If it can help people, here is the workaround I came with to generate my Python library. It set the path params first, then the body param, then the query params. You need to edit the comparator if you have more params type (form, header...). private void generatePythonLib(OpenAPI api) {
CodegenConfig config = new PythonClientCodegen() {
// workaround for https://github.com/swagger-api/swagger-codegen/issues/9103
// path params first, then body, then query params
Comparator<CodegenParameter> comp = new Comparator<CodegenParameter>() {
@Override
public int compare(CodegenParameter p1, CodegenParameter p2) {
if (p1.getIsPathParam()) {
if (p2.getIsPathParam())
return 0;
else
return -1;
} else if (p1.getIsBodyParam()) {
if (p2.getIsPathParam())
return 1;
else
return -1;
} else if (p1.getIsQueryParam()) {
if (p2.getIsQueryParam())
return 0;
else
return 1;
}
return 0;
}
};
@Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operation = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation op : operation) {
for (CodegenContent content : op.getContents()) {
List<CodegenParameter> params = content.getParameters();
if (!params.isEmpty()) {
// sort with our custom comparator ...
params.sort(comp);
// ... then restore "x-has-more" flag for all params
params.forEach(p -> p.getVendorExtensions().put(CodegenConstants.HAS_MORE_EXT_NAME, true));
params.get(params.size() - 1).getVendorExtensions().put(CodegenConstants.HAS_MORE_EXT_NAME, false);
}
}
}
return super.postProcessOperations(objs);
}
};
ClientOpts opts = new ClientOpts();
ClientOptInput input = new ClientOptInput()
.config(config)
.opts(opts)
.openAPI(api);
new DefaultGenerator()
.opts(input)
.generate();
} |
Description
When an operation has multiple types of parameters, i.e. query and body, the order of these parameters provided to the code generators in 2.x was such that body was last. This resulted in the generated clients to place the body argument after all the query arguments.
Example:
In 3.0, the order has been changed such that body is first, before query parameters - verified with
-DdebugOperations=true
.Example:
This results in an API breakage in any language where argument order is used.
Swagger-codegen version
3.0.4 and 3.0.5-SNAPSHOT
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli-3.0.4.jar generate -i /path/to/swagger.yaml -l java -o /var/tmp/java-api-client -DdebugOperations=true
Steps to reproduce
See above.
Related issues/PRs
Suggest a fix/enhancement
The ordering of
operations.contents.parameters
(and perhapsallParams
to ease the migration) in 3.0 should be made consistent with that in 2.x, namely putting body last. This should result in code generators for all languages maintaining the same order as it did in 2.x.The text was updated successfully, but these errors were encountered: