Skip to content
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][CLIENT] Fix serialization for query params specified by ref #11864

Conversation

sorin-florea
Copy link
Contributor

Fixes #907

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@sorin-florea
Copy link
Contributor Author

@wing328

@sorin-florea sorin-florea force-pushed the sorin/fix-ref-query-param-explode branch from 2f060f2 to 486e7cd Compare March 14, 2022 09:52
@sorin-florea
Copy link
Contributor Author

@wing328 pinging you again

@sorin-florea sorin-florea force-pushed the sorin/fix-ref-query-param-explode branch 2 times, most recently from 89c0ac8 to fee81a3 Compare April 8, 2022 13:57
@sorin-florea
Copy link
Contributor Author

sorin-florea commented Apr 8, 2022

@guylabs
Copy link

guylabs commented Apr 29, 2022

Hi,

Any update on this pull request? Would it be possible to add it to another upcoming 6.0.0 beta release?

Thanks and regards.

@wing328
Copy link
Member

wing328 commented May 9, 2022

@sorin-florea thanks for the PR. Please resolve the merge conflicts when you've time.

@sorin-florea sorin-florea force-pushed the sorin/fix-ref-query-param-explode branch from 1d2438b to ef29bd6 Compare May 10, 2022 08:56
@wing328
Copy link
Member

wing328 commented May 10, 2022

Please also merge the latest master into your branch when you've time. Thank you.

…-param-explode

* origin/master:
  Add martindelille to code owners (OpenAPITools#12328)
  add tests to set httpUserAgent in r client (OpenAPITools#12321)
  better error messages for oneOf in java okhttp-gson (OpenAPITools#12311)
  [Inline model resolver] various improvements (OpenAPITools#12293)
@sorin-florea sorin-florea requested a review from wing328 May 10, 2022 10:38
@sorin-florea
Copy link
Contributor Author

@wing328 done. Can you please re-review it?

@wing328
Copy link
Member

wing328 commented May 13, 2022

@sorin-florea I tested with modules/openapi-generator/src/test/resources/3_0/issue907.yaml and noticed the following changes in openapi.yaml:

diff --git a/api/openapi.yaml b/api/openapi.yaml
index 998b576..cba8256 100644
--- a/api/openapi.yaml
+++ b/api/openapi.yaml
@@ -17,12 +17,33 @@ paths:
         schema:
           type: string
         style: simple
-      - explode: true
+      - $ref: '#/components/schemas/BuildQuery'
+        explode: true
         in: query
         name: BuildQuery
         required: false
         schema:
-          $ref: '#/components/schemas/BuildQuery'
+          properties:
+            integerProp:
+              format: int32
+              minimum: 0
+              type: integer
+            stringProp:
+              minLength: 1
+              type: string
+            booleanProp:
+              type: boolean
+            arrayProp:
+              items:
+                minLength: 1
+                type: string
+              type: array
+            objectProp:
+              type: object
+            numberProp:
+              minimum: 0
+              type: number
+          type: object
         style: form
       responses:
         "200":

In the past few days, we've merged a few PRs to improve the inline model resolver that are doing it the other way around by creating the inline schemas separately and referencing it instead.

Can we keep $ref as it's instead expanding it into the actual schema?

(I'm working on a PR to improve the inline model resolver so that inline schemas defined in the parameters are created separately and referenced using $ref instead)

I'm free in the afternoon (next couple of hours) so feel free to DM me via Slack to discuss this further.

Thanks again for the PR.

Inline model resolver-related PRs merged recently:

@wing328
Copy link
Member

wing328 commented May 13, 2022

One more thing to add is that I don't see changes to the Java classes that fix the serialization for query parameter issue:

➜  java-query git:(master) ✗ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   .openapi-generator/FILES
	modified:   README.md
	modified:   api/openapi.yaml
	modified:   docs/DefaultApi.md
	modified:   src/main/java/org/openapitools/client/ApiException.java
	modified:   src/main/java/org/openapitools/client/Configuration.java
	modified:   src/main/java/org/openapitools/client/Pair.java
	modified:   src/main/java/org/openapitools/client/StringUtil.java
	modified:   src/main/java/org/openapitools/client/auth/ApiKeyAuth.java
	modified:   src/main/java/org/openapitools/client/auth/HttpBearerAuth.java
	modified:   src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
	modified:   src/main/java/org/openapitools/client/model/BuildQuery.java
	modified:   src/main/java/org/openapitools/client/model/SomeReturnValue.java

All the changes to the Java files are due to timestamps change, e.g.

diff --git a/src/main/java/org/openapitools/client/model/BuildQuery.java b/src/main/java/org/openapitools/client/model/BuildQuery.java
index f6fd90d..518a520 100644
--- a/src/main/java/org/openapitools/client/model/BuildQuery.java
+++ b/src/main/java/org/openapitools/client/model/BuildQuery.java
@@ -50,7 +50,7 @@ import org.openapitools.client.JSON;
 /**
  * BuildQuery
  */
-@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-05-13T13:18:02.304890+08:00[Asia/Hong_Kong]")
+@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-05-13T13:21:16.933465+08:00[Asia/Hong_Kong]")
 public class BuildQuery {
   public static final String SERIALIZED_NAME_INTEGER_PROP = "integerProp";
   @SerializedName(SERIALIZED_NAME_INTEGER_PROP)

@wing328
Copy link
Member

wing328 commented May 19, 2022

FYI. The issue is addressed by #12369 instead.

@newmen
Copy link

newmen commented Mar 6, 2024

As I see, the original PR from @sorin-florea was not merged.
Instead, you referred to #12369, which is clearly not exactly the same as what @sorin-florea did. For example, I don't see the test that was added in #11864 (for issue 907) and nothing same in the master.

@wing328 could you please , instead of an incomprehensible link to another PR, somehow summarize the decision on this fix? Which version contains similar one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Java] Codegen Bad object serialization when query parameter is Object
4 participants