Skip to content

DrSatyr/issue212 #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
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
@@ -352,4 +352,60 @@ public void changePatternHandling() {
assertThat(props.get("patternAdded").getPattern().getNewPattern())
.isEqualTo("^\\d{3}-\\d{2}-\\d{4}$?");
}

@Test // issue #212
public void testAnyOfDiff() {
ChangedOpenApi changedOpenApi =
OpenApiCompare.fromLocations(
"schemaDiff/anyOf-diff-1.yaml", "schemaDiff/anyOf-diff-2.yaml");
ChangedSchema changedSchema =
getRequestBodyChangedSchema(changedOpenApi, POST, "/anyof/test", "application/json");

assertThat(changedSchema).isNotNull();
// The diff compares the *merged* schema resulting from anyOf, not the anyOf structure itself.
// See details in #772
assertThat(changedSchema.isChanged()).isEqualTo(DiffResult.COMPATIBLE);

// fieldA only changed required status, not its schema
assertThat(changedSchema.getChangedProperties()).isEmpty();

// fieldB: Removed from the merged schema properties
assertThat(changedSchema.getMissingProperties()).containsKey("fieldB");

// fieldC: Added to the merged schema properties
assertThat(changedSchema.getIncreasedProperties()).containsKey("fieldC");

// Check the overall required list changes for the merged schema
assertThat(changedSchema.getRequired().isChanged()).isEqualTo(DiffResult.COMPATIBLE);
assertThat(changedSchema.getRequired().getMissing()).containsExactly("fieldA");
assertThat(changedSchema.getRequired().getIncreased()).isEmpty();
}

@Test // issue #212 - adapted for allOf
public void testAllOfDiff() {
ChangedOpenApi changedOpenApi =
OpenApiCompare.fromLocations(
"schemaDiff/allOf-diff-1.yaml", "schemaDiff/allOf-diff-2.yaml");
ChangedSchema changedSchema =
getRequestBodyChangedSchema(changedOpenApi, POST, "/allof/test", "application/json");

assertThat(changedSchema).isNotNull();
// The diff compares the *merged* schema resulting from allOf, not the allOf structure itself.
// See details in #772
assertThat(changedSchema.isChanged()).isEqualTo(DiffResult.COMPATIBLE);

// fieldA only changed required status, commonField is unchanged
assertThat(changedSchema.getChangedProperties()).isEmpty();

// fieldB: Removed from the merged schema properties
assertThat(changedSchema.getMissingProperties()).containsKey("fieldB");

// fieldC: Added to the merged schema properties
assertThat(changedSchema.getIncreasedProperties()).containsKey("fieldC");

// Check the overall required list changes for the merged schema
assertThat(changedSchema.getRequired().isChanged()).isEqualTo(DiffResult.COMPATIBLE);
assertThat(changedSchema.getRequired().getMissing()).containsExactly("fieldA");
assertThat(changedSchema.getRequired().getIncreased()).isEmpty();
}
}
35 changes: 35 additions & 0 deletions core/src/test/resources/schemaDiff/allOf-diff-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
title: AllOf Diff Test - Version 1
version: 1.0.0
paths:
/allof/test:
post:
summary: Test endpoint for allOf diff
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeB'
responses:
'200':
description: OK
components:
schemas:
TypeA:
type: object
required:
- fieldA
properties:
fieldA:
type: string
commonField:
type: integer
TypeB:
type: object
properties:
fieldB:
type: boolean
34 changes: 34 additions & 0 deletions core/src/test/resources/schemaDiff/allOf-diff-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.0
info:
title: AllOf Diff Test - Version 2
version: 1.0.0
paths:
/allof/test:
post:
summary: Test endpoint for allOf diff
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeC'
responses:
'200':
description: OK
components:
schemas:
TypeA:
type: object
# fieldA is no longer required here
properties:
fieldA:
type: string
commonField:
type: integer
TypeC:
type: object
properties:
fieldC:
type: number
35 changes: 35 additions & 0 deletions core/src/test/resources/schemaDiff/anyOf-diff-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
title: AnyOf Diff Test - Version 1
version: 1.0.0
paths:
/anyof/test:
post:
summary: Test endpoint for anyOf diff
requestBody:
required: true
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeB'
responses:
'200':
description: OK
components:
schemas:
TypeA:
type: object
properties:
fieldA:
type: string
commonField:
type: integer
required:
- fieldA
TypeB:
type: object
properties:
fieldB:
type: boolean
33 changes: 33 additions & 0 deletions core/src/test/resources/schemaDiff/anyOf-diff-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
openapi: 3.0.0
info:
title: AnyOf Diff Test - Version 2
version: 1.0.0
paths:
/anyof/test:
post:
summary: Test endpoint for anyOf diff
requestBody:
required: true
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeC'
responses:
'200':
description: OK
components:
schemas:
TypeA:
type: object
properties:
fieldA:
type: string
commonField:
type: integer
TypeC:
type: object
properties:
fieldC:
type: number