Skip to content

[BUG] [Groovy] Fix client to work with services that support other formats in addition to JSON#22908

Open
sekikn wants to merge 4 commits intoOpenAPITools:masterfrom
sekikn:22907-add-accept-header-to-groovy-generator
Open

[BUG] [Groovy] Fix client to work with services that support other formats in addition to JSON#22908
sekikn wants to merge 4 commits intoOpenAPITools:masterfrom
sekikn:22907-add-accept-header-to-groovy-generator

Conversation

@sekikn
Copy link
Contributor

@sekikn sekikn commented Feb 6, 2026

This PR fixes the Groovy client to add the Accept header since it only supports JSON wire format as of now.
It also includes some fixes for the sample tests, because the current client implementation doesn't seem to deal with the enum conversion and the redirect from http to https correctly.

You can ensure its behavior as follows:

Build openapi-generator and generate the Groovy sample with JDK 11+:

$ ./mvnw clean install
$ bin/generate-samples.sh bin/configs/groovy.yaml

Run the sample tests against the generated client with JDK 8:

$ cd samples/client/petstore/groovy
$ gradle wrapper
$ ./gradlew clean build --info

(snip)

openapitools.PetApiTest > testGetPetByStatus STANDARD_OUT
    url=https://petstore.swagger.io uriPath=/v2/pet/findByStatus

openapitools.PetApiTest > testGetPetByStatus STANDARD_ERROR
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

openapitools.PetApiTest > testUpdateOnePet STANDARD_OUT
    url=https://petstore.swagger.io uriPath=/v2/pet
    url=https://petstore.swagger.io uriPath=/v2/pet/10009
    url=https://petstore.swagger.io uriPath=/v2/pet/10009
    url=https://petstore.swagger.io uriPath=/v2/pet/10009
    url=https://petstore.swagger.io uriPath=/v2/pet/10009
    url=https://petstore.swagger.io uriPath=/v2/pet/10009

openapitools.PetApiTest > testAddAndGetPet STANDARD_OUT
    url=https://petstore.swagger.io uriPath=/v2/pet
    url=https://petstore.swagger.io uriPath=/v2/pet/10009

Gradle Test Executor 6 finished executing tests.

(snip)

BUILD SUCCESSFUL in 4s
5 actionable tasks: 5 executed

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 || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
    fixes [BUG] [Groovy] Generated client can't work with the openapi-petstore service by default #22907
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    No one is in the Groovy technical committee as of now, so let me ping @wing328

Summary by cubic

Set the Accept header per operation using each operation’s produces list (preferring application/json), and add JAXB-based XML request/response support so Groovy clients work with servers that offer JSON or XML. Fixes #22907.

  • New Features

    • XML support end-to-end: JAXB annotations in models and XML encode/decode in the client when the spec declares XML.
  • Bug Fixes

    • Use operation produces to set Accept via selectHeaderAccept and generator templates; prefer application/json when available.
    • Preserve enum names (enumPropertyNaming: original) and update Pet/Order enums and tests to use typed enums.
    • Switch sample base URLs to https to avoid http→https redirects.
    • Add a Groovy-specific petstore.yaml and point groovy.yaml inputSpec to it.

Written for commit 9bd583a. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 10 files

if (bodyParams != null) {
request.body = bodyParams
}
request.accept = ['application/json']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR

according to the description. the change should support other formats in addition to JSON but looks like it's now hard-code to application/json.

should it use the accept provided in the spec instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for reviewing @wing328.

according to the description. the change should support other formats in addition to JSON but looks like it's now hard-code to application/json.

My intention was to force the server to respond in JSON format by specifying that header in the request, because all of the servers listed in the official document at least support JSON.
But yes, it is clear that adding new format support is better as you mentioned, since there can be a service only supporting XML in the wild. Let me give it a try.

should it use the accept provided in the spec instead?

Agreed, I'll fix it accordingly.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/Groovy/modelEnum.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Groovy/modelEnum.mustache:12">
P2: @XmlEnumValue expects a String literal, but boolean enums render @XmlEnumValue(true) without quotes, which will not compile in XML-enabled generation.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/ApiUtils.groovy">

<violation number="1" location="samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/ApiUtils.groovy:75">
P2: Recursive array parsing still calls the old 3-argument parse signature, which will throw MissingMethodException after the method signature was expanded to include `response`. Array responses will fail to deserialize.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache:101">
P2: XML parsing short-circuits array handling; XML responses for array operations will return a single instance instead of a collection.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@sekikn sekikn force-pushed the 22907-add-accept-header-to-groovy-generator branch from 58a9620 to 9bd583a Compare February 9, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Groovy] Generated client can't work with the openapi-petstore service by default

2 participants