-
Notifications
You must be signed in to change notification settings - Fork 179
fix #810: remove restriction on $ref format #879
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
Open
ctreatma
wants to merge
2
commits into
OpenAPITools:master
Choose a base branch
from
ctreatma:remove-ref-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
core/src/test/java/org/openapitools/openapidiff/core/RemoteRefsDiffTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package org.openapitools.openapidiff.core; | ||
|
|
||
| import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals; | ||
| import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiChangedEndpoints; | ||
| import static org.openapitools.openapidiff.core.TestUtils.assertSpecChangedButCompatible; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class RemoteRefsDiffTest { | ||
|
|
||
| private final String OPENAPI_NESTED_REFS = "remoteRefs/specUsingNestedRefs.yaml"; | ||
| private final String OPENAPI_NO_REFS = "remoteRefs/specUsingNoRefs.yaml"; | ||
| private final String OPENAPI_SIMPLE_REFS = "remoteRefs/specUsingSimpleRefs.yaml"; | ||
| private final String OPENAPI_ELEMENT_REFS = "remoteRefs/specUsingElementRefs.yaml"; | ||
| private final String OPENAPI_MODIFIED_REFS = "remoteRefs/specUsingModifiedRefs.yaml"; | ||
|
|
||
| @Test | ||
| public void testDiffSpecIsSameAsItself() { | ||
| assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_NESTED_REFS); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDiffRefsSameAsInline() { | ||
| assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_NO_REFS); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDiffNestedRefsSameAsSimpleRefs() { | ||
| assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_SIMPLE_REFS); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDiffNestedRefsSameAsElementRefs() { | ||
| assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_ELEMENT_REFS); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDiffShowsChangesWhenRefContentChanges() { | ||
| assertOpenApiChangedEndpoints(OPENAPI_NESTED_REFS, OPENAPI_MODIFIED_REFS); | ||
| assertSpecChangedButCompatible(OPENAPI_NESTED_REFS, OPENAPI_MODIFIED_REFS); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
core/src/test/resources/remoteRefs/reusableSchemas/AllInOne.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Pet: | ||
| allOf: | ||
| - $ref: '#/BasePet' | ||
| - type: object | ||
| required: | ||
| - pet_type | ||
| properties: | ||
| pet_type: | ||
| type: string | ||
| BasePet: | ||
| type: object | ||
| properties: | ||
| pet_color: | ||
| type: string |
4 changes: 4 additions & 0 deletions
4
core/src/test/resources/remoteRefs/reusableSchemas/BasePet.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| type: object | ||
| properties: | ||
| pet_color: | ||
| type: string |
10 changes: 10 additions & 0 deletions
10
core/src/test/resources/remoteRefs/reusableSchemas/PetWithModifiedContent.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| type: object | ||
| required: | ||
| - pet_type | ||
| properties: | ||
| pet_color: | ||
| type: string | ||
| pet_type: | ||
| type: string | ||
| pet_age: | ||
| type: integer |
8 changes: 8 additions & 0 deletions
8
core/src/test/resources/remoteRefs/reusableSchemas/PetWithNestedRef.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| allOf: | ||
| - $ref: './BasePet.yaml' | ||
| - type: object | ||
| required: | ||
| - pet_type | ||
| properties: | ||
| pet_type: | ||
| type: string |
8 changes: 8 additions & 0 deletions
8
core/src/test/resources/remoteRefs/reusableSchemas/PetWithoutNestedRef.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| type: object | ||
| required: | ||
| - pet_type | ||
| properties: | ||
| pet_color: | ||
| type: string | ||
| pet_type: | ||
| type: string |
113 changes: 113 additions & 0 deletions
113
core/src/test/resources/remoteRefs/specUsingElementRefs.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| openapi: 3.0.0 | ||
| servers: | ||
| - url: 'http://petstore.swagger.io/v2' | ||
| info: | ||
| description: >- | ||
| This is a sample server Petstore server. You can find out more about | ||
| Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, | ||
| #swagger](http://swagger.io/irc/). For this sample, you can use the api key | ||
| `special-key` to test the authorization filters. | ||
| version: 1.0.0 | ||
| title: Swagger Petstore | ||
| termsOfService: 'http://swagger.io/terms/' | ||
| contact: | ||
| email: [email protected] | ||
| license: | ||
| name: Apache 2.0 | ||
| url: 'http://www.apache.org/licenses/LICENSE-2.0.html' | ||
| tags: | ||
| - name: pet | ||
| description: Everything about your Pets | ||
| externalDocs: | ||
| description: Find out more | ||
| url: 'http://swagger.io' | ||
| - name: store | ||
| description: Access to Petstore orders | ||
| - name: user | ||
| description: Operations about user | ||
| externalDocs: | ||
| description: Find out more about our store | ||
| url: 'http://swagger.io' | ||
| paths: | ||
| /pet/findByStatus: | ||
| get: | ||
| tags: | ||
| - pet | ||
| summary: Finds Pets by status | ||
| description: Multiple status values can be provided with comma separated strings | ||
| operationId: findPetsByStatus | ||
| parameters: | ||
| - name: status | ||
| in: query | ||
| description: Status values that need to be considered for filter | ||
| required: true | ||
| explode: true | ||
| schema: | ||
| type: array | ||
| items: | ||
| type: string | ||
| enum: | ||
| - available | ||
| - pending | ||
| - sold | ||
| default: available | ||
| responses: | ||
| '200': | ||
| description: successful operation | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| pets: | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/Cat' | ||
| '400': | ||
| description: Invalid status value | ||
| security: | ||
| - petstore_auth: | ||
| - 'write:pets' | ||
| - 'read:pets' | ||
| externalDocs: | ||
| description: Find out more about Swagger | ||
| url: 'http://swagger.io' | ||
| components: | ||
| requestBodies: | ||
| Pet: | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: './reusableSchemas/AllInOne.yaml#/Pet' | ||
| description: Pet object that needs to be added to the store | ||
| required: true | ||
| securitySchemes: | ||
| petstore_auth: | ||
| type: oauth2 | ||
| flows: | ||
| implicit: | ||
| authorizationUrl: 'http://petstore.swagger.io/oauth/dialog' | ||
| scopes: | ||
| 'write:pets': modify pets in your account | ||
| 'read:pets': read your pets | ||
| api_key: | ||
| type: apiKey | ||
| name: api_key | ||
| in: header | ||
| schemas: | ||
| Cat: | ||
| description: Cat class | ||
| allOf: | ||
| - $ref: './reusableSchemas/AllInOne.yaml#/Pet' | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| Dog: | ||
| description: Dog class | ||
| allOf: | ||
| - $ref: './reusableSchemas/AllInOne.yaml#/Pet' | ||
| type: object | ||
| properties: | ||
| bark: | ||
| type: string |
113 changes: 113 additions & 0 deletions
113
core/src/test/resources/remoteRefs/specUsingModifiedRefs.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| openapi: 3.0.0 | ||
| servers: | ||
| - url: 'http://petstore.swagger.io/v2' | ||
| info: | ||
| description: >- | ||
| This is a sample server Petstore server. You can find out more about | ||
| Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, | ||
| #swagger](http://swagger.io/irc/). For this sample, you can use the api key | ||
| `special-key` to test the authorization filters. | ||
| version: 1.0.0 | ||
| title: Swagger Petstore | ||
| termsOfService: 'http://swagger.io/terms/' | ||
| contact: | ||
| email: [email protected] | ||
| license: | ||
| name: Apache 2.0 | ||
| url: 'http://www.apache.org/licenses/LICENSE-2.0.html' | ||
| tags: | ||
| - name: pet | ||
| description: Everything about your Pets | ||
| externalDocs: | ||
| description: Find out more | ||
| url: 'http://swagger.io' | ||
| - name: store | ||
| description: Access to Petstore orders | ||
| - name: user | ||
| description: Operations about user | ||
| externalDocs: | ||
| description: Find out more about our store | ||
| url: 'http://swagger.io' | ||
| paths: | ||
| /pet/findByStatus: | ||
| get: | ||
| tags: | ||
| - pet | ||
| summary: Finds Pets by status | ||
| description: Multiple status values can be provided with comma separated strings | ||
| operationId: findPetsByStatus | ||
| parameters: | ||
| - name: status | ||
| in: query | ||
| description: Status values that need to be considered for filter | ||
| required: true | ||
| explode: true | ||
| schema: | ||
| type: array | ||
| items: | ||
| type: string | ||
| enum: | ||
| - available | ||
| - pending | ||
| - sold | ||
| default: available | ||
| responses: | ||
| '200': | ||
| description: successful operation | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| pets: | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/Cat' | ||
| '400': | ||
| description: Invalid status value | ||
| security: | ||
| - petstore_auth: | ||
| - 'write:pets' | ||
| - 'read:pets' | ||
| externalDocs: | ||
| description: Find out more about Swagger | ||
| url: 'http://swagger.io' | ||
| components: | ||
| requestBodies: | ||
| Pet: | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: './reusableSchemas/PetWithModifiedContent.yaml' | ||
| description: Pet object that needs to be added to the store | ||
| required: true | ||
| securitySchemes: | ||
| petstore_auth: | ||
| type: oauth2 | ||
| flows: | ||
| implicit: | ||
| authorizationUrl: 'http://petstore.swagger.io/oauth/dialog' | ||
| scopes: | ||
| 'write:pets': modify pets in your account | ||
| 'read:pets': read your pets | ||
| api_key: | ||
| type: apiKey | ||
| name: api_key | ||
| in: header | ||
| schemas: | ||
| Cat: | ||
| description: Cat class | ||
| allOf: | ||
| - $ref: './reusableSchemas/PetWithModifiedContent.yaml' | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| Dog: | ||
| description: Dog class | ||
| allOf: | ||
| - $ref: './reusableSchemas/PetWithModifiedContent.yaml' | ||
| type: object | ||
| properties: | ||
| bark: | ||
| type: string |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, looks like just removing this validation would not work well. getRefName method is used by resolveRef method. Under the hood it searches referenced objects only in components section and does not consider remote files. So we need to think here about full support of the remote refs, instead of just removing the validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting; I would have expected an issue like that to be caught by this assertion, since the baseline spec uses an external ref to define the common properties of the
Catschema and the updated spec defines those properties inline.Is there a different test I could write that would exercise remote ref resolution? Once I have a failing test demonstrating the issue I can work on addressing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a few more tests to cover different styles of external
$refand based on the test results, it looks like external references are all being resolved correctly for the purposes of generating a diff. (Although I haven't added a test for external URL references.) Most of the tests added here are checking for an empty diff, but I did add one test to confirm that changes in the content of a remote$refare detected as a diff.