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 boolean operators precedence #4158

Merged
merged 1 commit into from
Oct 15, 2019

Conversation

masci
Copy link
Contributor

@masci masci commented Oct 15, 2019

This is a fix for a bug I've introduced with #3973

Due to operator precedence, even if addedTimeImport is true, the if branch is executed and it results in duplicated import time statements in the generated code.

Steps to reproduce

Use this definition (notice User has 2 date-time related fields, joined and times):

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
        joined:
          type: string
          format: date-time
        times:
          type: array
          items:
            type: string
            format: date-time
            #        from_date:
            #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'

With the latest version (4.1.3), run:

openapi-generator generate -g go -i api.yaml -o go/

Notice the wrong import statement in go/model_user.go:

import (
        "time"
        "time"
)

cc: @antihax @bvwells @grokify @kemokemo @bkabrda

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before .
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@auto-labeler
Copy link

auto-labeler bot commented Oct 15, 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.

@wing328 wing328 added this to the 4.2.0 milestone Oct 15, 2019
@wing328 wing328 changed the title fix boolean operators precedence ix boolean operators precedence Oct 15, 2019
@wing328 wing328 changed the title ix boolean operators precedence Fix boolean operators precedence Oct 15, 2019
@wing328
Copy link
Member

wing328 commented Oct 15, 2019

The CI failure has been fixed in the master.

@wing328 wing328 merged commit 756984a into OpenAPITools:master Oct 15, 2019
@wing328
Copy link
Member

wing328 commented Oct 31, 2019

@masci thanks for the PR, which has been included in v4.2.0 release: https://twitter.com/oas_generator/status/1189824932345069569

@masci masci deleted the go-fix-added-time-import branch October 31, 2019 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants