Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public enum BackwardIncompatibleProp {
SECURITY_SCHEME_SCOPES_INCREASED("incompatible.security.scheme.scopes.increased", true),
SCHEMA_DISCRIMINATOR_CHANGED("incompatible.schema.discriminator.changed", true),
SCHEMA_TYPE_CHANGED("incompatible.schema.type.changed", true),
SCHEMA_PATTERN_CHANGED("incompatible.schema.pattern.changed", true),
;

private final String propertyName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.openapitools.openapidiff.core.model.schema;

import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_PATTERN_CHANGED;

import java.util.Objects;
import org.openapitools.openapidiff.core.model.Changed;
import org.openapitools.openapidiff.core.model.DiffContext;
Expand All @@ -18,7 +20,13 @@ public ChangedPattern(String oldPattern, String newPattern, DiffContext context)

@Override
public DiffResult isChanged() {
return Objects.equals(oldPattern, newPattern) ? DiffResult.NO_CHANGES : DiffResult.INCOMPATIBLE;
if (Objects.equals(oldPattern, newPattern)) {
return DiffResult.NO_CHANGES;
} else if (SCHEMA_PATTERN_CHANGED.enabled(context)) {
return DiffResult.INCOMPATIBLE;
} else {
return DiffResult.COMPATIBLE;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.openapitools.openapidiff.core.TestUtils.assertSpecUnchanged;
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.RESPONSE_REQUIRED_DECREASED;
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_DISCRIMINATOR_CHANGED;
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_PATTERN_CHANGED;
import static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.SCHEMA_TYPE_CHANGED;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -69,4 +70,10 @@ public void typeChanged() {
BackwardIncompatibleProp prop = SCHEMA_TYPE_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_type_changed.yaml", prop);
}

@Test
public void patternChanged() {
BackwardIncompatibleProp prop = SCHEMA_PATTERN_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_pattern_changed.yaml", prop);
}
}
116 changes: 116 additions & 0 deletions core/src/test/resources/bc_schema_pattern_changed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
openapi: 3.0.0
info:
description: myDesc
title: myTitle
version: 1.0.0
paths:
/widgets:
post:
operationId: widgetCreate
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/WidgetCreateRequest'
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/WidgetCreateResponse'
put:
operationId: widgetUpdate
requestBody:
content:
application/json:
schema:
type: object
properties:
put_prop1:
type: string
put_prop2:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: string
components:
schemas:
WidgetCreateRequest:
type: object
properties:
to_create:
$ref: '#/components/schemas/Widget_Polymorphic'
request_prop1:
type: integer
format: int32
request_prop2:
type: integer
format: int64
required:
- to_create
- request_prop1
WidgetCreateResponse:
type: object
properties:
created:
$ref: '#/components/schemas/Widget_Polymorphic'
response_prop1:
type: integer
format: int32
response_prop2:
type: integer
format: int64
required:
- created
- response_prop1
Widget_Polymorphic:
type: object
oneOf:
- $ref: '#/components/schemas/Doodad'
- $ref: '#/components/schemas/Gadget'
discriminator:
propertyName: '@type'
Widget:
type: object
properties:
'@type':
type: string
prop1:
type: string
pattern: '[A-Za-z0-9#$]$'
prop2:
type: integer
format: int32
deprecated: true
required:
- '@type'
- prop1
Doodad:
type: object
allOf:
- $ref: '#/components/schemas/Widget'
- type: object
properties:
doodad_prop1:
type: string
Gadget:
type: object
allOf:
- $ref: '#/components/schemas/Widget'
- type: object
properties:
gadget_prop1:
type: string
Gizmo:
type: object
allOf:
- $ref: '#/components/schemas/Widget'
- type: object
properties:
gizmo_prop1:
type: string