[BUG] Missing import of 'time' package when model contains array of dates
Created by: masci
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
The Go module generated from a schema property like this:
times:
type: array
items:
type: string
format: date-time
is missing the import time
statement and won't compile.
openapi-generator version
4.1.2
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Sample OpenAPI Specification
version: 0.0.1
servers:
- url: http://localhost:8080/
description: Example API Service
components:
schemas:
'User':
type: object
required:
- display_name
- email
properties:
name:
type: string
readOnly: true
display_name:
type: string
maxLength: 20
minLength: 1
email:
type: string
format: email
times:
type: array
items:
type: string
format: date-time
'ErrorMessage':
type: object
required:
- error_code
- error_message
properties:
error_code:
type: string
error_message:
type: string
paths:
/users/{user_id}:
parameters:
- name: user_id
in: path
description: ID of a user
required: true
schema:
type: string
get:
description: Gets a user
operationId: get_user
responses:
'200':
description: User found
content:
'application/json':
schema:
$ref: '#/components/schemas/User'
'default':
description: Unexpected error
content:
'application/json':
schema:
$ref: '#/components/schemas/ErrorMessage'
Command line used for generation
openapi-generator generate -g go -i api.yaml -o go/
Steps to reproduce
- generate the code with provided command and spec definition
- open the generated module
model_user.go
and notice the missing import
Related issues/PRs
Tentative fix: https://github.com/OpenAPITools/openapi-generator/pull/3973
Suggest a fix
In postProcessModels
function, when checking if the base type for a property is time.Time
it should also check whether it's []time.Time
.