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
  • #10195
Closed
Open
Issue created Aug 19, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Go] Skip setting readOnly properties with default values in model constructors

Created by: code-lucidal58

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

In Go client-side SDK, there are two model constructors, New<model-name>() and New<model-name>WithDefaults(). Both of these functions' purpose is to set properties with their default values, except that the former i.e. New<model-name>(), excludes required properties. These functions are setting the default values for readOnly properties as well. This leads to the addition of such properties to the JSON request. Howver, readOnly properties should not be part of request for create and update requests.

openapi-generator version

v5.2.1

OpenAPI declaration file content or url
    ReadOnlyWithDefault:
      type: object
      properties:
        prop1:
          type: string
          readOnly: true
        prop2:
          type: string
          readOnly: true
          default: 'defaultProp2'
        prop3:
          type: string
          default: 'defaultProp3'

The generated Model constructors looks as follows:

func NewReadOnlyWithDefault() *ReadOnlyWithDefault {
	this := ReadOnlyWithDefault{}
	var prop2 string = "defaultProp2"
	this.Prop2 = &prop2
	var prop3 string = "defaultProp3"
	this.Prop3 = &prop3
	return &this
}

However, it should look as below:

func NewReadOnlyWithDefault() *ReadOnlyWithDefault {
	this := ReadOnlyWithDefault{}
	var prop3 string = "defaultProp3"
	this.Prop3 = &prop3
	return &this
}
Suggest a fix

Add a config flag: skipReadonlyPropertiesInInt, whose default value will be false to get the behaviour as it is right now. If this flag is true then skip readonly properties in the model constructors.

Assignee
Assign to
Time tracking