Skip to content

Commit 6b5dbb4

Browse files
authored
Add tests for content-type changes in request/response (#190)
1 parent 0856ad6 commit 6b5dbb4

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

core/src/test/java/org/openapitools/openapidiff/core/ContentDiffTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,36 @@ public void testSameContentDiff() {
2727
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC2, OPENAPI_DOC2);
2828
assertThat(changedOpenApi.isUnchanged()).isTrue();
2929
}
30+
31+
@Test
32+
public void testAddedResponseContentTypeDiff() {
33+
ChangedOpenApi changedOpenApi =
34+
OpenApiCompare.fromLocations(
35+
"content_type_response_add_1.yaml", "content_type_response_add_2.yaml");
36+
assertThat(changedOpenApi.isCompatible()).isFalse();
37+
}
38+
39+
@Test
40+
public void testRemovedResponseContentTypeDiff() {
41+
ChangedOpenApi changedOpenApi =
42+
OpenApiCompare.fromLocations(
43+
"content_type_response_add_2.yaml", "content_type_response_add_1.yaml");
44+
assertThat(changedOpenApi.isCompatible()).isTrue();
45+
}
46+
47+
@Test
48+
public void testAddedRequestContentTypeDiff() {
49+
ChangedOpenApi changedOpenApi =
50+
OpenApiCompare.fromLocations(
51+
"content_type_request_add_1.yaml", "content_type_request_add_2.yaml");
52+
assertThat(changedOpenApi.isCompatible()).isTrue();
53+
}
54+
55+
@Test
56+
public void testRemovedRequestContentTypeDiff() {
57+
ChangedOpenApi changedOpenApi =
58+
OpenApiCompare.fromLocations(
59+
"content_type_request_add_2.yaml", "content_type_request_add_1.yaml");
60+
assertThat(changedOpenApi.isCompatible()).isFalse();
61+
}
3062
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
openapi: "3.0.1"
3+
info:
4+
title: "Test title"
5+
description: "This is a test metadata"
6+
termsOfService: "http://test.com"
7+
contact:
8+
name: "Mark Snijder"
9+
url: "marksnijder.nl"
10+
11+
license:
12+
name: "To be decided"
13+
url: "http://test.com"
14+
version: "version 1.0"
15+
paths:
16+
/pets/{id}:
17+
get:
18+
description: Returns a user based on a single ID, if the user does not have access to the pet
19+
operationId: find pet by id
20+
requestBody:
21+
content:
22+
application/json:
23+
schema:
24+
type: string
25+
responses:
26+
'200':
27+
description: response
28+
content:
29+
application/json:
30+
schema:
31+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
openapi: "3.0.1"
3+
info:
4+
title: "Test title"
5+
description: "This is a test metadata"
6+
termsOfService: "http://test.com"
7+
contact:
8+
name: "Mark Snijder"
9+
url: "marksnijder.nl"
10+
11+
license:
12+
name: "To be decided"
13+
url: "http://test.com"
14+
version: "version 1.0"
15+
paths:
16+
/pets/{id}:
17+
get:
18+
description: Returns a user based on a single ID, if the user does not have access to the pet
19+
operationId: find pet by id
20+
requestBody:
21+
content:
22+
application/json:
23+
schema:
24+
type: string
25+
application/xml:
26+
schema:
27+
type: string
28+
responses:
29+
'200':
30+
description: response
31+
content:
32+
application/json:
33+
schema:
34+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
openapi: "3.0.1"
3+
info:
4+
title: "Test title"
5+
description: "This is a test metadata"
6+
termsOfService: "http://test.com"
7+
contact:
8+
name: "Mark Snijder"
9+
url: "marksnijder.nl"
10+
11+
license:
12+
name: "To be decided"
13+
url: "http://test.com"
14+
version: "version 1.0"
15+
paths:
16+
/pets/{id}:
17+
get:
18+
description: Returns a user based on a single ID, if the user does not have access to the pet
19+
operationId: find pet by id
20+
responses:
21+
'200':
22+
description: response
23+
content:
24+
application/json:
25+
schema:
26+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
openapi: "3.0.1"
3+
info:
4+
title: "Test title"
5+
description: "This is a test metadata"
6+
termsOfService: "http://test.com"
7+
contact:
8+
name: "Mark Snijder"
9+
url: "marksnijder.nl"
10+
11+
license:
12+
name: "To be decided"
13+
url: "http://test.com"
14+
version: "version 1.0"
15+
paths:
16+
/pets/{id}:
17+
get:
18+
description: Returns a user based on a single ID, if the user does not have access to the pet
19+
operationId: find pet by id
20+
responses:
21+
'200':
22+
description: response
23+
content:
24+
application/json:
25+
schema:
26+
type: string
27+
application/xml:
28+
schema:
29+
type: string

0 commit comments

Comments
 (0)