Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure models that have variables that contain a complexType of time.Time import the time module #17452

Merged
merged 6 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,11 @@ public ModelsMap postProcessModels(ModelsMap objs) {
}

for (CodegenProperty cp : codegenProperties) {
if (!addedTimeImport && ("time.Time".equals(cp.dataType) || (cp.items != null && "time.Time".equals(cp.items.dataType)))) {
if (!addedTimeImport && ("time.Time".equals(cp.dataType) || (cp.items != null && "time.Time".equals(cp.items.complexType)))) {
imports.add(createMapping("import", "time"));
addedTimeImport = true;
}

if (!addedOSImport && ("*os.File".equals(cp.dataType) ||
(cp.items != null && "*os.File".equals(cp.items.dataType)))) {
imports.add(createMapping("import", "os"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,11 +1335,22 @@ components:
type: http
scheme: signature
schemas:
MapWithDateTime:
type: object
additionalProperties:
items:
format: date-time
type: string
type: array
Foo:
type: object
required:
- bar
properties:
bar:
$ref: '#/components/schemas/Bar'
map:
$ref: '#/components/schemas/MapWithDateTime'
Bar:
type: string
default: bar
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.13
require (
github.com/OpenAPITools/openapi-generator/samples/client/petstore/go/go-petstore v0.0.0-00010101000000-000000000000
github.com/go-openapi/swag v0.22.3
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.2.0
github.com/stretchr/testify v1.8.4
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0
)
1,163 changes: 1,163 additions & 0 deletions samples/client/petstore/go/go.sum

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1245,13 +1245,33 @@ components:
description: Pet object that needs to be added to the store
required: true
schemas:
MapWithDateTime:
additionalProperties:
items:
format: date-time
type: string
type: array
type: object
Foo:
example:
bar: bar
map:
key:
- 2000-01-23T04:56:07.000+00:00
- 2000-01-23T04:56:07.000+00:00
properties:
bar:
default: bar
type: string
map:
additionalProperties:
items:
format: date-time
type: string
type: array
type: object
required:
- bar
type: object
Bar:
default: bar
Expand Down Expand Up @@ -2133,6 +2153,10 @@ components:
example:
string:
bar: bar
map:
key:
- 2000-01-23T04:56:07.000+00:00
- 2000-01-23T04:56:07.000+00:00
properties:
string:
$ref: '#/components/schemas/Foo'
Expand Down
31 changes: 26 additions & 5 deletions samples/openapi3/client/petstore/go/go-petstore/docs/Foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Bar** | Pointer to **string** | | [optional] [default to "bar"]
**Bar** | **string** | | [default to "bar"]
**Map** | Pointer to [**map[string][]time.Time**](array.md) | | [optional]

## Methods

### NewFoo

`func NewFoo() *Foo`
`func NewFoo(bar string, ) *Foo`

NewFoo instantiates a new Foo object
This constructor will assign default values to properties that have it defined,
Expand Down Expand Up @@ -44,11 +45,31 @@ and a boolean to check if the value has been set.

SetBar sets Bar field to given value.

### HasBar

`func (o *Foo) HasBar() bool`
### GetMap

HasBar returns a boolean if a field has been set.
`func (o *Foo) GetMap() map[string][]time.Time`

GetMap returns the Map field if non-nil, zero value otherwise.

### GetMapOk

`func (o *Foo) GetMapOk() (*map[string][]time.Time, bool)`

GetMapOk returns a tuple with the Map field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetMap

`func (o *Foo) SetMap(v map[string][]time.Time)`

SetMap sets Map field to given value.

### HasMap

`func (o *Foo) HasMap() bool`

HasMap 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)
Expand Down
87 changes: 68 additions & 19 deletions samples/openapi3/client/petstore/go/go-petstore/model_foo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading