Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !14586

[Go] properly set header parameters on api clients

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/sokolikp/sokolik/go-template-fix into master 2 years ago
  • Overview 8
  • Commits 2
  • Pipelines 0
  • Changes 15

Created by: sokolikp

Context

This PR addresses https://github.com/OpenAPITools/openapi-generator/issues/14578. Request headers were being improperly added as query params for Go clients. This PR:

  1. Updates the name of the function parameterAddToQuery (added in https://github.com/OpenAPITools/openapi-generator/pull/13909) to parameterAddToHeaderOrQuery to indicate that a header or query interface arg can be passed
  2. Correctly passes localVarHeaderParams (instead of localVarQueryParams) to the above function for header params
  3. Regenerates Go samples based on the above. Note that there are some automatic formatting/indentation changes to the samples - I can update those if necessary.

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 (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Checking approval status

Closed by William ChengWilliam Cheng 2 years ago (Feb 7, 2023 1:45pm UTC) 2 years ago

Loading

Activity


  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: sokolikp

    cc Go maintainers @antihax @grokify @kemokemo @jirikuncar @ph4r5h4d. I believe I'll have some test failures that I'll need to resolve, but I'm having a difficult time getting the Swagger tests to run locally.

  • William Cheng
    William Cheng @wing328 · 2 years ago
    Contributor

    @sokolikp can you please PM me via Slack when you've time so that I can help you with the test?

    https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

  • William Cheng added Client: Go Issue: Bug labels 2 years ago

    added Client: Go Issue: Bug labels

  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: sokolikp

    @sokolikp can you please PM me via Slack when you've time so that I can help you with the test?

    https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

    @wing328 thanks, I'll try pinging tomorrow! Logging off for the night.

  • Administrator changed title from Sokolik/go template fix to [Go] properly set header parameters on api clients 2 years ago

    changed title from Sokolik/go template fix to [Go] properly set header parameters on api clients

  • William Cheng changed milestone to %6.4.0 2 years ago

    changed milestone to %6.4.0

  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: sokolikp

    @wing328 when you have a chance, could you help me re-kick off the CI tests? Looks like I'm unable.

  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: sokolikp

    When I run ./mvnw clean package I get the following:

    [ERROR] Failures: 
    [ERROR]   DefaultGeneratorTest.supportCustomTemplateEngine:318 » Runtime Could not generate api file for 'Ping'
    [ERROR]   DefaultGeneratorTest.testProcessUserDefinedTemplatesWithConfig:731 » Runtime Could not generate model 'ApiResponse'
    [ERROR]   PythonClientTest.testApiTestsNotGenerated:143 » Runtime Could not generate model 'ApiResponse'
    [ERROR]   PythonClientTest.testApisNotGenerated:164 » Runtime Could not generate model 'ApiResponse'
    [ERROR]   PythonPriorClientTest.testObjectModelWithRefedAdditionalPropertiesIsGenerated:408 » Runtime Could not generate model 'A'
    [ERROR]   StringHelpersTest.startsWithSectionalTest:47->evaluate:28 » Handlebars inline@486b7642:1:4: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @3b22cdd0
        inline@486b7642:1:4
    [ERROR]   StringHelpersTest.startsWithTest:61->evaluate:28 » Handlebars inline@43bd77be:1:2: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @3b22cdd0
        inline@43bd77be:1:2
    [ERROR]   StringHelpersTest.startsWithYesOverrideTest:81->evaluate:28 » Handlebars inline@689e2599:1:2: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @3b22cdd0
        inline@689e2599:1:2
    [INFO] 
    [ERROR] Tests run: 1861, Failures: 8, Errors: 0, Skipped: 0

    When I run ./bin/generate-samples.sh I get the following:

    [pool-1-thread-27] Generation failed for python: (RuntimeException) Could not generate api file for 'usage'
    java.lang.RuntimeException: Could not generate api file for 'usage'
    	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:701)
    	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:924)
    	at org.openapitools.codegen.cmd.GenerateBatch$GenerationRunner.run(GenerateBatch.java:232)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    	at java.base/java.lang.Thread.run(Thread.java:833)
    Caused by: com.github.jknack.handlebars.HandlebarsException: endpoint.handlebars:3:3: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @41a962cf
        endpoint.handlebars:3:3
    	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
    	at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
    	at com.github.jknack.handlebars.context.FieldValueResolver$FieldMember.setAccessible(FieldValueResolver.java:150)
    	at com.github.jknack.handlebars.context.MemberValueResolver.cache(MemberValueResolver.java:82)
    	at com.github.jknack.handlebars.context.MemberValueResolver.resolve(MemberValueResolver.java:54)
    	at com.github.jknack.handlebars.Context$CompositeValueResolver.resolve(Context.java:199)
    	at com.github.jknack.handlebars.internal.path.PropertyPath.eval(PropertyPath.java:52)
    	at com.github.jknack.handlebars.Context$PathExpressionChain.next(Context.java:361)
    	at com.github.jknack.handlebars.Context$PathExpressionChain.eval(Context.java:381)
    	at com.github.jknack.handlebars.Context.get(Context.java:618)
    	at com.github.jknack.handlebars.internal.Partial.override(Partial.java:253)
    	at com.github.jknack.handlebars.internal.Partial.merge(Partial.java:226)
    	at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:125)
    	at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:95)
    	at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:125)
    	at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:113)
    	at org.openapitools.codegen.templating.HandlebarsEngineAdapter.compileTemplate(HandlebarsEngineAdapter.java:92)
    	at org.openapitools.codegen.TemplateManager.write(TemplateManager.java:163)
    	at org.openapitools.codegen.languages.PythonClientCodegen.processTemplateToFile(PythonClientCodegen.java:482)
    	at org.openapitools.codegen.languages.PythonClientCodegen.generateFiles(PythonClientCodegen.java:505)
    	at org.openapitools.codegen.languages.PythonClientCodegen.generateEndpoints(PythonClientCodegen.java:671)
    	at org.openapitools.codegen.languages.PythonClientCodegen.postProcessOperationsWithModels(PythonClientCodegen.java:916)
    	at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1246)
    	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:605)
    	... 5 more
    Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @41a962cf
    	... 31 more

    I'm not sure whether either of these are important given when I'm trying to update. @wing328 let me know if you have ideas on how to fix these.

  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: sokolikp

    Note that the updated /samples files are still generated (e.g. for python), but it's possible the script fails before the Java samples are updated.

  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: sokolikp

    Ah I found this thread where it indicates to run with:

    _JAVA_OPTIONS="--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED"

    This resolves more errors for me! It works for on on all scripts except one: ./mvnw clean package:

    [ERROR] Failures: 
    [ERROR]   DefaultGeneratorTest.supportCustomTemplateEngine:318 » Runtime Could not generate api file for 'Ping'
    [INFO] 
    [ERROR] Tests run: 1861, Failures: 1, Errors: 0, Skipped: 0

    To recap:

    • [ FAILS ] ./mvnw clean package (run w/ above Java options - a single command fails with above error "Runtime Could not generate api file for 'Ping'")
    • [ SUCCEEDS ] ./bin/generate-samples.sh (run w/ above Java options)
    • [ SUCCEEDS ] ./mvnw clean package (run w/ above Java options)
  • Administrator closed 2 years ago

    closed

  • Administrator reopened 2 years ago

    reopened

  • Administrator closed 2 years ago

    closed

  • Administrator reopened 2 years ago

    reopened

  • William Cheng mentioned in merge request !14637 (merged) 2 years ago

    mentioned in merge request !14637 (merged)

  • William Cheng
    William Cheng @wing328 · 2 years ago
    Contributor

    Closed via http://metis.lti.cs.cmu.edu:8023/OpenAPITools/openapi-generator/-/merge_requests/14637

  • William Cheng closed 2 years ago

    closed

Please register or sign in to reply
0 Assignees
None
Assign to
Reviewer
William Cheng's avatar
William Cheng
Request review from
Labels
2
Client: Go Issue: Bug
2
Client: Go Issue: Bug
    Assign labels
  • Manage project labels

Milestone
6.4.0
6.4.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
2
2 participants
William Cheng
Administrator
Reference: OpenAPITools/openapi-generator!14586
Source branch: github/fork/sokolikp/sokolik/go-template-fix

Menu

Explore Projects Groups Snippets