Skip to content

$ref in additionalProperties in external yaml ignored #342

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

Closed
rakus opened this issue Nov 5, 2016 · 9 comments
Closed

$ref in additionalProperties in external yaml ignored #342

rakus opened this issue Nov 5, 2016 · 9 comments
Assignees

Comments

@rakus
Copy link

rakus commented Nov 5, 2016

Initially opened against swagger codegen as #4135. They send me here.

It seems that swagger-parser cannot handle a $ref below additionalProperties in a external yaml file.

Example:


swagger.yaml

swagger: "2.0"
info:
  title: Test API
  version: 1.0.0
host: swagger.io
basePath: /show-bug
schemes:
- http
produces:
- application/json
consumes:
- application/json

paths:
  /tests:
    get:
      operationId: listTests
      responses:
        200:
          description: Returns results.
          schema:
              $ref: "./globals.yaml#/definitions/result"

globals.yaml

definitions:
  link-object:
    type: object
    additionalProperties:
      $ref: '#/definitions/rel-data'

  rel-data:
    type: object
    required:
      - href
    properties:
      href:
        type: string
      note:
        type: string

  result:
    type: object
    properties: 
      name:
        type: string
      _links:
        $ref: "#/definitions/link-object"

After parsing the object rel-data (globals.yaml#/definitions/rel-data) is missing.
The verbose output of swagger-codegen shows it:

{
  "swagger" : "2.0",
  "info" : {
    "version" : "1.0.0",
    "title" : "Test API"
  },
  "host" : "swagger.io",
  "basePath" : "/show-bug",
  "schemes" : [ "http" ],
  "consumes" : [ "application/json" ],
  "produces" : [ "application/json" ],
  "paths" : {
    "/tests" : {
      "get" : {
        "operationId" : "listTests",
        "parameters" : [ ],
        "responses" : {
          "200" : {
            "description" : "Returns results.",
            "schema" : {
              "$ref" : "#/definitions/result"
            }
          }
        }
      }
    }
  },
  "definitions" : {
    "result" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "_links" : {
          "$ref" : "#/definitions/link-object"
        }
      }
    },
    "link-object" : {
      "type" : "object",
      "additionalProperties" : {
        "$ref" : "#/definitions/rel-data"
      }
    }
  }
}
@fehguy
Copy link
Contributor

fehguy commented Dec 27, 2016

This is not implemented

@jimschubert
Copy link

@fehguy When you say it's not implemented, is it that this is currently not implemented in YAML? IT looks like there are tests to cover this in JSON processing.

I ask because there's a related issue reported to swagger-codegen (swagger-api/swagger-codegen#5753).

@fehguy
Copy link
Contributor

fehguy commented Jun 1, 2017

hmm. As of december last year it wasn't implemented, and it shouldn't matter if it's JSON or YAML for how the parser works. Where are the tests that you've seen?

@jimschubert
Copy link

@fehguy it looked like tests hitting this file should have covered it. Specifically testLoadRelativeFileTree_Json and testLoadRelativeFileTree_Yaml look like they'd cover JSON and YAML of this scenario, although I can't seem to find the yaml file referenced in that last test. Maybe the test is parsing JSON and passing? I didn't dig much deeper than that.

@fehguy
Copy link
Contributor

fehguy commented Jun 3, 2017

thanks @jimschubert I'll get into this one shortly

@slarti-b
Copy link

We just ran up against this. Any news or updates? I also left a more detailed question on the linked codegen ticket - don't think that impacts here, but it may.

@webron
Copy link
Contributor

webron commented Dec 12, 2017

Ugh, sorry, this got lost. We'll try to have a look at it soon.

@gracekarina
Copy link
Contributor

Hi, Please check in branch 2.0, we merged a PR solving the issue. @slarti-b @jimschubert @rakus

@gracekarina
Copy link
Contributor

Closing Issue, please report again if this keeps presenting

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

No branches or pull requests

6 participants