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

[BUG] [Java] [JaxRS] readOnly/writeOnly not respected in "required" attribute bean validaion #9654

Open
5 of 6 tasks
mickroll opened this issue Jun 2, 2021 · 0 comments
Open
5 of 6 tasks

Comments

@mickroll
Copy link
Contributor

mickroll commented Jun 2, 2021

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

Currently, the attribute parameters readOnly and writeOnly are ignored when generating bean validation @NotNull annotation.

Spec says:

If a readOnly or writeOnly property is included in the required list, required affects just the relevant scope.
see https://swagger.io/docs/specification/data-models/data-types/#readonly-writeonly

Using @NotNull on these fields is wrong, because it fails validation in the other direction, where the attribute is intentionally not present.

openapi-generator version

5.1.1

OpenAPI declaration file content or url
      "Example": {
        "type": "object",
        "required": ["displayName_r", "displayName_w"],
        "properties": {
          "displayName_r": {
            "type": "string",
            "readOnly": true
          },
          "displayName_w": {
            "type": "string",
            "writeOnly": true
          }
        }
      },
Generation Details
                            <generatorName>jaxrs-spec</generatorName>
                            <configOptions>
                                <interfaceOnly>true</interfaceOnly>
                                <returnResponse>false</returnResponse>
                                <sourceFolder>java</sourceFolder>
                                <useSwaggerAnnotations>false</useSwaggerAnnotations>
                                <generatePom>false</generatePom>
                                <dateLibrary>java8</dateLibrary>
                            </configOptions>
Steps to reproduce
  1. Generate Code
  2. Check contents of generated Example.java -> getters of displayName_r/displayName_w define @NotNull
Related issues/PRs

#9222: "readOnly/writeOnly not respected in jackson annotation"

Suggest a fix

Update beanValidation.mustache to respect readOnly/writeOnly markers:

{{#required}}{{^isReadOnly}}{{^isWriteOnly}}
  @NotNull
{{/isWriteOnly}}{{/isReadOnly}}{{/required}}
{{>beanValidationCore}}

instead of

{{#required}}
  @NotNull
{{/required}}
{{>beanValidationCore}}
@mickroll mickroll changed the title [BUG] Description [BUG] [Java] [JaxRS] readOnly/writeOnly not respected in "required" attribute bean validaion Jun 2, 2021
gokul-krishnamoorthy added a commit to gokul-krishnamoorthy/openapi-generator that referenced this issue Nov 18, 2021
@mickroll mickroll reopened this Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant