Skip to content

Commit 6265628

Browse files
Merge pull request #848
* fix(#845): Proposed solution to disable BC on pattern change
1 parent 78393d0 commit 6265628

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

core/src/main/java/org/openapitools/openapidiff/core/model/BackwardIncompatibleProp.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum BackwardIncompatibleProp {
5353
SECURITY_SCHEME_SCOPES_INCREASED("incompatible.security.scheme.scopes.increased", true),
5454
SCHEMA_DISCRIMINATOR_CHANGED("incompatible.schema.discriminator.changed", true),
5555
SCHEMA_TYPE_CHANGED("incompatible.schema.type.changed", true),
56+
SCHEMA_PATTERN_CHANGED("incompatible.schema.pattern.changed", true),
5657
;
5758

5859
private final String propertyName;

core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedPattern.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.openapitools.openapidiff.core.model.schema;
22

3+
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_PATTERN_CHANGED;
4+
35
import java.util.Objects;
46
import org.openapitools.openapidiff.core.model.Changed;
57
import org.openapitools.openapidiff.core.model.DiffContext;
@@ -18,7 +20,13 @@ public ChangedPattern(String oldPattern, String newPattern, DiffContext context)
1820

1921
@Override
2022
public DiffResult isChanged() {
21-
return Objects.equals(oldPattern, newPattern) ? DiffResult.NO_CHANGES : DiffResult.INCOMPATIBLE;
23+
if (Objects.equals(oldPattern, newPattern)) {
24+
return DiffResult.NO_CHANGES;
25+
} else if (SCHEMA_PATTERN_CHANGED.enabled(context)) {
26+
return DiffResult.INCOMPATIBLE;
27+
} else {
28+
return DiffResult.COMPATIBLE;
29+
}
2230
}
2331

2432
@Override

core/src/test/java/org/openapitools/openapidiff/core/backcompat/SchemaBCTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.openapitools.openapidiff.core.TestUtils.assertSpecUnchanged;
77
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.RESPONSE_REQUIRED_DECREASED;
88
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_DISCRIMINATOR_CHANGED;
9+
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_PATTERN_CHANGED;
910
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_TYPE_CHANGED;
1011

1112
import org.junit.jupiter.api.Test;
@@ -69,4 +70,10 @@ public void typeChanged() {
6970
BackwardIncompatibleProp prop = SCHEMA_TYPE_CHANGED;
7071
assertSpecIncompatible(BASE, "bc_schema_type_changed.yaml", prop);
7172
}
73+
74+
@Test
75+
public void patternChanged() {
76+
BackwardIncompatibleProp prop = SCHEMA_PATTERN_CHANGED;
77+
assertSpecIncompatible(BASE, "bc_schema_pattern_changed.yaml", prop);
78+
}
7279
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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: 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+
pattern: '[A-Za-z0-9#$]$'
86+
prop2:
87+
type: integer
88+
format: int32
89+
deprecated: true
90+
required:
91+
- '@type'
92+
- prop1
93+
Doodad:
94+
type: object
95+
allOf:
96+
- $ref: '#/components/schemas/Widget'
97+
- type: object
98+
properties:
99+
doodad_prop1:
100+
type: string
101+
Gadget:
102+
type: object
103+
allOf:
104+
- $ref: '#/components/schemas/Widget'
105+
- type: object
106+
properties:
107+
gadget_prop1:
108+
type: string
109+
Gizmo:
110+
type: object
111+
allOf:
112+
- $ref: '#/components/schemas/Widget'
113+
- type: object
114+
properties:
115+
gizmo_prop1:
116+
type: string

0 commit comments

Comments
 (0)