Skip to content

[BUG] [Java] [JaxRS] readOnly/writeOnly not respected in jackson annotation #9222

@mickroll

Description

@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

The attribute parameters readOnly and writeOnly are ignored when generating jackson JsonProperty annotation.

openapi-generator version

5.0.1

OpenAPI declaration file content or url
      "Example": {
        "type": "object",
        "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 -> usages of JsonProperty do not define access
Related issues/PRs

none

Suggest a fix

Update pojo.mustache to use
@JsonProperty(value = "{{baseName}}"{{#isReadOnly}}, access = JsonProperty.Access.READ_ONLY{{/isReadOnly}}{{#isWriteOnly}}, access = JsonProperty.Access.WRITE_ONLY{{/isWriteOnly}})
instead of
@JsonProperty("{{baseName}}")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions