Skip to content

Commit 8e387ad

Browse files
committed
add more extensive tests of behavior with external $refs
1 parent c4e1108 commit 8e387ad

File tree

11 files changed

+407
-11
lines changed

11 files changed

+407
-11
lines changed
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
package org.openapitools.openapidiff.core;
22

33
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;
4+
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiChangedEndpoints;
5+
import static org.openapitools.openapidiff.core.TestUtils.assertSpecChangedButCompatible;
46

57
import org.junit.jupiter.api.Test;
68

79
public class RemoteRefsDiffTest {
810

9-
private final String OPENAPI_DOC1 = "remoteRefs/diff_1.yaml";
10-
private final String OPENAPI_DOC2 = "remoteRefs/diff_2.yaml";
11+
private final String OPENAPI_NESTED_REFS = "remoteRefs/specUsingNestedRefs.yaml";
12+
private final String OPENAPI_NO_REFS = "remoteRefs/specUsingNoRefs.yaml";
13+
private final String OPENAPI_SIMPLE_REFS = "remoteRefs/specUsingSimpleRefs.yaml";
14+
private final String OPENAPI_ELEMENT_REFS = "remoteRefs/specUsingElementRefs.yaml";
15+
private final String OPENAPI_MODIFIED_REFS = "remoteRefs/specUsingModifiedRefs.yaml";
1116

1217
@Test
13-
public void testDiffSame() {
14-
assertOpenApiAreEquals(OPENAPI_DOC1, OPENAPI_DOC1);
18+
public void testDiffSpecIsSameAsItself() {
19+
assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_NESTED_REFS);
1520
}
1621

1722
@Test
18-
public void testDiffSameWithAllOf() {
19-
assertOpenApiAreEquals(OPENAPI_DOC1, OPENAPI_DOC2);
23+
public void testDiffRefsSameAsInline() {
24+
assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_NO_REFS);
25+
}
26+
27+
@Test
28+
public void testDiffNestedRefsSameAsSimpleRefs() {
29+
assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_SIMPLE_REFS);
30+
}
31+
32+
@Test
33+
public void testDiffNestedRefsSameAsElementRefs() {
34+
assertOpenApiAreEquals(OPENAPI_NESTED_REFS, OPENAPI_ELEMENT_REFS);
35+
}
36+
37+
@Test
38+
public void testDiffShowsChangesWhenRefContentChanges() {
39+
assertOpenApiChangedEndpoints(OPENAPI_NESTED_REFS, OPENAPI_MODIFIED_REFS);
40+
assertSpecChangedButCompatible(OPENAPI_NESTED_REFS, OPENAPI_MODIFIED_REFS);
2041
}
2142
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Pet:
2+
allOf:
3+
- $ref: '#/BasePet'
4+
- type: object
5+
required:
6+
- pet_type
7+
properties:
8+
pet_type:
9+
type: string
10+
BasePet:
11+
type: object
12+
properties:
13+
pet_color:
14+
type: string

core/src/test/resources/remoteRefs/components/BasePet.yaml renamed to core/src/test/resources/remoteRefs/reusableSchemas/BasePet.yaml

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type: object
2+
required:
3+
- pet_type
4+
properties:
5+
pet_color:
6+
type: string
7+
pet_type:
8+
type: string
9+
pet_age:
10+
type: integer

core/src/test/resources/remoteRefs/components/Pet.yaml renamed to core/src/test/resources/remoteRefs/reusableSchemas/PetWithNestedRef.yaml

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type: object
2+
required:
3+
- pet_type
4+
properties:
5+
pet_color:
6+
type: string
7+
pet_type:
8+
type: string

core/src/test/resources/remoteRefs/diff_1.yaml renamed to core/src/test/resources/remoteRefs/specUsingElementRefs.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ components:
7878
content:
7979
application/json:
8080
schema:
81-
$ref: '#/components/schemas/Pet'
81+
$ref: './reusableSchemas/AllInOne.yaml#/Pet'
8282
description: Pet object that needs to be added to the store
8383
required: true
8484
securitySchemes:
@@ -98,15 +98,15 @@ components:
9898
Cat:
9999
description: Cat class
100100
allOf:
101-
- $ref: './components/Pet.yaml'
101+
- $ref: './reusableSchemas/AllInOne.yaml#/Pet'
102102
type: object
103103
properties:
104104
name:
105105
type: string
106106
Dog:
107107
description: Dog class
108108
allOf:
109-
- $ref: './components/Pet.yaml'
109+
- $ref: './reusableSchemas/AllInOne.yaml#/Pet'
110110
type: object
111111
properties:
112112
bark:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: >-
6+
This is a sample server Petstore server. You can find out more about
7+
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
8+
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
9+
`special-key` to test the authorization filters.
10+
version: 1.0.0
11+
title: Swagger Petstore
12+
termsOfService: 'http://swagger.io/terms/'
13+
contact:
14+
email: apiteam@swagger.io
15+
license:
16+
name: Apache 2.0
17+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
18+
tags:
19+
- name: pet
20+
description: Everything about your Pets
21+
externalDocs:
22+
description: Find out more
23+
url: 'http://swagger.io'
24+
- name: store
25+
description: Access to Petstore orders
26+
- name: user
27+
description: Operations about user
28+
externalDocs:
29+
description: Find out more about our store
30+
url: 'http://swagger.io'
31+
paths:
32+
/pet/findByStatus:
33+
get:
34+
tags:
35+
- pet
36+
summary: Finds Pets by status
37+
description: Multiple status values can be provided with comma separated strings
38+
operationId: findPetsByStatus
39+
parameters:
40+
- name: status
41+
in: query
42+
description: Status values that need to be considered for filter
43+
required: true
44+
explode: true
45+
schema:
46+
type: array
47+
items:
48+
type: string
49+
enum:
50+
- available
51+
- pending
52+
- sold
53+
default: available
54+
responses:
55+
'200':
56+
description: successful operation
57+
content:
58+
application/json:
59+
schema:
60+
type: object
61+
properties:
62+
pets:
63+
type: array
64+
items:
65+
$ref: '#/components/schemas/Cat'
66+
'400':
67+
description: Invalid status value
68+
security:
69+
- petstore_auth:
70+
- 'write:pets'
71+
- 'read:pets'
72+
externalDocs:
73+
description: Find out more about Swagger
74+
url: 'http://swagger.io'
75+
components:
76+
requestBodies:
77+
Pet:
78+
content:
79+
application/json:
80+
schema:
81+
$ref: './reusableSchemas/PetWithModifiedContent.yaml'
82+
description: Pet object that needs to be added to the store
83+
required: true
84+
securitySchemes:
85+
petstore_auth:
86+
type: oauth2
87+
flows:
88+
implicit:
89+
authorizationUrl: 'http://petstore.swagger.io/oauth/dialog'
90+
scopes:
91+
'write:pets': modify pets in your account
92+
'read:pets': read your pets
93+
api_key:
94+
type: apiKey
95+
name: api_key
96+
in: header
97+
schemas:
98+
Cat:
99+
description: Cat class
100+
allOf:
101+
- $ref: './reusableSchemas/PetWithModifiedContent.yaml'
102+
type: object
103+
properties:
104+
name:
105+
type: string
106+
Dog:
107+
description: Dog class
108+
allOf:
109+
- $ref: './reusableSchemas/PetWithModifiedContent.yaml'
110+
type: object
111+
properties:
112+
bark:
113+
type: string
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: >-
6+
This is a sample server Petstore server. You can find out more about
7+
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
8+
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
9+
`special-key` to test the authorization filters.
10+
version: 1.0.0
11+
title: Swagger Petstore
12+
termsOfService: 'http://swagger.io/terms/'
13+
contact:
14+
email: apiteam@swagger.io
15+
license:
16+
name: Apache 2.0
17+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
18+
tags:
19+
- name: pet
20+
description: Everything about your Pets
21+
externalDocs:
22+
description: Find out more
23+
url: 'http://swagger.io'
24+
- name: store
25+
description: Access to Petstore orders
26+
- name: user
27+
description: Operations about user
28+
externalDocs:
29+
description: Find out more about our store
30+
url: 'http://swagger.io'
31+
paths:
32+
/pet/findByStatus:
33+
get:
34+
tags:
35+
- pet
36+
summary: Finds Pets by status
37+
description: Multiple status values can be provided with comma separated strings
38+
operationId: findPetsByStatus
39+
parameters:
40+
- name: status
41+
in: query
42+
description: Status values that need to be considered for filter
43+
required: true
44+
explode: true
45+
schema:
46+
type: array
47+
items:
48+
type: string
49+
enum:
50+
- available
51+
- pending
52+
- sold
53+
default: available
54+
responses:
55+
'200':
56+
description: successful operation
57+
content:
58+
application/json:
59+
schema:
60+
type: object
61+
properties:
62+
pets:
63+
type: array
64+
items:
65+
$ref: '#/components/schemas/Cat'
66+
'400':
67+
description: Invalid status value
68+
security:
69+
- petstore_auth:
70+
- 'write:pets'
71+
- 'read:pets'
72+
externalDocs:
73+
description: Find out more about Swagger
74+
url: 'http://swagger.io'
75+
components:
76+
requestBodies:
77+
Pet:
78+
content:
79+
application/json:
80+
schema:
81+
$ref: './reusableSchemas/PetWithNestedRef.yaml'
82+
description: Pet object that needs to be added to the store
83+
required: true
84+
securitySchemes:
85+
petstore_auth:
86+
type: oauth2
87+
flows:
88+
implicit:
89+
authorizationUrl: 'http://petstore.swagger.io/oauth/dialog'
90+
scopes:
91+
'write:pets': modify pets in your account
92+
'read:pets': read your pets
93+
api_key:
94+
type: apiKey
95+
name: api_key
96+
in: header
97+
schemas:
98+
Cat:
99+
description: Cat class
100+
allOf:
101+
- $ref: './reusableSchemas/PetWithNestedRef.yaml'
102+
type: object
103+
properties:
104+
name:
105+
type: string
106+
Dog:
107+
description: Dog class
108+
allOf:
109+
- $ref: './reusableSchemas/PetWithNestedRef.yaml'
110+
type: object
111+
properties:
112+
bark:
113+
type: string

core/src/test/resources/remoteRefs/diff_2.yaml renamed to core/src/test/resources/remoteRefs/specUsingNoRefs.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ components:
117117
type: string
118118
Dog:
119119
description: Dog class
120-
allOf:
121-
- $ref: './components/Pet.yaml'
122120
type: object
121+
required:
122+
- pet_type
123123
properties:
124+
pet_color:
125+
type: string
126+
pet_type:
127+
type: string
124128
bark:
125129
type: string

0 commit comments

Comments
 (0)