[Go] Fix missing import for array/map of file (#13143)

* fix missing import for array/map of file in go client

* add new files
This commit is contained in:
William Cheng 2022-08-10 16:26:10 +08:00 committed by GitHub
parent a6ce5f711b
commit 1c0d6d84d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 229 additions and 5 deletions

View File

@ -625,13 +625,14 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
boolean addedOSImport = false; boolean addedOSImport = false;
for (ModelMap m : objs.getModels()) { for (ModelMap m : objs.getModels()) {
CodegenModel model = m.getModel(); CodegenModel model = m.getModel();
for (CodegenProperty param : model.vars) { for (CodegenProperty cp : model.vars) {
if (!addedTimeImport if (!addedTimeImport && ("time.Time".equals(cp.dataType) ||
&& ("time.Time".equals(param.dataType) || ("[]time.Time".equals(param.dataType)))) { (cp.items != null && "time.Time".equals(cp.items.dataType)))) {
imports.add(createMapping("import", "time")); imports.add(createMapping("import", "time"));
addedTimeImport = true; addedTimeImport = true;
} }
if (!addedOSImport && "*os.File".equals(param.baseType)) { if (!addedOSImport && ("*os.File".equals(cp.dataType) ||
(cp.items != null && "*os.File".equals(cp.items.dataType)))) {
imports.add(createMapping("import", "os")); imports.add(createMapping("import", "os"));
addedOSImport = true; addedOSImport = true;
} }

View File

@ -2007,3 +2007,13 @@ components:
'dup-prop': 'dup-prop':
description: A discriminator value description: A discriminator value
type: string type: string
MapOfFileTest:
description: test map of file in a property
type: object
properties:
'prop_test':
description: a property to test map of file
type: object
additionalProperties:
type: string
format: binary

View File

@ -51,6 +51,7 @@ docs/HasOnlyReadOnly.md
docs/HealthCheckResult.md docs/HealthCheckResult.md
docs/List.md docs/List.md
docs/Mammal.md docs/Mammal.md
docs/MapOfFileTest.md
docs/MapTest.md docs/MapTest.md
docs/MixedPropertiesAndAdditionalPropertiesClass.md docs/MixedPropertiesAndAdditionalPropertiesClass.md
docs/Model200Response.md docs/Model200Response.md
@ -120,6 +121,7 @@ model_has_only_read_only.go
model_health_check_result.go model_health_check_result.go
model_list.go model_list.go
model_mammal.go model_mammal.go
model_map_of_file_test_.go
model_map_test_.go model_map_test_.go
model_mixed_properties_and_additional_properties_class.go model_mixed_properties_and_additional_properties_class.go
model_name.go model_name.go

View File

@ -157,6 +157,7 @@ Class | Method | HTTP request | Description
- [HealthCheckResult](docs/HealthCheckResult.md) - [HealthCheckResult](docs/HealthCheckResult.md)
- [List](docs/List.md) - [List](docs/List.md)
- [Mammal](docs/Mammal.md) - [Mammal](docs/Mammal.md)
- [MapOfFileTest](docs/MapOfFileTest.md)
- [MapTest](docs/MapTest.md) - [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) - [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
- [Model200Response](docs/Model200Response.md) - [Model200Response](docs/Model200Response.md)

View File

@ -1968,6 +1968,16 @@ components:
required: required:
- dup-prop - dup-prop
type: object type: object
MapOfFileTest:
description: test map of file in a property
properties:
prop_test:
additionalProperties:
format: binary
type: string
description: a property to test map of file
type: object
type: object
_foo_get_default_response: _foo_get_default_response:
example: example:
string: string:

View File

@ -0,0 +1,56 @@
# MapOfFileTest
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**PropTest** | Pointer to **map[string]*os.File** | a property to test map of file | [optional]
## Methods
### NewMapOfFileTest
`func NewMapOfFileTest() *MapOfFileTest`
NewMapOfFileTest instantiates a new MapOfFileTest 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
### NewMapOfFileTestWithDefaults
`func NewMapOfFileTestWithDefaults() *MapOfFileTest`
NewMapOfFileTestWithDefaults instantiates a new MapOfFileTest 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
### GetPropTest
`func (o *MapOfFileTest) GetPropTest() map[string]*os.File`
GetPropTest returns the PropTest field if non-nil, zero value otherwise.
### GetPropTestOk
`func (o *MapOfFileTest) GetPropTestOk() (*map[string]*os.File, bool)`
GetPropTestOk returns a tuple with the PropTest field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetPropTest
`func (o *MapOfFileTest) SetPropTest(v map[string]*os.File)`
SetPropTest sets PropTest field to given value.
### HasPropTest
`func (o *MapOfFileTest) HasPropTest() bool`
HasPropTest 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)

View File

@ -0,0 +1,142 @@
/*
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"
"os"
)
// MapOfFileTest test map of file in a property
type MapOfFileTest struct {
// a property to test map of file
PropTest *map[string]*os.File `json:"prop_test,omitempty"`
AdditionalProperties map[string]interface{}
}
type _MapOfFileTest MapOfFileTest
// NewMapOfFileTest instantiates a new MapOfFileTest 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 NewMapOfFileTest() *MapOfFileTest {
this := MapOfFileTest{}
return &this
}
// NewMapOfFileTestWithDefaults instantiates a new MapOfFileTest 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 NewMapOfFileTestWithDefaults() *MapOfFileTest {
this := MapOfFileTest{}
return &this
}
// GetPropTest returns the PropTest field value if set, zero value otherwise.
func (o *MapOfFileTest) GetPropTest() map[string]*os.File {
if o == nil || o.PropTest == nil {
var ret map[string]*os.File
return ret
}
return *o.PropTest
}
// GetPropTestOk returns a tuple with the PropTest field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *MapOfFileTest) GetPropTestOk() (*map[string]*os.File, bool) {
if o == nil || o.PropTest == nil {
return nil, false
}
return o.PropTest, true
}
// HasPropTest returns a boolean if a field has been set.
func (o *MapOfFileTest) HasPropTest() bool {
if o != nil && o.PropTest != nil {
return true
}
return false
}
// SetPropTest gets a reference to the given map[string]*os.File and assigns it to the PropTest field.
func (o *MapOfFileTest) SetPropTest(v map[string]*os.File) {
o.PropTest = &v
}
func (o MapOfFileTest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.PropTest != nil {
toSerialize["prop_test"] = o.PropTest
}
for key, value := range o.AdditionalProperties {
toSerialize[key] = value
}
return json.Marshal(toSerialize)
}
func (o *MapOfFileTest) UnmarshalJSON(bytes []byte) (err error) {
varMapOfFileTest := _MapOfFileTest{}
if err = json.Unmarshal(bytes, &varMapOfFileTest); err == nil {
*o = MapOfFileTest(varMapOfFileTest)
}
additionalProperties := make(map[string]interface{})
if err = json.Unmarshal(bytes, &additionalProperties); err == nil {
delete(additionalProperties, "prop_test")
o.AdditionalProperties = additionalProperties
}
return err
}
type NullableMapOfFileTest struct {
value *MapOfFileTest
isSet bool
}
func (v NullableMapOfFileTest) Get() *MapOfFileTest {
return v.value
}
func (v *NullableMapOfFileTest) Set(val *MapOfFileTest) {
v.value = val
v.isSet = true
}
func (v NullableMapOfFileTest) IsSet() bool {
return v.isSet
}
func (v *NullableMapOfFileTest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableMapOfFileTest(val *MapOfFileTest) *NullableMapOfFileTest {
return &NullableMapOfFileTest{value: val, isSet: true}
}
func (v NullableMapOfFileTest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableMapOfFileTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -7,6 +7,6 @@ replace go-petstore => ./go-petstore
require ( require (
github.com/stretchr/testify v1.8.0 github.com/stretchr/testify v1.8.0
go-petstore v0.0.0-00010101000000-000000000000 go-petstore v0.0.0-00010101000000-000000000000
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 // indirect golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
golang.org/x/oauth2 v0.0.0-20220808172628-8227340efae7 golang.org/x/oauth2 v0.0.0-20220808172628-8227340efae7
) )

View File

@ -301,6 +301,8 @@ golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1g
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 h1:N9Vc/rorQUDes6B9CNdIxAn5jODGj2wzfrei2x4wNj4= golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 h1:N9Vc/rorQUDes6B9CNdIxAn5jODGj2wzfrei2x4wNj4=
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9WKk6PdGOrb9n+SbIvw=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=