Skip to content

referencing objects does not work with the model #1228

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
x12a1f opened this issue Apr 30, 2015 · 10 comments
Closed

referencing objects does not work with the model #1228

x12a1f opened this issue Apr 30, 2015 · 10 comments

Comments

@x12a1f
Copy link

x12a1f commented Apr 30, 2015

When I add a reference to another object it does not show up in the model. But the weird thing is that when I wrap the reference in an array it works:

selection_108

however it does show up in the model schema:

selection_107

Is this a bug or is there something wrong with my swagger file. I tried master and develop_2.0, they both gave the same result.
A stripped down version of the swagger file is shown below:

{
   "paths" : {
      "/person" : {
         "post" : {
            "parameters" : [
               {
                  "in" : "body",
                  "name" : "body",
                  "schema" : {
                     "$ref" : "Person"
                  }
               }
            ],
            "tags" : [
               "person"
            ],
            "summary" : "Create new person",
            "responses" : {
               "200" : {
                  "schema" : {
                     "$ref" : "Person"
                  },
                  "description" : "Success"
               }
            }
         }
      }
   },
   "swagger" : "2.0",
   "basePath" : "/person",
   "info" : {
      "title" : "Person API",
      "version" : "1",
      "description" : ""
   },
   "tags" : [
      {
         "name" : "person",
         "description" : "Persons"
      }
   ],
   "definitions" : {
      "map1" : {
         "type" : "object",
         "properties" : {
            "anId1" : {
               "title" : "Id",
               "type" : "string"
            }
         },
         "title" : "map1"
      },
      "map2" : {
         "type" : "object",
         "properties" : {
            "anId2" : {
               "title" : "Id",
               "type" : "string"
            }
         },
         "title" : "map2"
      },
       "Person" : {
         "type" : "object",
         "title" : "Information about a person",
         "properties" : {
            "externalId1" : {
               "title" : "first",
               "type" : "object",
               "$ref" : "#/definitions/map1"
            },
            "externalId2" : {
               "title" : "second",
                "type" : "array",
                "items": {
                    "$ref" : "#/definitions/map2"
                }
            }
         }
      }       
   }
}
@webron
Copy link
Contributor

webron commented Apr 30, 2015

@ralphvanetten - by definition you need to use full refs. So "$ref" : "Person" should be "$ref" : "#/definitions/Person"

@ponelat
Copy link
Contributor

ponelat commented Apr 30, 2015

Yes, and you need to wrap your $ref in a schema... like so
@webron, is a $ref allowed to be outside a schema, like this case?

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

Then it'll work as expected (I tested :) )

@x12a1f
Copy link
Author

x12a1f commented Apr 30, 2015

Ah, yes, ofcourse... I knew it had to be some silly mistake..
Thanks!

@x12a1f x12a1f closed this as completed Apr 30, 2015
@ponelat
Copy link
Contributor

ponelat commented Apr 30, 2015

@ralphvanetten ...and by tested I mean with the latest source, so it'll be in a release soon :(
There was a bug with it, at some point. Apologies.

@x12a1f
Copy link
Author

x12a1f commented Apr 30, 2015

@ponelat oh, I guess was a bit optimistic with closing then :)

Anyway, I guess it is fixed in swagger-js? Can you tell which commit and is it documented somewhere how to use your own swagger-js instead of the default one used by swagger-ui?

Thanks.

@x12a1f x12a1f reopened this Apr 30, 2015
@ponelat
Copy link
Contributor

ponelat commented Apr 30, 2015

@ralphvanetten Funny you should ask! We wrote up this a few day(s) ago....
DIY: #1133 (comment)
But first a take a look at
What @mohsen1 suggests (npm link) and what I want to add as a feature...
#1220

@ponelat
Copy link
Contributor

ponelat commented Apr 30, 2015

I made another guide, might be easier to maintain than the DIY version.
#1220 (comment)

@x12a1f
Copy link
Author

x12a1f commented Apr 30, 2015

When I use the develop_2.0 branch of both swagger-ui and swagger-js it is indeed fixed.

Thanks!

@webron
Copy link
Contributor

webron commented Apr 30, 2015

So we can close the issue ;)

@x12a1f
Copy link
Author

x12a1f commented May 7, 2015

Actually. The correct solution is to use:

"externalId1" : {
                    "$ref" : "#/definitions/map1"
            }

As soon as you add anything else like title it does not work. See also swagger-api/swagger-js#402

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

3 participants