OpenAPITools / OpenAPITools/openapi-generator

[BUG][jaxrs-spec] openApiNullable doesn't appear to be respected

Open
#9,018 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The openApiNullable option on the jaxrs-spec generator doesn't appear to be used. It would be nice to have this functionality since I want to have request objects which have nullable fields so that I can know whether or not a field is being set to null or if it simply wasn't provided in the payload if it's optional. I see that other Java generators seem to support this option so it would be nice to have.

openapi-generator version

5.0.1

OpenAPI declaration file content or url

N/A. I didn't think it was necessary to add the full spec, but I can if needed.

Generation Details

Using the Maven plugin with the following configuration:

                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
                    <output>${project.build.directory}/generated-sources/openapi</output>
                    <apiPackage>com.foo.bar.web.api.v1</apiPackage>
                    <modelPackage>com.foo.bar.web.api.v1</modelPackage>
                    <generatorName>jaxrs-spec</generatorName>
                    <configOptions>
                        <interfaceOnly>true</interfaceOnly>
                        <generateBuilders>false</generateBuilders>
                        <useSwaggerAnnotations>false</useSwaggerAnnotations>
                        <openApiNullable>true</openApiNullable>
                        <generatePom>false</generatePom>
                    </configOptions>
                </configuration>
Steps to reproduce
  1. Create a schema which has at least 1 nullable property.
  2. Run the openapi generator maven plugin with the provided configuration.
  3. The resulting POJO's do not use JsonNullable
Suggest a fix

I'm a new user so I don't fully understand how this works, but it looks like this is probably just an update to some templates? I see the openApiNullable option referenced in other generators such as the one for Java clients.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the jaxrs-spec generator configuration and its model-generation templates, then compare how the other Java generators reference openApiNullable and JsonNullable. Reproduce with the Maven plugin configuration and a schema containing a nullable property; done means the generated jaxrs-spec POJO uses JsonNullable for that property.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.