feat: [TSI-2083] enable format_options argument for java-client #426
feat: [TSI-2083] enable format_options argument for java-client #426Hassan Ahmed (hahmed-dev) merged 11 commits intomasterfrom
Conversation
| {{javaUtilPrefix}}List<Pair> localVarCollectionQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>(); | ||
| {{#queryParams}} | ||
| if ({{paramName}} != null) { | ||
| {{#isMap}} |
There was a problem hiding this comment.
I believe you should use #isDeepObject instead. You can see it's available to the API template if you run generate with --global-property debugOperations=true (also isExplode is available)
There was a problem hiding this comment.
Thanks, will take a look, the document it printed out for me upon running with this argument,
- niether included any documentations for get end points
- nor
isDeepObjectorisExplodeproperties
But let me check again, would be more specific
There was a problem hiding this comment.
or, you can pass {{style}} as a parameter to mappedParameterToPairs, and then handle it appropriately (leaving other styles not covered until we need them).
There was a problem hiding this comment.
note that there are different debug... flags possible to pass as global-property. https://openapi-generator.tech/docs/debugging/#templates
There was a problem hiding this comment.
Will check this. Thanks for sharing.
There was a problem hiding this comment.
Thanks Mladen, using debugOperations was able to find the name of the directive.
| public List<Pair> mappedParameterToPairs(String name, Object parameter){ | ||
| List<Pair> params = new ArrayList<Pair>(); | ||
|
|
||
| if(parameter instanceof Map){ |
There was a problem hiding this comment.
there's additional problem that we'll have to address at some point: these objects can be nested. so, it should be possible to generate a parameter such as formatOptions[customMetadataColumns][order]=B and so on 😄 Perhaps we could address that in a separate ticket
There was a problem hiding this comment.
Thats true, i'll check if its something that can be addressed already within this PR otherwise we can do it separately :)
There was a problem hiding this comment.
I guess in case if a value against format_option is an array, it should already be handled? If not I will check and see if that can be addressed as well. I think from just a look maybe keynames need to be constructed in a nested way.
There was a problem hiding this comment.
seems it covers the basic case, but I guess arrays can also be nested 😬 never mind, we can cross that bridge when we get there
There was a problem hiding this comment.
Also go will probably have the same issue with customMetadataColumns https://github.com/phrase/phrase-go/blob/master/api_locales.go#L436
There was a problem hiding this comment.
Was already looking into nested arguments, that part is addressed with the latest commit. Regarding values being arrays/nested array, can see if it can be handled separately.
There was a problem hiding this comment.
Sönke Behrendt (@theSoenke) by same issue do you mean, it will require same patch like this?? For map based query params?
There was a problem hiding this comment.
Hassan Ahmed (@hahmed-dev) format_options should already work. But for more deeply nested params it will need a similar fix I think
There was a problem hiding this comment.
Sönke Behrendt (@theSoenke) I think deep nesting is an open feature request in the open api spec. If thats the case we may have to find a work around whenever we encounter something like this.
|
|
||
| RecordedRequest recordedRequest = mockBackend.takeRequest(); | ||
| Assert.assertEquals("Request path", "//projects/MY_PROJECT_ID/locales/MY_ID/download?format_options%5Bomit_separator_space%5D=true&format_options%5Bfallback_language%5D=en", recordedRequest.getPath()); | ||
| // for some reason with deep nested query params, ordering of query params change |
There was a problem hiding this comment.
rails implementation simply sorts the params by name at end. :)
|
Hassan Ahmed (@hahmed-dev) is this still valid? |
|
Manuel Boy (@docstun) yes, we initially were waiting to merge the open api version bump PR since its based out of that, but we discussed last week, there is no dependency and we can merge this independently as well. I will try and shortly open a new PR and if that gets merged close this one. |
d11a02b to
5f66775
Compare
Assumptions
Some assumptions made while working on the PR:
format_optionsargument will be key-value based map with values mostly being of primitive typesstyledeepObjectandexplode: trueoption as suggested here as a fix but subsquently wasn't able to find appropriate mustache directive to determine if the param has any of these attributes (deepObject, explode: true) which led to adding a fix by checking if input is of the type Map and if yes, manually convert it to key value basedPairobjects.Problem Statement
Phrase API accepts
format_optionsargument on locales download endpoint.For java-client the format_option argument was not being properly parsed and embedded in the query params resulting in a request url like below
Solution
This pull requests adds the ability to parse any query params of type map and embed them to the URL's query string as proper key value pairs resulting in request URLs like: