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
  • #5026
Closed
Open
Issue created Jan 17, 2020 by Administrator@rootContributor

[Spring-java] required readonly attribute generate not null field

Created by: esoni88

Hi All, regard required, readOnly and writeOnly open api specification report:

If a readOnly or writeOnly property is included in the required list, required affects just the relevant scope – responses only or requests only. That is, read-only required properties apply to responses only, and write-only required properties – to requests only.

so if i declare a field required and read-only means that in the request that field should be empty.

example with this yam:

Poll:
  title: Poll
  type: object
  description: A poll is an election, or a survey of people's opinions to ask inside the platform
  properties:
    id:
      type: integer
      format: int64
      readOnly: true
      description: Unique Identifier of a Poll

openapigenerator generate the class with id not null

@JsonProperty("id") private Long id;

@NotNull public Long getId() { return id; }

public void setId(Long id) { this.id = id; }

What happen if i run my code and i perform a post with an empty id ? Spring raise bad request but it is not correct. For openapi specification read-only required properties apply to responses only and not for the request. I think that openapi generator should generate @NotNull only for writeOnly property

Assignee
Assign to
Time tracking