forked from loafle/openapi-generator-original
12551 [Go] Skipping marshalling of readonly fields (#14335)
* Skip toSerialize for readOnly fields * Commit regenerated files
This commit is contained in:
parent
921199bba7
commit
d0800c46e1
@ -311,6 +311,7 @@ func (o {{classname}}) ToMap() (map[string]interface{}, error) {
|
|||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{! if argument is not nullable, don't set it if it is nil}}
|
{{! if argument is not nullable, don't set it if it is nil}}
|
||||||
{{^isNullable}}
|
{{^isNullable}}
|
||||||
|
{{^isReadOnly}}
|
||||||
{{#required}}
|
{{#required}}
|
||||||
toSerialize["{{baseName}}"] = o.{{name}}
|
toSerialize["{{baseName}}"] = o.{{name}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
@ -319,6 +320,10 @@ func (o {{classname}}) ToMap() (map[string]interface{}, error) {
|
|||||||
toSerialize["{{baseName}}"] = o.{{name}}
|
toSerialize["{{baseName}}"] = o.{{name}}
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
|
{{/isReadOnly}}
|
||||||
|
{{#isReadOnly}}
|
||||||
|
// skip: {{baseName}} is readOnly
|
||||||
|
{{/isReadOnly}}
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
{{#isAdditionalPropertiesTrue}}
|
{{#isAdditionalPropertiesTrue}}
|
||||||
|
@ -286,4 +286,24 @@ public class GoClientCodegenTest {
|
|||||||
TestUtils.assertFileContains(Paths.get(output + "/test/api_pet_test.go"),
|
TestUtils.assertFileContains(Paths.get(output + "/test/api_pet_test.go"),
|
||||||
"httpRes, err := apiClient.PetApi.PetDelete(context.Background()).Execute()");
|
"httpRes, err := apiClient.PetApi.PetDelete(context.Background()).Execute()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyReadOnlyAttributes() throws IOException {
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setGeneratorName("go")
|
||||||
|
.setInputSpec("src/test/resources/3_0/property-readonly.yaml")
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||||
|
files.forEach(File::deleteOnExit);
|
||||||
|
|
||||||
|
TestUtils.assertFileExists(Paths.get(output + "/model_request.go"));
|
||||||
|
TestUtils.assertFileContains(Paths.get(output + "/model_request.go"),
|
||||||
|
"// skip: customerCode is readOnly");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
title: Example
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
servers:
|
||||||
|
- url: http://api.example.xyz/v1
|
||||||
|
paths:
|
||||||
|
/test:
|
||||||
|
post:
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Request'
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: responses
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Response'
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Request:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
customerCode:
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
example: '0001'
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
example: 'first'
|
||||||
|
Response:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
customerCode:
|
||||||
|
type: string
|
||||||
|
example: '0001'
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
example: 'first'
|
@ -114,12 +114,8 @@ func (o HasOnlyReadOnly) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (o HasOnlyReadOnly) ToMap() (map[string]interface{}, error) {
|
func (o HasOnlyReadOnly) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
if !isNil(o.Bar) {
|
// skip: bar is readOnly
|
||||||
toSerialize["bar"] = o.Bar
|
// skip: foo is readOnly
|
||||||
}
|
|
||||||
if !isNil(o.Foo) {
|
|
||||||
toSerialize["foo"] = o.Foo
|
|
||||||
}
|
|
||||||
return toSerialize, nil
|
return toSerialize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,15 +174,11 @@ func (o Name) MarshalJSON() ([]byte, error) {
|
|||||||
func (o Name) ToMap() (map[string]interface{}, error) {
|
func (o Name) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
toSerialize["name"] = o.Name
|
toSerialize["name"] = o.Name
|
||||||
if !isNil(o.SnakeCase) {
|
// skip: snake_case is readOnly
|
||||||
toSerialize["snake_case"] = o.SnakeCase
|
|
||||||
}
|
|
||||||
if !isNil(o.Property) {
|
if !isNil(o.Property) {
|
||||||
toSerialize["property"] = o.Property
|
toSerialize["property"] = o.Property
|
||||||
}
|
}
|
||||||
if !isNil(o.Var123Number) {
|
// skip: 123Number is readOnly
|
||||||
toSerialize["123Number"] = o.Var123Number
|
|
||||||
}
|
|
||||||
return toSerialize, nil
|
return toSerialize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,9 +114,7 @@ func (o ReadOnlyFirst) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (o ReadOnlyFirst) ToMap() (map[string]interface{}, error) {
|
func (o ReadOnlyFirst) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
if !isNil(o.Bar) {
|
// skip: bar is readOnly
|
||||||
toSerialize["bar"] = o.Bar
|
|
||||||
}
|
|
||||||
if !isNil(o.Baz) {
|
if !isNil(o.Baz) {
|
||||||
toSerialize["baz"] = o.Baz
|
toSerialize["baz"] = o.Baz
|
||||||
}
|
}
|
||||||
|
@ -117,12 +117,8 @@ func (o HasOnlyReadOnly) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (o HasOnlyReadOnly) ToMap() (map[string]interface{}, error) {
|
func (o HasOnlyReadOnly) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
if !isNil(o.Bar) {
|
// skip: bar is readOnly
|
||||||
toSerialize["bar"] = o.Bar
|
// skip: foo is readOnly
|
||||||
}
|
|
||||||
if !isNil(o.Foo) {
|
|
||||||
toSerialize["foo"] = o.Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value := range o.AdditionalProperties {
|
for key, value := range o.AdditionalProperties {
|
||||||
toSerialize[key] = value
|
toSerialize[key] = value
|
||||||
|
@ -177,15 +177,11 @@ func (o Name) MarshalJSON() ([]byte, error) {
|
|||||||
func (o Name) ToMap() (map[string]interface{}, error) {
|
func (o Name) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
toSerialize["name"] = o.Name
|
toSerialize["name"] = o.Name
|
||||||
if !isNil(o.SnakeCase) {
|
// skip: snake_case is readOnly
|
||||||
toSerialize["snake_case"] = o.SnakeCase
|
|
||||||
}
|
|
||||||
if !isNil(o.Property) {
|
if !isNil(o.Property) {
|
||||||
toSerialize["property"] = o.Property
|
toSerialize["property"] = o.Property
|
||||||
}
|
}
|
||||||
if !isNil(o.Var123Number) {
|
// skip: 123Number is readOnly
|
||||||
toSerialize["123Number"] = o.Var123Number
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value := range o.AdditionalProperties {
|
for key, value := range o.AdditionalProperties {
|
||||||
toSerialize[key] = value
|
toSerialize[key] = value
|
||||||
|
@ -117,9 +117,7 @@ func (o ReadOnlyFirst) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (o ReadOnlyFirst) ToMap() (map[string]interface{}, error) {
|
func (o ReadOnlyFirst) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
if !isNil(o.Bar) {
|
// skip: bar is readOnly
|
||||||
toSerialize["bar"] = o.Bar
|
|
||||||
}
|
|
||||||
if !isNil(o.Baz) {
|
if !isNil(o.Baz) {
|
||||||
toSerialize["baz"] = o.Baz
|
toSerialize["baz"] = o.Baz
|
||||||
}
|
}
|
||||||
|
@ -294,24 +294,16 @@ func (o ReadOnlyWithDefault) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (o ReadOnlyWithDefault) ToMap() (map[string]interface{}, error) {
|
func (o ReadOnlyWithDefault) ToMap() (map[string]interface{}, error) {
|
||||||
toSerialize := map[string]interface{}{}
|
toSerialize := map[string]interface{}{}
|
||||||
if !isNil(o.Prop1) {
|
// skip: prop1 is readOnly
|
||||||
toSerialize["prop1"] = o.Prop1
|
// skip: prop2 is readOnly
|
||||||
}
|
|
||||||
if !isNil(o.Prop2) {
|
|
||||||
toSerialize["prop2"] = o.Prop2
|
|
||||||
}
|
|
||||||
if !isNil(o.Prop3) {
|
if !isNil(o.Prop3) {
|
||||||
toSerialize["prop3"] = o.Prop3
|
toSerialize["prop3"] = o.Prop3
|
||||||
}
|
}
|
||||||
if !isNil(o.BoolProp1) {
|
// skip: boolProp1 is readOnly
|
||||||
toSerialize["boolProp1"] = o.BoolProp1
|
|
||||||
}
|
|
||||||
if !isNil(o.BoolProp2) {
|
if !isNil(o.BoolProp2) {
|
||||||
toSerialize["boolProp2"] = o.BoolProp2
|
toSerialize["boolProp2"] = o.BoolProp2
|
||||||
}
|
}
|
||||||
if !isNil(o.IntProp1) {
|
// skip: intProp1 is readOnly
|
||||||
toSerialize["intProp1"] = o.IntProp1
|
|
||||||
}
|
|
||||||
if !isNil(o.IntProp2) {
|
if !isNil(o.IntProp2) {
|
||||||
toSerialize["intProp2"] = o.IntProp2
|
toSerialize["intProp2"] = o.IntProp2
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user