question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A $ref needs to be wrapped inside a schema which is not according to spec.

See original GitHub issue

This is a followup to https://github.com/swagger-api/swagger-ui/issues/1228

I have

 "Person" : {
         "type" : "object",
         "title" : "Information about a person",
         "properties" : {
            "externalId1" : {
               "title" : "first",
               "type" : "object",
               "$ref" : "#/definitions/map1"
            }

which does not work. The answer was to wrap it inside a “schema” and then it works:

"externalId1" : {
               "title" : "first",
               "type" : "object",
               "schema": {  // < -------------- This will make it work like you expect
                    "$ref" : "#/definitions/map1"
                } // ------------------- :)
            },

However, after looking into the spec of both swagger and JSON schema, there is no reference anywhere the “schema” wrapper is required.

As far as I can tell, my version without the “schema” wrapper is correct.

The example here https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#simple-model does not use the “schema” wrapper.

Am I missing something?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
x12a1fcommented, May 4, 2015

Ok, I thought the description is used to describe the field (externalId1 and externalId2 in this case). If the description must be on the referenced object, then you can not have a different description if you have multple references to the same object?

So something like:

"properties" : {
            "externalId1" : {
                "$ref" : "#/definitions/map1",
                "description": "This is the ID for the first thing."
            },
            "externalId3" : {
                "$ref" : "#/definitions/map1",
                "description": "This is the ID for the third thing."
            },

is not correct and not otherwise possible?

3reactions
webroncommented, May 4, 2015

Okay, just wanted to make sure.

This how "Person" should be defined:

{
  "type": "object",
  "title": "Information about a person",
  "properties": {
    "externalId1": {
      "$ref": "#/definitions/map1"
    },
    "externalId2": {
      "title": "second",
      "type": "array",
      "items": {
        "$ref": "#/definitions/map2"
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

openapi - Swagger schema properties ignored when using $ref
A possible workaround is to wrap $ref into allOf - this can be used to "add" attributes to a $ref but not override...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
Schema. In the following description, if a field is not explicitly REQUIRED or described with a MUST or SHALL, it can be considered...
Read more >
Applying Subschemas Conditionally - JSON Schema
The dependentRequired keyword conditionally requires that certain properties must be present if a given property is present in an object. For example, suppose ......
Read more >
XML Schema Part 0: Primer Second Edition - W3C
In such cases, you will need to refer to the XML Schema specification, ... An instance is not actually required to reference a...
Read more >
Language Guide | Protocol Buffers - Google Developers
Repeated fields of numeric types can be serialized in the packed format, which will not be parsed correctly when an optional field is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found