swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
774 stars 526 forks source link

Swagger 2 parser parses $ref to "#/paths/" as "#/definitions/" #1995

Open garydgregory opened 8 months ago

garydgregory commented 8 months ago

In the schema below from https://github.com/APIs-guru/openapi-directory/blob/main/APIs/powerdns.local/0.0.13/swagger.yaml:

swagger: "2.0"
schemes:
  - http
  - https
host: sedra.bethmardutho.org
basePath: /api
info:
  contact:
    email: sedra@bethmardutho.org
  description: |-
    The SEDRA API is documented in **OpenAPI format** and uses [ReDoc](https://github.com/Rebilly/ReDoc) for documentation.
    # Introduction
    This document describes the JSON API for the Syriac Electronic Data Research Archive (SEDRA). The SEDRA project is a linguistic and literary database of Syriac language and literature focusing on providing electronic access to the corpus of Syriac lexicons with linguistic information added to each entry in those lexicons. The API is a mechanism to provide the linguistic information stored in SEDRA to a broader audience.
    Additionally there is a XML API for Syriac words which conforms to a prototype Semitic Languages schema which can be found in the XSD file https://sedra.bethmardutho.org/api/semiticLanguages.xsd.
    # Cross-Origin Resource Sharing
    This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with the [W3C spec](https://www.w3.org/TR/cors/) and allows cross-domain communication from the browser.
    All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site.
    # Samples
    Explaining how to lookup words in the SEDRA API is complex and would clutter the API description. For that reason we have chosen to give the explanation of how to lookup words in its own section. SEDRA can lookup words by the SEDRA word Id. However, it will often be the case that the consumer of information provided by the SEDRA API does not know the SEDRA word Id. It is for that reason that the SEDRA API provides a method to lookup words by the Syriac text. But that process is complicated by the nature of Syriac writing. So the SEDRA API will lookup words for consonantal, partially vocalized, and fully vocalized Syriac text. Using the word Id will provide the most accurate results as the exact word will be returned. Fully vocalized text will provide the next most accurate result. The least accurate results will be returned by partially vocalized and consonantal Syriac words in that order. Following are some samples to help understand how this works.
    1. By Word Id [30862](https://sedra.bethmardutho.org/api/word/30862.json)
    2. By fully vocalized Syriac word [ܐܰܒܳܪܳܐ](https://sedra.bethmardutho.org/api/word/ܐܰܒܳܪܳܐ.json)
    3. By partially vocalized Syriac word [ܐܶܒܪܐ](https://sedra.bethmardutho.org/api/word/ܐܶܒܪܐ.json)
    4. By consonantal Syriac word [ܐܒܪܐ](https://sedra.bethmardutho.org/api/word/ܐܒܪܐ.json).
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  title: SEDRA IV API
  version: 1.0.0
  x-logo:
    url: https://bethmardutho.org/wp-content/uploads/2018/04/cropped-BMlogo-6-180x180.jpg
  x-origin:
    - format: swagger
      url: https://sedra.bethmardutho.org/api/openapi
      version: "2.0"
  x-providerName: bethmardutho.org
externalDocs:
  description: Find out how to create a Github repo for your OpenAPI spec.
  url: https://github.com/Rebilly/generator-openapi-repo
consumes:
  - application/json
produces:
  - application/json
tags:
  - name: API
paths:
  "/lexeme/{id}":
    get:
      description: Returns linguistic information for a Syriac lexeme.
      parameters:
        - description: The Id of a lexeme from the Sedra database.
          in: path
          name: id
          required: true
          type: string
      responses:
        "200":
          description: A Syriac lexeme.
          schema:
            properties:
              categoryType:
                description: The category of the Syriac lexeme or word.
                enum:
                  - adjective
                  - adjective of place
                  - adverb
                  - adverb ending with aiyt
                  - denominative
                  - idiom
                  - noun
                  - numeral
                  - participle adjective
                  - particle
                  - pronoun
                  - proper noun
                  - substantive
                  - verb
                  - proper noun (individual's name; e.g. Ephrem)
                  - proper noun (place name)
                  - proper noun (nations; e.g. Huns)
                  - demonym
                  - preposition
                  - interjection
                type: string
              etymologies:
                $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/glosses"
              glosses:
                $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/glosses"
              kaylo:
                $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/kaylo"
              lexeme:
                $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/word"
              root:
                $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/word"
              syriac:
                description: Consonantal form of this Syriac lexeme.
                type: string
              words:
                items:
                  $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/word"
                type: array
            required:
              - lexeme
              - syriac
            type: object
      summary: Get Syriac lexeme.
      tags:
        - API
  "/word/{id}":
    get:
      description: Returns an array of linguistic information for every word that matches the Syriac word. Adjustment is made if the Syriac word is consonantal, partially, or fully vocalized.
      parameters:
        - description: The id parameters must contain either the Id of a word from the Sedra database or a Syriac word in the unicode character set. When the id parameter is a Syriac word it may be consonantal, partially vocalized, or fully vocalized. Fully vocalized Syriac words will have less false positive results than partially vocalized or consonantal Syriac words. When id is the Id of a word from the SEDRA database then that word will be the only word in the result.
          in: path
          name: id
          required: true
          type: string
      responses:
        "200":
          description: An array of Syriac words.
          schema:
            items:
              properties:
                eastern:
                  description: Eastern vocalized form of this Syriac word.
                  type: string
                gender:
                  description: The gender of a Syriac adjective, noun, numeral, pronoun, suffix, or verb.
                  enum:
                    - common
                    - feminine
                    - masculine
                  type: string
                glosses:
                  additionalProperties:
                    items:
                      type: string
                    type: array
                  description: A hashmap with language name as a key and and array of text strings in that language
                  type: object
                hasSeyame:
                  description: Indicator to the presence of a Seyame in this word.
                  type: boolean
                isEnclitic:
                  description: Indicator if this Syriac word is an enclitic.
                  type: boolean
                isLexicalForm:
                  description: Indicator if this Syriac word is the lexeme form.
                  type: boolean
                isTheoretical:
                  description: Indicator if this Syriac word is theoretical or it is attested.
                  type: boolean
                kaylo:
                  description: The Kaylo or conjugation of a Syriac verb.
                  enum:
                    - ettaphʿal (pass. of Taphʿel)
                    - IVa
                    - IVp
                    - pʿal
                    - paʿʿel
                    - shaphʿel
                    - palpel
                    - ethpaʿʿal
                    - aphʿel
                    - ettaphʿal
                    - saphʿel
                    - ethpʿel
                    - p
                    - ethp
                    - ethpalpal
                    - payʿel
                    - ethpayʿal
                    - ethparʿal
                    - eshtaphʿal
                    - ethpawʿal
                    - pawʿel
                    - palpal
                    - pamʿel
                    - taphʿel
                    - parʿel
                    - estaphʿal
                    - ethpaʿli
                    - paʿli
                  type: string
                lexeme:
                  $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/word"
                number:
                  description: The number of a Syriac adjective, noun, suffix, or verb.
                  enum:
                    - plural
                    - singular
                  type: string
                person:
                  description: The person of a Syriac verb.
                  enum:
                    - first
                    - second
                    - third
                  type: string
                state:
                  description: The state of a Syriac substantive or adjective.
                  enum:
                    - absolute
                    - emphatic
                    - construct
                  type: string
                suffixGender:
                  $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/gender"
                suffixNumber:
                  $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/number"
                suffixPerson:
                  $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/person"
                suffixType:
                  description: The type of suffix attached to the Syriac word.
                  enum:
                    - contraction
                    - suffix
                  type: string
                syriac:
                  description: Consonantal form of this Syriac word.
                  type: string
                tense:
                  description: The tense of a Syriac verb.
                  enum:
                    - active participle
                    - imperative
                    - imperfect
                    - infinitive
                    - participle
                    - passive participle
                    - perfect
                  type: string
                western:
                  description: Western vocalized form of this Syriac word.
                  type: string
                word:
                  description: ""
                  properties:
                    id:
                      description: The SEDRA 'Id' used for referencing this object.
                      type: integer
                    uri:
                      description: Full URI of the SEDRA API reference for this object.
                      type: string
                  required:
                    - id
                    - uri
                  type: object
              required:
                - word
                - lexeme
                - syriac
              type: object
            type: array
      summary: Get Syriac word.
      tags:
        - API
x-tagGroups:
  - name: ""
    tags:
      - API

The property:

etymologies:
                $ref: "#/paths/~1word~1%7Bid%7D/get/responses/200/schema/items/properties/glosses"

is parsed as a io.swagger.models.refs.RefType.DEFINITION instead of a io.swagger.models.refs.RefType.PATH.

See this Eclipse debugger screenshot

image

This messes up our processing since in this case io.swagger.models.Swagger.getDefinitions() returns null despite the RefFormat in the RefProperty being INTERNAL. I have to assume that INTERNAL can mean anything within the Swagger object and not just a definition it seems. Is that correct?