OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.29k stars 6.44k forks source link

[BUG] swagger parser failed to resolve complex external references #6019

Open yilinjuang opened 4 years ago

yilinjuang commented 4 years ago

Bug Report Checklist

Description
openapi-generator version

4.3.1 from latest master

OpenAPI declaration file content or url

test.yaml

openapi: 3.0.2
info:
  title: Test
  version: 0.1.0
servers:
  - url: http://localhost
paths:
  /tags:
    $ref: "paths/tag.yaml#/~1tags"

paths/tag.yaml

/tags:
  get:
    summary: get tags
    operationId: GetTags
    parameters:
      - name: type
        in: query
        description: type of tag
        schema:
          $ref: "../components/misc.yaml#/TagType"
        required: true
    responses:
      200:
        description: successful operation
        content:
          application/json:
            schema:
              $ref: "../components/misc.yaml#/Tag"

components/misc.yaml

Tag:
  type: object
  properties:
    test:
      $ref: "#/TagType"
TagType:
  type: string
  enum:
    - school
Command line used for generation

default option. any language. An example is

openapi-generator generate -g aspnetcore -i ./test.yaml
Steps to reproduce

generate throws warning

[main] WARN  i.s.v.p.p.ExternalRefProcessor - A model for class StringSchema {
    class Schema {
        type: string
        format: null
        $ref: null
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }
} already exists
Related issues/PRs

Might be related to https://github.com/OpenAPITools/openapi-generator/pull/5413

Suggest a fix

Want to first make sure it's not other bugs causing this. Then I'll file an issue to swagger parser. In the meantime, maybe we want to downgrade parser to 2.0.17?

auto-labeler[bot] commented 4 years ago

👍 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.

haikusw commented 4 years ago

We are running into similar issues.

I have reproduced the bug above using the data files indicated for the swift5 language generation for:

openapi-generator-cli 4.3.1 commit : 003165c built : 2020-05-06T09:38:39Z source : https://github.com/openapitools/openapi-generator docs : https://openapi-generator.tech/

on macOS 10.15.4

openapi-generator generate -g swift5 -i ~/Desktop/testbug/test.yaml -o ~/Desktop/testbug/OUTPUT/

In some more complex cases we are also getting to versions of a model file, "ModelName.swift" and "ModelName2.swift" and references to each in the code which is a serious problem because the code is wrong.