Skip to content

Commit 5025731

Browse files
committed
remove restriction on $ref format
1 parent ca2c426 commit 5025731

File tree

6 files changed

+275
-1
lines changed

6 files changed

+275
-1
lines changed

core/src/main/java/org/openapitools/openapidiff/core/utils/RefPointer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public String getRefName(String ref) {
5757

5858
final String baseRef = getBaseRefForType(refType.getName());
5959
if (!ref.startsWith(baseRef)) {
60-
throw new IllegalArgumentException("Invalid ref: " + ref);
60+
// If the ref doesn't point to something in #/components,
61+
// we return it as-is. This avoids making an assumption
62+
// that we can simplify refs without collisions.
63+
return ref;
6164
}
6265
return ref.substring(baseRef.length());
6366
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.openapitools.openapidiff.core;
2+
3+
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class RemoteRefsDiffTest {
8+
9+
private final String OPENAPI_DOC1 = "remoteRefs/diff_1.yaml";
10+
private final String OPENAPI_DOC2 = "remoteRefs/diff_2.yaml";
11+
12+
@Test
13+
public void testDiffSame() {
14+
assertOpenApiAreEquals(OPENAPI_DOC1, OPENAPI_DOC1);
15+
}
16+
17+
@Test
18+
public void testDiffSameWithAllOf() {
19+
assertOpenApiAreEquals(OPENAPI_DOC1, OPENAPI_DOC2);
20+
}
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type: object
2+
properties:
3+
pet_color:
4+
type: string
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
allOf:
2+
- $ref: './BasePet.yaml'
3+
- type: object
4+
required:
5+
- pet_type
6+
properties:
7+
pet_type:
8+
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: '#/components/schemas/Pet'
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: './components/Pet.yaml'
102+
type: object
103+
properties:
104+
name:
105+
type: string
106+
Dog:
107+
description: Dog class
108+
allOf:
109+
- $ref: './components/Pet.yaml'
110+
type: object
111+
properties:
112+
bark:
113+
type: string
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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: '#/components/schemas/Pet'
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+
Pet:
99+
type: object
100+
required:
101+
- pet_type
102+
properties:
103+
pet_type:
104+
nullable: false
105+
type: string
106+
Cat:
107+
description: Cat class
108+
type: object
109+
required:
110+
- pet_type
111+
properties:
112+
pet_type:
113+
type: string
114+
name:
115+
type: string
116+
pet_color:
117+
type: string
118+
Dog:
119+
description: Dog class
120+
allOf:
121+
- $ref: './components/Pet.yaml'
122+
type: object
123+
properties:
124+
bark:
125+
type: string

0 commit comments

Comments
 (0)