Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9654
Closed
Open
Issue created Jun 02, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: mickroll

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 (closed): "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}}
Assignee
Assign to
Time tracking