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

fix: #10618 Using incorrect @Multipart instead of @FormParam in microprofile java client #20690

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jochenr
Copy link

@jochenr jochenr commented Feb 19, 2025

Fix #10618

[BUG][JAVA] Using incorrect @multipart instead of @FormParam when generated Microprofile java client

#10618

To fix #10618 I changed two template files of the Java client codegenerator for mircoprofile:

  • modules/openapi-generator/src/main/resources/Java/libraries/microprofile/api.mustache
  • modules/openapi-generator/src/main/resources/Java/libraries/microprofile/formParams.mustache

The non-standard annotations "@multipart" are replaced by the microprofile annotations "@FormParam".
the corresponding import "import org.apache.cxf.jaxrs.ext.multipart.*;" is deleted.

To be able to use required params the new version of the template uses "@NotNull" instead of "@multipart(value = "password", required = "true")", if "true" is set and the OpenAPI contract defines a field as required.

@Multipart(value = "name")

becomes

@FormParam("name")

and

@Multipart(value = "name", required = "true")

becomes

@NotNull @FormParam("name")

if "useBeanValidation" is set ton true

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 Git BASH)
    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 is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)

…ram in microprofile java client

[BUG][JAVA] Using incorrect @multipart instead of @FormParam when generated Microprofile java client OpenAPITools#10618
OpenAPITools#10618
@wing328
Copy link
Member

wing328 commented Feb 23, 2025

thanks for the PR

please update the samples to fix https://github.com/OpenAPITools/openapi-generator/actions/runs/13416373732/job/37671155659?pr=20690

@jochenr
Copy link
Author

jochenr commented Feb 24, 2025

oh I didn't commit and push the samles after generation.
fixed now.
and I did some additonal cleanup

@wing328
Copy link
Member

wing328 commented Feb 26, 2025

https://github.com/OpenAPITools/openapi-generator/actions/runs/13493811133/job/37840378475?pr=20690

please have a look at the test failure when you've time

@jochenr
Copy link
Author

jochenr commented Feb 26, 2025

I got rid of the compilation error, but now I get this error:

[ERROR] Failed to execute goal org.jboss.jandex:jandex-maven-plugin:1.2.3:jandex (make-index) on project openapi-microprofile-server: Execution make-index of goal org.jboss.jandex:jandex-maven-plugin:1.2.3:jandex failed: Cannot read the array length because "bytes" is null -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jboss.jandex:jandex-maven-plugin:1.2.3:jandex (make-index) on project openapi-microprofile-server: Execution make-index of goal org.jboss.jandex:jandex-maven-plugin:1.2.3:jandex failed: Cannot read the array length because "bytes" is null

I have no clue what the cause of this could be.
using the latest version of the jandex-plugin makes no difference

After switching to

<plugin>
        <groupId>io.smallrye</groupId>
        <artifactId>jandex-maven-plugin</artifactId>

the java samples seem to build again.

@wing328 wing328 modified the milestones: 7.12.0, 7.13.0 Feb 28, 2025
@wing328
Copy link
Member

wing328 commented Mar 8, 2025

To be able to use required params the new version of the template uses "https://github.com/NotNull" instead of "https://github.com/multipart(value = "password", required = "true")", if "true" is set and the OpenAPI contract defines a field as required.

what if the required parameter is nullable (nullable: true) ?

@jochenr
Copy link
Author

jochenr commented Mar 9, 2025

As far as I understand the spec and docs there is no "required" attribute for the microprofile/Jakarta REST @FormParam annotation.

So I decided to combine required with bean-validation

{{#required}}{{#useBeanValidation}}@NotNull {{/useBeanValidation}}{{/required}}@FormParam

instead of using the proprietary required attribute of CXF

@Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}

IMHO you have to use BeanValidation additionally to Microprofile to get null checks.
At least I have no better idea.

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][JAVA] Using incorrect @Multipart instead of @FormParam when generated Microprofile java client
2 participants