Skip to content
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

added check to avoid removing referenced models #278 #333

Merged
merged 1 commit into from
Oct 28, 2016
Merged

Conversation

fehguy
Copy link
Contributor

@fehguy fehguy commented Oct 27, 2016

Fixes #278

@diegode this is to fix the issue in #278 but...

I don't necessarily agree with the expectations in a couple tests. Once I fixed this bug some other test failures appeared.

For example, when we have this:

definitions:
  x:
    properties:
      foo:
        $ref: '#/definitions/y'
  y:
    $ref: '#/definitions/z'
  z:
    type: object

That the parser should change the definitions to this:

definitions:
  x:
    properties:
      foo:
        $ref: '#/definitions/z'
  z:
    type: object

Because a model is referencing y in this example as a property, there may be intent and value in retaining that name. So even though y absorbs all the properties of z, the name y may be useful.

So this PR changes the behavior of a couple tests that were previously behaving differently. Since you put them there, I thought it was only considerate to get your feedback before any merge :)

Map<String, Model> definitions = swagger.getDefinitions();
assertTrue(definitions.containsKey("x"));
assertTrue(!definitions.containsKey("y"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that y lives on, even though it is directly referencing all aspects of z

assertTrue(!definitions.containsKey("y"));
assertEquals(((RefProperty) ((ArrayProperty) definitions.get("x").getProperties().get("children")).getItems()).get$ref(), "#/definitions/x");
assertTrue(definitions.containsKey("y"));
assertEquals(((RefProperty) ((ArrayProperty) definitions.get("x").getProperties().get("children")).getItems()).get$ref(), "#/definitions/y");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing the reference to x, I'm leaving it as modeled as y

@fehguy
Copy link
Contributor Author

fehguy commented Oct 28, 2016

OK I've reviewed the behavior with a few others and this PR and test changes seem correct. We don't want this:

definitions:
  Address:
    type: object
    # properties:...
  AlternateAddress:
    $ref: '#/definitions/Address'

to remove the Address definition and change references to AlternateAddress. @diegode please open a new issue if you disagree.

@fehguy fehguy merged commit 9c93464 into master Oct 28, 2016
@fehguy fehguy deleted the issue-278 branch October 28, 2016 18:52
@fehguy fehguy modified the milestone: v1.0.23 Oct 28, 2016
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

Successfully merging this pull request may close these issues.

External recursive refs aren't being resolved
1 participant