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

[BUG] Missing import of 'time' package when model contains array of dates #3972

Closed
3 of 6 tasks
masci opened this issue Sep 27, 2019 · 1 comment · Fixed by #3973
Closed
3 of 6 tasks

[BUG] Missing import of 'time' package when model contains array of dates #3972

masci opened this issue Sep 27, 2019 · 1 comment · Fixed by #3973

Comments

@masci
Copy link
Contributor

masci commented Sep 27, 2019

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: #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.

@auto-labeler
Copy link

auto-labeler bot commented Sep 27, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant