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 @@ -52,8 +52,10 @@ public enum BackwardIncompatibleProp {
SECURITY_SCHEME_SCHEME_CHANGED("incompatible.security.scheme.scheme.changed", true),
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),
SCHEMA_MIN_PROPERTIES_CHANGED("incompatible.schema.min-properties.changed", true),
SCHEMA_MAX_PROPERTIES_CHANGED("incompatible.schema.max-properties.changed", true),
SCHEMA_TYPE_CHANGED("incompatible.schema.type.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_MAX_PROPERTIES_CHANGED;

import org.openapitools.openapidiff.core.model.Changed;
import org.openapitools.openapidiff.core.model.DiffContext;
import org.openapitools.openapidiff.core.model.DiffResult;
Expand Down Expand Up @@ -30,15 +32,23 @@ public DiffResult isChanged() {
}

if (oldValue == null) {
return DiffResult.INCOMPATIBLE;
if (SCHEMA_MAX_PROPERTIES_CHANGED.enabled(context)) {
return DiffResult.INCOMPATIBLE;
} else {
return DiffResult.COMPATIBLE;
}
}

if (newValue == null) {
return DiffResult.COMPATIBLE;
}

if (!oldValue.equals(newValue)) {
return oldValue > newValue ? DiffResult.INCOMPATIBLE : DiffResult.COMPATIBLE;
if (SCHEMA_MAX_PROPERTIES_CHANGED.enabled(context) && oldValue > newValue) {
return DiffResult.INCOMPATIBLE;
} else {
return DiffResult.COMPATIBLE;
}
}

return DiffResult.NO_CHANGES;
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_MIN_PROPERTIES_CHANGED;

import org.openapitools.openapidiff.core.model.Changed;
import org.openapitools.openapidiff.core.model.DiffContext;
import org.openapitools.openapidiff.core.model.DiffResult;
Expand Down Expand Up @@ -30,15 +32,23 @@ public DiffResult isChanged() {
}

if (oldValue == null) {
return DiffResult.INCOMPATIBLE;
if (SCHEMA_MIN_PROPERTIES_CHANGED.enabled(context)) {
return DiffResult.INCOMPATIBLE;
} else {
return DiffResult.COMPATIBLE;
}
}

if (newValue == null) {
return DiffResult.COMPATIBLE;
}

if (!oldValue.equals(newValue)) {
return newValue > oldValue ? DiffResult.INCOMPATIBLE : DiffResult.COMPATIBLE;
if (SCHEMA_MIN_PROPERTIES_CHANGED.enabled(context) && newValue > oldValue) {
return DiffResult.INCOMPATIBLE;
} else {
return DiffResult.COMPATIBLE;
}
}

return DiffResult.NO_CHANGES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import static org.openapitools.openapidiff.core.TestUtils.assertSpecChangedButCompatible;
import static org.openapitools.openapidiff.core.TestUtils.assertSpecIncompatible;
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 static org.openapitools.openapidiff.core.model.BackwardIncompatibleProp.*;

import org.junit.jupiter.api.Test;
import org.openapitools.openapidiff.core.model.BackwardIncompatibleProp;
Expand Down Expand Up @@ -76,4 +73,28 @@ public void patternChanged() {
BackwardIncompatibleProp prop = SCHEMA_PATTERN_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_pattern_changed.yaml", prop);
}

@Test
public void minPropertiesIncreased() {
BackwardIncompatibleProp prop = SCHEMA_MIN_PROPERTIES_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_min_properties_increased.yaml", prop);
}

@Test
public void minPropertiesAdded() {
BackwardIncompatibleProp prop = SCHEMA_MIN_PROPERTIES_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_min_properties_added.yaml", prop);
}

@Test
public void maxPropertiesDecreased() {
BackwardIncompatibleProp prop = SCHEMA_MAX_PROPERTIES_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_max_properties_decreased.yaml", prop);
}

@Test
public void maxPropertiesAdded() {
BackwardIncompatibleProp prop = SCHEMA_MAX_PROPERTIES_CHANGED;
assertSpecIncompatible(BASE, "bc_schema_max_properties_added.yaml", prop);
}
}
10 changes: 10 additions & 0 deletions core/src/test/resources/bc_schema_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ components:
type: integer
format: int32
deprecated: true
stuffUnbounded:
type: object
additionalProperties:
type: string
stuffBounded:
type: object
minProperties: 1
maxProperties: 10
additionalProperties:
type: string
required:
- '@type'
- prop1
Expand Down
126 changes: 126 additions & 0 deletions core/src/test/resources/bc_schema_max_properties_added.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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
prop2:
type: integer
format: int32
deprecated: true
stuffUnbounded:
type: object
maxProperties: 5
additionalProperties:
type: string
stuffBounded:
type: object
minProperties: 1
maxProperties: 10
additionalProperties:
type: string
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
125 changes: 125 additions & 0 deletions core/src/test/resources/bc_schema_max_properties_decreased.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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
prop2:
type: integer
format: int32
deprecated: true
stuffUnbounded:
type: object
additionalProperties:
type: string
stuffBounded:
type: object
minProperties: 1
maxProperties: 5
additionalProperties:
type: string
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
Loading