Skip to content
GitLab
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
  • Issues
  • #3972
Closed
Open
Issue created Sep 27, 2019 by Administrator@rootContributor3 of 6 checklist items completed3/6 checklist items

[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
  1. generate the code with provided command and spec definition
  2. 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.

Assignee
Assign to
Time tracking