Skip to content

Commit ab3854a

Browse files
committed
Compatibility test Schema
1 parent 0fb2408 commit ab3854a

11 files changed

+1212
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.openapitools.openapidiff.core.backcompat;
2+
3+
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiBackwardIncompatible;
4+
import static org.openapitools.openapidiff.core.TestUtils.assertSpecChangedButCompatible;
5+
import static org.openapitools.openapidiff.core.TestUtils.assertSpecUnchanged;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
public class SchemaBCTest {
10+
private final String BASE = "bc_schema_base.yaml";
11+
12+
@Test
13+
public void unchanged() {
14+
assertSpecUnchanged(BASE, BASE);
15+
}
16+
17+
@Test
18+
public void changedButCompatible() {
19+
assertSpecChangedButCompatible(BASE, "bc_schema_changed_but_compatible.yaml");
20+
}
21+
22+
@Test
23+
public void discriminatorChanged() {
24+
assertOpenApiBackwardIncompatible(BASE, "bc_schema_discriminator_changed.yaml");
25+
}
26+
27+
@Test
28+
public void requestFormatDecreased() {
29+
assertOpenApiBackwardIncompatible(BASE, "bc_request_schema_format_decreased.yaml");
30+
}
31+
32+
@Test
33+
public void requestFormatIncreased() {
34+
// TODO: Document why desired or remove support (test added to avoid unintentional regression)
35+
assertOpenApiBackwardIncompatible(BASE, "bc_request_schema_format_increased.yaml");
36+
}
37+
38+
@Test
39+
public void requestPropsPutIncreased() {
40+
// TODO: Document why desired or remove support (test added to avoid unintentional regression)
41+
// See https://github.com/OpenAPITools/openapi-diff/issues/537
42+
assertOpenApiBackwardIncompatible(BASE, "bc_request_schema_props_put_increased.yaml");
43+
}
44+
45+
@Test
46+
public void responseFormatDecreased() {
47+
// TODO: Document why desired or remove support (test added to avoid unintentional regression)
48+
assertOpenApiBackwardIncompatible(BASE, "bc_response_schema_format_decreased.yaml");
49+
}
50+
51+
@Test
52+
public void responseFormatIncreased() {
53+
assertOpenApiBackwardIncompatible(BASE, "bc_response_schema_format_increased.yaml");
54+
}
55+
56+
@Test
57+
public void responsePropsRequiredDecreased() {
58+
assertOpenApiBackwardIncompatible(BASE, "bc_response_schema_props_required_decreased.yaml");
59+
}
60+
61+
@Test
62+
public void typeChanged() {
63+
assertOpenApiBackwardIncompatible(BASE, "bc_schema_type_changed.yaml");
64+
}
65+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
openapi: 3.0.0
2+
info:
3+
description: myDesc
4+
title: myTitle
5+
version: 1.0.0
6+
paths:
7+
/widgets:
8+
post:
9+
operationId: widgetCreate
10+
requestBody:
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/WidgetCreateRequest'
15+
responses:
16+
'200':
17+
description: successful operation
18+
content:
19+
application/json:
20+
schema:
21+
$ref: '#/components/schemas/WidgetCreateResponse'
22+
put:
23+
operationId: widgetUpdate
24+
requestBody:
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
properties:
30+
put_prop1:
31+
type: string
32+
put_prop2:
33+
type: string
34+
responses:
35+
'200':
36+
description: successful operation
37+
content:
38+
application/json:
39+
schema:
40+
type: string
41+
components:
42+
schemas:
43+
WidgetCreateRequest:
44+
type: object
45+
properties:
46+
to_create:
47+
$ref: '#/components/schemas/Widget_Polymorphic'
48+
request_prop1:
49+
type: integer
50+
format: int32
51+
request_prop2:
52+
type: integer
53+
format: int32
54+
required:
55+
- to_create
56+
- request_prop1
57+
WidgetCreateResponse:
58+
type: object
59+
properties:
60+
created:
61+
$ref: '#/components/schemas/Widget_Polymorphic'
62+
response_prop1:
63+
type: integer
64+
format: int32
65+
response_prop2:
66+
type: integer
67+
format: int64
68+
required:
69+
- created
70+
- response_prop1
71+
Widget_Polymorphic:
72+
type: object
73+
oneOf:
74+
- $ref: '#/components/schemas/Doodad'
75+
- $ref: '#/components/schemas/Gadget'
76+
discriminator:
77+
propertyName: '@type'
78+
Widget:
79+
type: object
80+
properties:
81+
'@type':
82+
type: string
83+
prop1:
84+
type: string
85+
prop2:
86+
type: integer
87+
format: int32
88+
deprecated: true
89+
required:
90+
- '@type'
91+
- prop1
92+
Doodad:
93+
type: object
94+
allOf:
95+
- $ref: '#/components/schemas/Widget'
96+
- type: object
97+
properties:
98+
doodad_prop1:
99+
type: string
100+
Gadget:
101+
type: object
102+
allOf:
103+
- $ref: '#/components/schemas/Widget'
104+
- type: object
105+
properties:
106+
gadget_prop1:
107+
type: string
108+
Gizmo:
109+
type: object
110+
allOf:
111+
- $ref: '#/components/schemas/Widget'
112+
- type: object
113+
properties:
114+
gizmo_prop1:
115+
type: string
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
openapi: 3.0.0
2+
info:
3+
description: myDesc
4+
title: myTitle
5+
version: 1.0.0
6+
paths:
7+
/widgets:
8+
post:
9+
operationId: widgetCreate
10+
requestBody:
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/WidgetCreateRequest'
15+
responses:
16+
'200':
17+
description: successful operation
18+
content:
19+
application/json:
20+
schema:
21+
$ref: '#/components/schemas/WidgetCreateResponse'
22+
put:
23+
operationId: widgetUpdate
24+
requestBody:
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
properties:
30+
put_prop1:
31+
type: string
32+
put_prop2:
33+
type: string
34+
responses:
35+
'200':
36+
description: successful operation
37+
content:
38+
application/json:
39+
schema:
40+
type: string
41+
components:
42+
schemas:
43+
WidgetCreateRequest:
44+
type: object
45+
properties:
46+
to_create:
47+
$ref: '#/components/schemas/Widget_Polymorphic'
48+
request_prop1:
49+
type: integer
50+
format: int64
51+
request_prop2:
52+
type: integer
53+
format: int64
54+
required:
55+
- to_create
56+
- request_prop1
57+
WidgetCreateResponse:
58+
type: object
59+
properties:
60+
created:
61+
$ref: '#/components/schemas/Widget_Polymorphic'
62+
response_prop1:
63+
type: integer
64+
format: int32
65+
response_prop2:
66+
type: integer
67+
format: int64
68+
required:
69+
- created
70+
- response_prop1
71+
Widget_Polymorphic:
72+
type: object
73+
oneOf:
74+
- $ref: '#/components/schemas/Doodad'
75+
- $ref: '#/components/schemas/Gadget'
76+
discriminator:
77+
propertyName: '@type'
78+
Widget:
79+
type: object
80+
properties:
81+
'@type':
82+
type: string
83+
prop1:
84+
type: string
85+
prop2:
86+
type: integer
87+
format: int32
88+
deprecated: true
89+
required:
90+
- '@type'
91+
- prop1
92+
Doodad:
93+
type: object
94+
allOf:
95+
- $ref: '#/components/schemas/Widget'
96+
- type: object
97+
properties:
98+
doodad_prop1:
99+
type: string
100+
Gadget:
101+
type: object
102+
allOf:
103+
- $ref: '#/components/schemas/Widget'
104+
- type: object
105+
properties:
106+
gadget_prop1:
107+
type: string
108+
Gizmo:
109+
type: object
110+
allOf:
111+
- $ref: '#/components/schemas/Widget'
112+
- type: object
113+
properties:
114+
gizmo_prop1:
115+
type: string

0 commit comments

Comments
 (0)