[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.