Skip to content
GitLab
    • Explore Projects Groups Snippets
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
  • Merge requests
  • !13143

[Go] Fix missing import for array/map of file

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged William Cheng requested to merge fix-go-import into master 2 years ago
  • Overview 2
  • Commits 2
  • Pipelines 0
  • Changes 9
  • Fix missing import when a model's property is an array/map of file
  • Add test

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @jirikuncar (2021/01) @ph4r5h4d (2021/04)

Compare
  • master (base)

and
  • latest version
    8c287157
    2 commits, 2 years ago

9 files
+ 229
- 5

    Preferences

    File browser
    Compare changes
modules/openap‎i-generator/src‎
main/java/org/…/‎codegen/languages‎
AbstractGoC‎odegen.java‎ +5 -4
test/resou‎rces/3_0/go‎
petstore-with-fake-endpoints-models-‎for-testing-with-http-signature.yaml‎ +10 -0
samples/openapi3/‎client/petstore/go‎
go-pe‎tstore‎
.openapi-‎generator‎
FI‎LES‎ +2 -0
a‎pi‎
openap‎i.yaml‎ +10 -0
do‎cs‎
MapOfFil‎eTest.md‎ +56 -0
READ‎ME.md‎ +1 -0
model_map_of_‎file_test_.go‎ +142 -0
go.‎mod‎ +1 -1
go.‎sum‎ +2 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
+ 5
- 4
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -625,13 +625,14 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
boolean addedOSImport = false;
for (ModelMap m : objs.getModels()) {
CodegenModel model = m.getModel();
for (CodegenProperty param : model.vars) {
if (!addedTimeImport
&& ("time.Time".equals(param.dataType) || ("[]time.Time".equals(param.dataType)))) {
for (CodegenProperty cp : model.vars) {
if (!addedTimeImport && ("time.Time".equals(cp.dataType) ||
(cp.items != null && "time.Time".equals(cp.items.dataType)))) {
imports.add(createMapping("import", "time"));
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"));
addedOSImport = true;
}
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
+ 5
- 4
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -625,13 +625,14 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
boolean addedOSImport = false;
for (ModelMap m : objs.getModels()) {
CodegenModel model = m.getModel();
for (CodegenProperty param : model.vars) {
if (!addedTimeImport
&& ("time.Time".equals(param.dataType) || ("[]time.Time".equals(param.dataType)))) {
for (CodegenProperty cp : model.vars) {
if (!addedTimeImport && ("time.Time".equals(cp.dataType) ||
(cp.items != null && "time.Time".equals(cp.items.dataType)))) {
imports.add(createMapping("import", "time"));
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"));
addedOSImport = true;
}
modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
+ 10
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -2007,3 +2007,13 @@ components:
'dup-prop':
description: A discriminator value
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
samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES
+ 2
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -51,6 +51,7 @@ docs/HasOnlyReadOnly.md
docs/HealthCheckResult.md
docs/List.md
docs/Mammal.md
docs/MapOfFileTest.md
docs/MapTest.md
docs/MixedPropertiesAndAdditionalPropertiesClass.md
docs/Model200Response.md
@@ -120,6 +121,7 @@ model_has_only_read_only.go
model_health_check_result.go
model_list.go
model_mammal.go
model_map_of_file_test_.go
model_map_test_.go
model_mixed_properties_and_additional_properties_class.go
model_name.go
samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml
+ 10
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -1968,6 +1968,16 @@ components:
required:
- dup-prop
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:
example:
string:
samples/openapi3/client/petstore/go/go-petstore/docs/MapOfFileTest.md 0 → 100644
+ 56
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE

# 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)
samples/openapi3/client/petstore/go/go-petstore/README.md
+ 1
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -157,6 +157,7 @@ Class | Method | HTTP request | Description
- [HealthCheckResult](docs/HealthCheckResult.md)
- [List](docs/List.md)
- [Mammal](docs/Mammal.md)
- [MapOfFileTest](docs/MapOfFileTest.md)
- [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
- [Model200Response](docs/Model200Response.md)
samples/openapi3/client/petstore/go/go-petstore/model_map_of_file_test_.go 0 → 100644
+ 142
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE

/*
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)
}
samples/openapi3/client/petstore/go/go.mod
+ 1
- 1
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -7,6 +7,6 @@ replace go-petstore => ./go-petstore
require (
github.com/stretchr/testify v1.8.0
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
)
samples/openapi3/client/petstore/go/go.sum
+ 2
- 0
  • View file @ 8c287157

  • Edit in single-file editor

  • Open in Web IDE


@@ -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-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-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-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Client: Go Issue: Bug
2
Client: Go Issue: Bug
    Assign labels
  • Manage project labels

Milestone
6.1.0
6.1.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
2
2 participants
Administrator
William Cheng
Reference: OpenAPITools/openapi-generator!13143
Source branch: fix-go-import

Menu

Explore Projects Groups Snippets