Skip to content

Schema $ref of $ref not working #160

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
mpoiriert opened this issue Nov 22, 2014 · 8 comments
Closed

Schema $ref of $ref not working #160

mpoiriert opened this issue Nov 22, 2014 · 8 comments
Milestone

Comments

@mpoiriert
Copy link
Contributor

This is seem to be a valid schema but it's not loaded properly:

{
  "definitions": {
    "Response": {
      "$ref": "User"
    },
    "User": {
      "properties": {
        "username": {
          "type": "string"
        }
      }
    }
}

I would expect the Reponse definition to "import" the User definition but it doesn't. This can easily be seen with the getMockSignature of a model since it does get the reference from properties but not from himself.

@webron
Copy link
Contributor

webron commented Nov 22, 2014

Technically, that's not a valid $ref definition, it really should be #/definitions/User. There's a related discussion in swagger-spec - OAI/OpenAPI-Specification#135.

@mpoiriert
Copy link
Contributor Author

Sorry this is not the concern of the bug here is the updated schema:

{
  "definitions": {
    "Response": {
      "$ref": "#/definitions/User"
    },
    "User": {
      "properties": {
        "username": {
          "type": "string"
        }
      }
    }
}

This is not working.

I did do a fix for another concern (#162) but this doesn't fix this case since it's not the root problem of this.

@webron
Copy link
Contributor

webron commented Nov 22, 2014

Fair enough, thank you for the contributions! 👍

@fehguy
Copy link
Contributor

fehguy commented Dec 4, 2014

the issue above should be resolved with #162. Please reopen if not.

@fehguy fehguy closed this as completed Dec 4, 2014
@mpoiriert
Copy link
Contributor Author

This is not related.

The problem is in the SwaggerClient.prototype.buildFromSpec and the Model class.

In the buildFromSpec arround line 121

  for(key in this.definitions) {
    var model = new Model(key, this.definitions[key]);
    if(model) {
      models[key] = model;
    }
  }

A new Model class is instanciate but none of the code in the for and the Model contructor take in consideration that a definition could be a reference on another definition...

@fehguy fehguy reopened this Dec 4, 2014
@fehguy fehguy modified the milestone: 2.1-M1 Dec 24, 2014
@fehguy
Copy link
Contributor

fehguy commented Dec 24, 2014

This can be handled by #152

@fehguy fehguy modified the milestones: v2.1-M2, v2.1-M1 Jan 28, 2015
@whitlockjc
Copy link
Contributor

If all you need is the reference dereferencing, you could use json-refs. If you want to construct an object model from a Swagger document, I don't think #152 will help.

@whitlockjc
Copy link
Contributor

This has been resolved.

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

4 participants