forked from loafle/openapi-generator-original
Skip setting readOnly properties with default values in model constructors (#10196)
* skipReadonlyPropertiesInInt flag to go SDK * minor amendments * update docs for go
This commit is contained in:
@@ -7,3 +7,4 @@ additionalProperties:
|
||||
packageName: petstore
|
||||
disallowAdditionalPropertiesIfNotPresent: false
|
||||
generateInterfaces: true
|
||||
skipReadonlyPropertiesInInt: false
|
||||
@@ -15,6 +15,7 @@ sidebar_label: go-experimental
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
|structPrefix|whether to prefix struct with the class name. e.g. DeletePetOpts => PetApiDeletePetOpts| |false|
|
||||
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and onlye one match in oneOf's schemas) will be skipped.| |false|
|
||||
|skipReadonlyPropertiesInInt|Skip default values to the readOnly properties in the model init function./ /false/
|
||||
|withAWSV4Signature|whether to include AWS v4 signature support| |false|
|
||||
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default in GitHub PRs and diffs| |false|
|
||||
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
|
||||
|
||||
@@ -15,6 +15,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||
|packageVersion|Go package version.| |1.0.0|
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
|skipReadonlyPropertiesInInit|Skip default values to the readOnly properties in the model init function| |true|
|
||||
|structPrefix|whether to prefix struct with the class name. e.g. DeletePetOpts => PetApiDeletePetOpts| |false|
|
||||
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false|
|
||||
|withAWSV4Signature|whether to include AWS v4 signature support| |false|
|
||||
|
||||
@@ -388,4 +388,7 @@ public class CodegenConstants {
|
||||
"If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.";
|
||||
public static final String USE_ONEOF_DISCRIMINATOR_LOOKUP = "useOneOfDiscriminatorLookup";
|
||||
public static final String USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC = "Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.";
|
||||
|
||||
public static final String SKIP_READONLY_PROPERTIES_IN_INIT = "skipReadonlyPropertiesInInit";
|
||||
public static final String SKIP_READONLY_PROPERTIES_IN_INIT_DESC = "Skip default values to the readOnly properties in the model init function";
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
protected String goImportAlias = "openapiclient";
|
||||
protected boolean isGoSubmodule = false;
|
||||
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
|
||||
protected boolean skipReadonlyPropertiesInInt = false;
|
||||
|
||||
// A cache to efficiently lookup schema `toModelName()` based on the schema Key
|
||||
private Map<String, String> schemaKeyToModelNameCache = new HashMap<>();
|
||||
@@ -112,6 +113,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC).defaultValue("false"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT, CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT_DESC).defaultValue("true"));
|
||||
// option to change how we process + set the data in the 'additionalProperties' keyword.
|
||||
CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean(
|
||||
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT,
|
||||
@@ -240,6 +242,12 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, getUseOneOfDiscriminatorLookup());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT)) {
|
||||
setSkipReadonlyPropertiesInInit(convertPropertyToBooleanAndWriteBack(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT, getSkipReadonlyPropertiesInInit());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT)) {
|
||||
this.setDisallowAdditionalPropertiesIfNotPresent(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT).toString()));
|
||||
@@ -266,6 +274,14 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
return this.useOneOfDiscriminatorLookup;
|
||||
}
|
||||
|
||||
public void setSkipReadonlyPropertiesInInit(boolean skipReadonlyPropertiesInInt) {
|
||||
this.skipReadonlyPropertiesInInt = skipReadonlyPropertiesInInt;
|
||||
}
|
||||
|
||||
public boolean getSkipReadonlyPropertiesInInit() {
|
||||
return this.skipReadonlyPropertiesInInt;
|
||||
}
|
||||
|
||||
public void setGoImportAlias(String goImportAlias) {
|
||||
this.goImportAlias = goImportAlias;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{dataType}}{{^-last}
|
||||
{{^required}}
|
||||
{{#defaultValue}}
|
||||
{{^vendorExtensions.x-golang-is-container}}
|
||||
{{#skipReadonlyPropertiesInInt}}
|
||||
{{#isNullable}}
|
||||
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
|
||||
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
|
||||
@@ -51,6 +52,19 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{dataType}}{{^-last}
|
||||
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
|
||||
this.{{name}} = &{{nameInCamelCase}}
|
||||
{{/isNullable}}
|
||||
{{/skipReadonlyPropertiesInInt}}
|
||||
{{^skipReadonlyPropertiesInInt}}
|
||||
{{^isReadOnly}}
|
||||
{{#isNullable}}
|
||||
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
|
||||
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
|
||||
this.{{name}} = &{{nameInCamelCase}}
|
||||
{{/isNullable}}
|
||||
{{/isReadOnly}}
|
||||
{{/skipReadonlyPropertiesInInt}}
|
||||
{{/vendorExtensions.x-golang-is-container}}
|
||||
{{/defaultValue}}
|
||||
{{/required}}
|
||||
@@ -66,6 +80,7 @@ func New{{classname}}WithDefaults() *{{classname}} {
|
||||
{{#vars}}
|
||||
{{#defaultValue}}
|
||||
{{^vendorExtensions.x-golang-is-container}}
|
||||
{{#skipReadonlyPropertiesInInt}}
|
||||
{{#isNullable}}
|
||||
{{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}}
|
||||
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
|
||||
@@ -75,6 +90,20 @@ func New{{classname}}WithDefaults() *{{classname}} {
|
||||
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
|
||||
this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}}
|
||||
{{/isNullable}}
|
||||
{{/skipReadonlyPropertiesInInt}}
|
||||
{{^skipReadonlyPropertiesInInt}}
|
||||
{{^isReadOnly}}
|
||||
{{#isNullable}}
|
||||
{{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}}
|
||||
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
|
||||
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
|
||||
this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}}
|
||||
{{/isNullable}}
|
||||
{{/isReadOnly}}
|
||||
{{/skipReadonlyPropertiesInInt}}
|
||||
{{/vendorExtensions.x-golang-is-container}}
|
||||
{{/defaultValue}}
|
||||
{{/vars}}
|
||||
|
||||
@@ -1914,3 +1914,30 @@ components:
|
||||
type: boolean
|
||||
required:
|
||||
- lengthCm
|
||||
ReadOnlyWithDefault:
|
||||
type: object
|
||||
properties:
|
||||
prop1:
|
||||
type: string
|
||||
readOnly: true
|
||||
prop2:
|
||||
type: string
|
||||
readOnly: true
|
||||
default: 'defaultProp2'
|
||||
prop3:
|
||||
type: string
|
||||
default: 'defaultProp3'
|
||||
boolProp1:
|
||||
default: false
|
||||
type: boolean
|
||||
readOnly: true
|
||||
boolProp2:
|
||||
type: boolean
|
||||
default: true
|
||||
intProp1:
|
||||
type: number
|
||||
default: 100
|
||||
readOnly: true
|
||||
intProp2:
|
||||
type: number
|
||||
default: 120
|
||||
|
||||
@@ -1135,6 +1135,55 @@ export interface ReadOnlyFirst {
|
||||
*/
|
||||
baz?: string;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface ReadOnlyWithDefault
|
||||
*/
|
||||
export interface ReadOnlyWithDefault {
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
prop1?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
prop2?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
prop3?: string;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
boolProp1?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
boolProp2?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
intProp1?: number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof ReadOnlyWithDefault
|
||||
*/
|
||||
intProp2?: number;
|
||||
}
|
||||
/**
|
||||
* Model for testing reserved words
|
||||
* @export
|
||||
|
||||
@@ -63,6 +63,7 @@ docs/OuterEnumIntegerDefaultValue.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/ReadOnlyFirst.md
|
||||
docs/ReadOnlyWithDefault.md
|
||||
docs/Return.md
|
||||
docs/SpecialModelName.md
|
||||
docs/StoreApi.md
|
||||
@@ -122,6 +123,7 @@ model_outer_enum_integer.go
|
||||
model_outer_enum_integer_default_value.go
|
||||
model_pet.go
|
||||
model_read_only_first.go
|
||||
model_read_only_with_default.go
|
||||
model_return.go
|
||||
model_tag.go
|
||||
model_user.go
|
||||
|
||||
@@ -168,6 +168,7 @@ Class | Method | HTTP request | Description
|
||||
- [OuterEnumIntegerDefaultValue](docs/OuterEnumIntegerDefaultValue.md)
|
||||
- [Pet](docs/Pet.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
- [ReadOnlyWithDefault](docs/ReadOnlyWithDefault.md)
|
||||
- [Return](docs/Return.md)
|
||||
- [SpecialModelName](docs/SpecialModelName.md)
|
||||
- [Tag](docs/Tag.md)
|
||||
|
||||
@@ -2034,6 +2034,33 @@ components:
|
||||
required:
|
||||
- lengthCm
|
||||
type: object
|
||||
ReadOnlyWithDefault:
|
||||
properties:
|
||||
prop1:
|
||||
readOnly: true
|
||||
type: string
|
||||
prop2:
|
||||
default: defaultProp2
|
||||
readOnly: true
|
||||
type: string
|
||||
prop3:
|
||||
default: defaultProp3
|
||||
type: string
|
||||
boolProp1:
|
||||
default: false
|
||||
readOnly: true
|
||||
type: boolean
|
||||
boolProp2:
|
||||
default: true
|
||||
type: boolean
|
||||
intProp1:
|
||||
default: 100
|
||||
readOnly: true
|
||||
type: number
|
||||
intProp2:
|
||||
default: 120
|
||||
type: number
|
||||
type: object
|
||||
inline_response_default:
|
||||
example:
|
||||
string:
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
# ReadOnlyWithDefault
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Prop1** | Pointer to **string** | | [optional] [readonly]
|
||||
**Prop2** | Pointer to **string** | | [optional] [readonly] [default to "defaultProp2"]
|
||||
**Prop3** | Pointer to **string** | | [optional] [default to "defaultProp3"]
|
||||
**BoolProp1** | Pointer to **bool** | | [optional] [readonly] [default to false]
|
||||
**BoolProp2** | Pointer to **bool** | | [optional] [default to true]
|
||||
**IntProp1** | Pointer to **float32** | | [optional] [readonly] [default to 100]
|
||||
**IntProp2** | Pointer to **float32** | | [optional] [default to 120]
|
||||
|
||||
## Methods
|
||||
|
||||
### NewReadOnlyWithDefault
|
||||
|
||||
`func NewReadOnlyWithDefault() *ReadOnlyWithDefault`
|
||||
|
||||
NewReadOnlyWithDefault instantiates a new ReadOnlyWithDefault object
|
||||
This constructor will assign default values to properties that have it defined,
|
||||
and makes sure properties required by API are set, but the set of arguments
|
||||
will change when the set of required properties is changed
|
||||
|
||||
### NewReadOnlyWithDefaultWithDefaults
|
||||
|
||||
`func NewReadOnlyWithDefaultWithDefaults() *ReadOnlyWithDefault`
|
||||
|
||||
NewReadOnlyWithDefaultWithDefaults instantiates a new ReadOnlyWithDefault object
|
||||
This constructor will only assign default values to properties that have it defined,
|
||||
but it doesn't guarantee that properties required by API are set
|
||||
|
||||
### GetProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetProp1() string`
|
||||
|
||||
GetProp1 returns the Prop1 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetProp1Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetProp1Ok() (*string, bool)`
|
||||
|
||||
GetProp1Ok returns a tuple with the Prop1 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetProp1(v string)`
|
||||
|
||||
SetProp1 sets Prop1 field to given value.
|
||||
|
||||
### HasProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasProp1() bool`
|
||||
|
||||
HasProp1 returns a boolean if a field has been set.
|
||||
|
||||
### GetProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetProp2() string`
|
||||
|
||||
GetProp2 returns the Prop2 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetProp2Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetProp2Ok() (*string, bool)`
|
||||
|
||||
GetProp2Ok returns a tuple with the Prop2 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetProp2(v string)`
|
||||
|
||||
SetProp2 sets Prop2 field to given value.
|
||||
|
||||
### HasProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasProp2() bool`
|
||||
|
||||
HasProp2 returns a boolean if a field has been set.
|
||||
|
||||
### GetProp3
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetProp3() string`
|
||||
|
||||
GetProp3 returns the Prop3 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetProp3Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetProp3Ok() (*string, bool)`
|
||||
|
||||
GetProp3Ok returns a tuple with the Prop3 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetProp3
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetProp3(v string)`
|
||||
|
||||
SetProp3 sets Prop3 field to given value.
|
||||
|
||||
### HasProp3
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasProp3() bool`
|
||||
|
||||
HasProp3 returns a boolean if a field has been set.
|
||||
|
||||
### GetBoolProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetBoolProp1() bool`
|
||||
|
||||
GetBoolProp1 returns the BoolProp1 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetBoolProp1Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetBoolProp1Ok() (*bool, bool)`
|
||||
|
||||
GetBoolProp1Ok returns a tuple with the BoolProp1 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetBoolProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetBoolProp1(v bool)`
|
||||
|
||||
SetBoolProp1 sets BoolProp1 field to given value.
|
||||
|
||||
### HasBoolProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasBoolProp1() bool`
|
||||
|
||||
HasBoolProp1 returns a boolean if a field has been set.
|
||||
|
||||
### GetBoolProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetBoolProp2() bool`
|
||||
|
||||
GetBoolProp2 returns the BoolProp2 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetBoolProp2Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetBoolProp2Ok() (*bool, bool)`
|
||||
|
||||
GetBoolProp2Ok returns a tuple with the BoolProp2 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetBoolProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetBoolProp2(v bool)`
|
||||
|
||||
SetBoolProp2 sets BoolProp2 field to given value.
|
||||
|
||||
### HasBoolProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasBoolProp2() bool`
|
||||
|
||||
HasBoolProp2 returns a boolean if a field has been set.
|
||||
|
||||
### GetIntProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetIntProp1() float32`
|
||||
|
||||
GetIntProp1 returns the IntProp1 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetIntProp1Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetIntProp1Ok() (*float32, bool)`
|
||||
|
||||
GetIntProp1Ok returns a tuple with the IntProp1 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetIntProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetIntProp1(v float32)`
|
||||
|
||||
SetIntProp1 sets IntProp1 field to given value.
|
||||
|
||||
### HasIntProp1
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasIntProp1() bool`
|
||||
|
||||
HasIntProp1 returns a boolean if a field has been set.
|
||||
|
||||
### GetIntProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetIntProp2() float32`
|
||||
|
||||
GetIntProp2 returns the IntProp2 field if non-nil, zero value otherwise.
|
||||
|
||||
### GetIntProp2Ok
|
||||
|
||||
`func (o *ReadOnlyWithDefault) GetIntProp2Ok() (*float32, bool)`
|
||||
|
||||
GetIntProp2Ok returns a tuple with the IntProp2 field if it's non-nil, zero value otherwise
|
||||
and a boolean to check if the value has been set.
|
||||
|
||||
### SetIntProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) SetIntProp2(v float32)`
|
||||
|
||||
SetIntProp2 sets IntProp2 field to given value.
|
||||
|
||||
### HasIntProp2
|
||||
|
||||
`func (o *ReadOnlyWithDefault) HasIntProp2() bool`
|
||||
|
||||
HasIntProp2 returns a boolean if a field has been set.
|
||||
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
API version: 1.0.0
|
||||
*/
|
||||
|
||||
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
||||
|
||||
package petstore
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// ReadOnlyWithDefault struct for ReadOnlyWithDefault
|
||||
type ReadOnlyWithDefault struct {
|
||||
Prop1 *string `json:"prop1,omitempty"`
|
||||
Prop2 *string `json:"prop2,omitempty"`
|
||||
Prop3 *string `json:"prop3,omitempty"`
|
||||
BoolProp1 *bool `json:"boolProp1,omitempty"`
|
||||
BoolProp2 *bool `json:"boolProp2,omitempty"`
|
||||
IntProp1 *float32 `json:"intProp1,omitempty"`
|
||||
IntProp2 *float32 `json:"intProp2,omitempty"`
|
||||
AdditionalProperties map[string]interface{}
|
||||
}
|
||||
|
||||
type _ReadOnlyWithDefault ReadOnlyWithDefault
|
||||
|
||||
// NewReadOnlyWithDefault instantiates a new ReadOnlyWithDefault object
|
||||
// This constructor will assign default values to properties that have it defined,
|
||||
// and makes sure properties required by API are set, but the set of arguments
|
||||
// will change when the set of required properties is changed
|
||||
func NewReadOnlyWithDefault() *ReadOnlyWithDefault {
|
||||
this := ReadOnlyWithDefault{}
|
||||
var prop3 string = "defaultProp3"
|
||||
this.Prop3 = &prop3
|
||||
var boolProp2 bool = true
|
||||
this.BoolProp2 = &boolProp2
|
||||
var intProp2 float32 = 120
|
||||
this.IntProp2 = &intProp2
|
||||
return &this
|
||||
}
|
||||
|
||||
// NewReadOnlyWithDefaultWithDefaults instantiates a new ReadOnlyWithDefault object
|
||||
// This constructor will only assign default values to properties that have it defined,
|
||||
// but it doesn't guarantee that properties required by API are set
|
||||
func NewReadOnlyWithDefaultWithDefaults() *ReadOnlyWithDefault {
|
||||
this := ReadOnlyWithDefault{}
|
||||
var prop3 string = "defaultProp3"
|
||||
this.Prop3 = &prop3
|
||||
var boolProp2 bool = true
|
||||
this.BoolProp2 = &boolProp2
|
||||
var intProp2 float32 = 120
|
||||
this.IntProp2 = &intProp2
|
||||
return &this
|
||||
}
|
||||
|
||||
// GetProp1 returns the Prop1 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetProp1() string {
|
||||
if o == nil || o.Prop1 == nil {
|
||||
var ret string
|
||||
return ret
|
||||
}
|
||||
return *o.Prop1
|
||||
}
|
||||
|
||||
// GetProp1Ok returns a tuple with the Prop1 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetProp1Ok() (*string, bool) {
|
||||
if o == nil || o.Prop1 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.Prop1, true
|
||||
}
|
||||
|
||||
// HasProp1 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasProp1() bool {
|
||||
if o != nil && o.Prop1 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetProp1 gets a reference to the given string and assigns it to the Prop1 field.
|
||||
func (o *ReadOnlyWithDefault) SetProp1(v string) {
|
||||
o.Prop1 = &v
|
||||
}
|
||||
|
||||
// GetProp2 returns the Prop2 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetProp2() string {
|
||||
if o == nil || o.Prop2 == nil {
|
||||
var ret string
|
||||
return ret
|
||||
}
|
||||
return *o.Prop2
|
||||
}
|
||||
|
||||
// GetProp2Ok returns a tuple with the Prop2 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetProp2Ok() (*string, bool) {
|
||||
if o == nil || o.Prop2 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.Prop2, true
|
||||
}
|
||||
|
||||
// HasProp2 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasProp2() bool {
|
||||
if o != nil && o.Prop2 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetProp2 gets a reference to the given string and assigns it to the Prop2 field.
|
||||
func (o *ReadOnlyWithDefault) SetProp2(v string) {
|
||||
o.Prop2 = &v
|
||||
}
|
||||
|
||||
// GetProp3 returns the Prop3 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetProp3() string {
|
||||
if o == nil || o.Prop3 == nil {
|
||||
var ret string
|
||||
return ret
|
||||
}
|
||||
return *o.Prop3
|
||||
}
|
||||
|
||||
// GetProp3Ok returns a tuple with the Prop3 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetProp3Ok() (*string, bool) {
|
||||
if o == nil || o.Prop3 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.Prop3, true
|
||||
}
|
||||
|
||||
// HasProp3 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasProp3() bool {
|
||||
if o != nil && o.Prop3 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetProp3 gets a reference to the given string and assigns it to the Prop3 field.
|
||||
func (o *ReadOnlyWithDefault) SetProp3(v string) {
|
||||
o.Prop3 = &v
|
||||
}
|
||||
|
||||
// GetBoolProp1 returns the BoolProp1 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetBoolProp1() bool {
|
||||
if o == nil || o.BoolProp1 == nil {
|
||||
var ret bool
|
||||
return ret
|
||||
}
|
||||
return *o.BoolProp1
|
||||
}
|
||||
|
||||
// GetBoolProp1Ok returns a tuple with the BoolProp1 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetBoolProp1Ok() (*bool, bool) {
|
||||
if o == nil || o.BoolProp1 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.BoolProp1, true
|
||||
}
|
||||
|
||||
// HasBoolProp1 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasBoolProp1() bool {
|
||||
if o != nil && o.BoolProp1 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetBoolProp1 gets a reference to the given bool and assigns it to the BoolProp1 field.
|
||||
func (o *ReadOnlyWithDefault) SetBoolProp1(v bool) {
|
||||
o.BoolProp1 = &v
|
||||
}
|
||||
|
||||
// GetBoolProp2 returns the BoolProp2 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetBoolProp2() bool {
|
||||
if o == nil || o.BoolProp2 == nil {
|
||||
var ret bool
|
||||
return ret
|
||||
}
|
||||
return *o.BoolProp2
|
||||
}
|
||||
|
||||
// GetBoolProp2Ok returns a tuple with the BoolProp2 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetBoolProp2Ok() (*bool, bool) {
|
||||
if o == nil || o.BoolProp2 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.BoolProp2, true
|
||||
}
|
||||
|
||||
// HasBoolProp2 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasBoolProp2() bool {
|
||||
if o != nil && o.BoolProp2 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetBoolProp2 gets a reference to the given bool and assigns it to the BoolProp2 field.
|
||||
func (o *ReadOnlyWithDefault) SetBoolProp2(v bool) {
|
||||
o.BoolProp2 = &v
|
||||
}
|
||||
|
||||
// GetIntProp1 returns the IntProp1 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetIntProp1() float32 {
|
||||
if o == nil || o.IntProp1 == nil {
|
||||
var ret float32
|
||||
return ret
|
||||
}
|
||||
return *o.IntProp1
|
||||
}
|
||||
|
||||
// GetIntProp1Ok returns a tuple with the IntProp1 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetIntProp1Ok() (*float32, bool) {
|
||||
if o == nil || o.IntProp1 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.IntProp1, true
|
||||
}
|
||||
|
||||
// HasIntProp1 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasIntProp1() bool {
|
||||
if o != nil && o.IntProp1 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetIntProp1 gets a reference to the given float32 and assigns it to the IntProp1 field.
|
||||
func (o *ReadOnlyWithDefault) SetIntProp1(v float32) {
|
||||
o.IntProp1 = &v
|
||||
}
|
||||
|
||||
// GetIntProp2 returns the IntProp2 field value if set, zero value otherwise.
|
||||
func (o *ReadOnlyWithDefault) GetIntProp2() float32 {
|
||||
if o == nil || o.IntProp2 == nil {
|
||||
var ret float32
|
||||
return ret
|
||||
}
|
||||
return *o.IntProp2
|
||||
}
|
||||
|
||||
// GetIntProp2Ok returns a tuple with the IntProp2 field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *ReadOnlyWithDefault) GetIntProp2Ok() (*float32, bool) {
|
||||
if o == nil || o.IntProp2 == nil {
|
||||
return nil, false
|
||||
}
|
||||
return o.IntProp2, true
|
||||
}
|
||||
|
||||
// HasIntProp2 returns a boolean if a field has been set.
|
||||
func (o *ReadOnlyWithDefault) HasIntProp2() bool {
|
||||
if o != nil && o.IntProp2 != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetIntProp2 gets a reference to the given float32 and assigns it to the IntProp2 field.
|
||||
func (o *ReadOnlyWithDefault) SetIntProp2(v float32) {
|
||||
o.IntProp2 = &v
|
||||
}
|
||||
|
||||
func (o ReadOnlyWithDefault) MarshalJSON() ([]byte, error) {
|
||||
toSerialize := map[string]interface{}{}
|
||||
if o.Prop1 != nil {
|
||||
toSerialize["prop1"] = o.Prop1
|
||||
}
|
||||
if o.Prop2 != nil {
|
||||
toSerialize["prop2"] = o.Prop2
|
||||
}
|
||||
if o.Prop3 != nil {
|
||||
toSerialize["prop3"] = o.Prop3
|
||||
}
|
||||
if o.BoolProp1 != nil {
|
||||
toSerialize["boolProp1"] = o.BoolProp1
|
||||
}
|
||||
if o.BoolProp2 != nil {
|
||||
toSerialize["boolProp2"] = o.BoolProp2
|
||||
}
|
||||
if o.IntProp1 != nil {
|
||||
toSerialize["intProp1"] = o.IntProp1
|
||||
}
|
||||
if o.IntProp2 != nil {
|
||||
toSerialize["intProp2"] = o.IntProp2
|
||||
}
|
||||
|
||||
for key, value := range o.AdditionalProperties {
|
||||
toSerialize[key] = value
|
||||
}
|
||||
|
||||
return json.Marshal(toSerialize)
|
||||
}
|
||||
|
||||
func (o *ReadOnlyWithDefault) UnmarshalJSON(bytes []byte) (err error) {
|
||||
varReadOnlyWithDefault := _ReadOnlyWithDefault{}
|
||||
|
||||
if err = json.Unmarshal(bytes, &varReadOnlyWithDefault); err == nil {
|
||||
*o = ReadOnlyWithDefault(varReadOnlyWithDefault)
|
||||
}
|
||||
|
||||
additionalProperties := make(map[string]interface{})
|
||||
|
||||
if err = json.Unmarshal(bytes, &additionalProperties); err == nil {
|
||||
delete(additionalProperties, "prop1")
|
||||
delete(additionalProperties, "prop2")
|
||||
delete(additionalProperties, "prop3")
|
||||
delete(additionalProperties, "boolProp1")
|
||||
delete(additionalProperties, "boolProp2")
|
||||
delete(additionalProperties, "intProp1")
|
||||
delete(additionalProperties, "intProp2")
|
||||
o.AdditionalProperties = additionalProperties
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type NullableReadOnlyWithDefault struct {
|
||||
value *ReadOnlyWithDefault
|
||||
isSet bool
|
||||
}
|
||||
|
||||
func (v NullableReadOnlyWithDefault) Get() *ReadOnlyWithDefault {
|
||||
return v.value
|
||||
}
|
||||
|
||||
func (v *NullableReadOnlyWithDefault) Set(val *ReadOnlyWithDefault) {
|
||||
v.value = val
|
||||
v.isSet = true
|
||||
}
|
||||
|
||||
func (v NullableReadOnlyWithDefault) IsSet() bool {
|
||||
return v.isSet
|
||||
}
|
||||
|
||||
func (v *NullableReadOnlyWithDefault) Unset() {
|
||||
v.value = nil
|
||||
v.isSet = false
|
||||
}
|
||||
|
||||
func NewNullableReadOnlyWithDefault(val *ReadOnlyWithDefault) *NullableReadOnlyWithDefault {
|
||||
return &NullableReadOnlyWithDefault{value: val, isSet: true}
|
||||
}
|
||||
|
||||
func (v NullableReadOnlyWithDefault) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.value)
|
||||
}
|
||||
|
||||
func (v *NullableReadOnlyWithDefault) UnmarshalJSON(src []byte) error {
|
||||
v.isSet = true
|
||||
return json.Unmarshal(src, &v.value)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user