Skip to content

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.
    • Add Gradle Shadow plugin to generator and samples to produce fat jars.
  • 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 c3fa247. Summary will update on new commits.

Copy link
Contributor

@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
Contributor

@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
Contributor

@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
@wing328
Copy link
Member

wing328 commented Feb 9, 2026

I'll try to test locally tomorrow and merge if no question/feedback from anyone. Thanks again for the contribution.

@sekikn
Copy link
Contributor Author

sekikn commented Feb 10, 2026

Thanks a lot for reviewing and checking @wing328!
FYI, I made sure the current version of this PR worked well as follows:

Build the Groovy generator and its sample, then against https://petstore.swagger.io/ to ensure prioritizing "application/json" to "application/xml":

$ sdk u java 11.0.26-amzn
$ ./mvnw clean install
$ bin/generate-samples.sh bin/configs/groovy.yaml 
$ cd samples/client/petstore/groovy
$ sdk u java 8.0.482-tem 
$ gradle wrapper
$ ./gradlew clean build --info

(snip)

> Task :test
Task ':test' is not up-to-date because:
  Output property 'binResultsDir' file /home/sekikn/repos/OpenAPITools/openapi-generator/samples/client/petstore/groovy/build/test-results/test/binary has been removed.
  Output property 'binResultsDir' file /home/sekikn/repos/OpenAPITools/openapi-generator/samples/client/petstore/groovy/build/test-results/test/binary/output.bin.idx has been removed.
  Output property 'binResultsDir' file /home/sekikn/repos/OpenAPITools/openapi-generator/samples/client/petstore/groovy/build/test-results/test/binary/output.bin has been removed.
Starting process 'Gradle Test Executor 4'. Working directory: /home/sekikn/repos/OpenAPITools/openapi-generator/samples/client/petstore/groovy Command: /home/sekikn/.sdkman/candidates/java/8.0.482-tem/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dorg.gradle.native=false -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea -cp /home/sekikn/.gradle/caches/4.9/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 4'
Successfully started process 'Gradle Test Executor 4'

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 4 finished executing tests.

(snip)

BUILD SUCCESSFUL in 4s
5 actionable tasks: 5 executed

Regenerate the client enabling the XML feature and ensure it works with the application/xml content type:

$ docker run -d -e DISABLE_API_KEY=1 -e DISABLE_OAUTH=1 -p 80:8080 --rm openapitools/openapi-petstore
$ cd -
$ curl -sLO http://localhost/openapi.yaml
$ vi openapi.yaml  # remove all `application/json` elements from the `content` fields and replace all of the values of the `x-accepts` and `x-contentType` fields with `application/xml` to enforce using XML

$ sdk u java 11.0.26-amzn
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g groovy -i openapi.yaml -o /tmp/petstore-groovy --additional-properties=enumPropertyNaming=original,withXml=true

$ cd /tmp/petstore-groovy
$ sdk u java 8.0.482-tem
$ gradle wrapper
$ ./gradlew clean shadowJar
$ CLASSPATH=build/libs/openapi-gen-groovy-1.0.0-all.jar groovysh
Groovy Shell (2.5.14, JVM: 1.8.0_482)
Type ':help' or ':h' for help.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000> new org.openapitools.api.PetApi(basePath: "http://localhost", versionPath: "/v3").getPetById(1L) { println(it) } { status, message -> println(message) }
url=http://localhost uriPath=/v3/pet/1
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.
org.openapitools.model.Pet(1, null, pet, [], [], null)
===> null

XML was surely sent during the transaction above, as follows:

$ sudo tcpflow -ac -i lo port 80
reportfilename: ./report.xml
tcpflow: listening on lo
127.000.000.001.54978-127.000.000.001.00080: GET /v3/pet/1 HTTP/1.1
Accept: application/xml
Accept-Encoding: gzip, deflate
User-Agent: Java/1.8.0_482
Host: localhost
Connection: keep-alive


127.000.000.001.00080-127.000.000.001.54978: HTTP/1.1 200 
Content-Type: application/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 09 Feb 2026 23:53:48 GMT

4a
<Pet><id>1</id><category/><name>pet</name><photoUrl/><tag/><status/></Pet>

@wing328
Copy link
Member

wing328 commented Feb 10, 2026

@sekikn I just merged #22936 to add petstore integration tests in the github workflow.

can you please merge the latest master into your branch? that should trigger the petstore integration in the gihtub workflow.

@sekikn
Copy link
Contributor Author

sekikn commented Feb 10, 2026

@wing328 Thanks! I'll rebase it shortly.
I'll adopt my change for PetApiTest.groovy and yours for others, but let me know if I'm misunderstanding your intention.

@wing328
Copy link
Member

wing328 commented Feb 10, 2026

Yes. Please adopt the tests accordingly.

@sekikn sekikn force-pushed the 22907-add-accept-header-to-groovy-generator branch from 9bd583a to c3fa247 Compare February 10, 2026 14:25
@sekikn
Copy link
Contributor Author

sekikn commented Feb 10, 2026

I've just pushed a rebased and squashed commit.

@wing328
Copy link
Member

wing328 commented Feb 10, 2026

all tests passed

let's give it a try

thanks for the contribution

@wing328 wing328 merged commit 8d88b82 into OpenAPITools:master Feb 10, 2026
16 checks passed
@wing328 wing328 added this to the 7.19.0 milestone Feb 10, 2026
@sekikn sekikn deleted the 22907-add-accept-header-to-groovy-generator branch February 10, 2026 15:08
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.

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

2 participants