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
Not preserving the parameter order when creating API using Java Configuration in springfox 2.9.2 #2705
Comments
I can see there is another thread |
Here is a (ugly) workaround:
by
You may also remove the byParameterName() method, which became useless or implement your own comparator if you want to customize parameters order. |
Any chance to get this in before 3.0? This (and #2418) hit us pretty bad. |
@wwerner working on it, technically the order is not guaranteed as I've mentioned many times before. It is a Map just like a Map in any language doent preserve order |
@dilipkrish I suggest a LinkedHashMap or a TreeMap. A LinkedHashMap keeps the keys in the order they were inserted, while a TreeMap is kept sorted via a Comparator or the natural Comparable ordering of the elements. https://stackoverflow.com/a/683524/256544 |
Is there any update for this issue? |
A workaround is to use a ParameterBuilderPlugin and prefix the parameter name by its parameter index. An implementation in Scala is:
The tricky part is that not only the parameter names are adjusted but the request mapping pattern has to be adjusted too. Fortunately this can be done by a CustomPathDecorator that adds the index prefix to parameter names that occur in curly braces inside the path. Note: This does work for path parameters only. In case of query parameters the names must not be changed. Otherwise the server would not recognize the query paramenters. |
After some more thoughts I came to the conclustion, that keeping the order of parameters when generating the api doc would not solve the general problem. Relying on the allignment of parameters in client code and backend code would be brittle anyway. Therefore I solved this problem by refering to parameter names in client code. The client code is generated by swagger codegen. I had to tweak the typescript-angular template somewhat to use structural argument decomposition if more than one argument must be given to a call. An example of a generated method is:
Now the method can be called in the following way:
|
Thx for solution. This still doesn't solve original issue which is the fact that arguments are being reordered, when most expect for them to not to. Some apis could be relying on the order of arguments for clarity, or already have clients that were generated based on previous springfox generated open api specs, without alphabetical reorder. Also note that not all languages have structural argument decomposition. |
@fathzer I came across your solution in #2705 (comment), but I don't understand it. How will Springfox run the code in the class in my application, instead of its own? |
@cesarblum You should keep the same class name and package (springfox.documentation.service.Operation). |
Thanks man, Problem Solved. |
Fixed via #2022 |
looks still broken |
Yes , still broken |
I was using Java Configuration to create the client and was using the generated client in other application.
When I updated the springfox version 2.9.2 then in the new client the parameter order is changes. It is in sorted order now. It is breaking my integration as in older version, the parameter was in the order as listed in API
Please let me know what is the solution to preserve the parameter order as it is ?
The text was updated successfully, but these errors were encountered: