-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: [TSI-2083] enable format_options argument for java-client #426
Conversation
@@ -100,7 +100,12 @@ public class {{classname}} { | |||
{{javaUtilPrefix}}List<Pair> localVarCollectionQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>(); | |||
{{#queryParams}} | |||
if ({{paramName}} != null) { | |||
{{#isMap}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
isDeepObject
orisExplode
properties
But let me check again, would be more specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check this. Thanks for sharing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..and arrays :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
@@ -168,7 +173,8 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx | |||
Assert.assertEquals("Correct file contents", fileContents, body); | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rails implementation simply sorts the params by name at end. :)
@hahmed-dev is this still valid? |
@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_options
argument will be key-value based map with values mostly being of primitive typesstyle
deepObject
andexplode: true
option 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 basedPair
objects.Problem Statement
Phrase API accepts
format_options
argument 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: