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
35 changes: 10 additions & 25 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl Compare {
if old_boolean != new_boolean {
self.schema_push_change(
dry_run,
"integer schema changed",
"boolean schema changed",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untested?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this.

&old_schema_type,
&new_schema_type,
comparison,
Expand Down Expand Up @@ -733,44 +733,29 @@ impl Compare {
Ok(ret)
}

// NOTE: Single-element allOf schemas are flattened by `try_compare_flattened`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this something we just missed when introducing try_compare_flattened?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

// before reaching this function. Multi-element allOf would require semantic
// merging for proper comparison, so we just do an equality check.
fn compare_schema_type_all_of(
&mut self,
comparison: SchemaComparison,
dry_run: bool,
old_all_of: Contextual<'_, &Vec<ReferenceOr<Schema>>>,
new_all_of: Contextual<'_, &Vec<ReferenceOr<Schema>>>,
) -> anyhow::Result<bool> {
let old_schemas = old_all_of.as_ref();
let new_schemas = new_all_of.as_ref();

if old_schemas.len() != new_schemas.len() {
return self.schema_push_change(
dry_run,
"allOf schema count changed",
&old_all_of,
&new_all_of,
comparison,
ChangeClass::Unhandled,
ChangeDetails::UnknownDifference,
);
}

if old_schemas.len() != 1 {
return self.schema_push_change(
if old_all_of.as_ref() != new_all_of.as_ref() {
self.schema_push_change(
dry_run,
"allOf with multiple schemas is unhandled",
"unhandled, 'allOf' schema",
&old_all_of,
&new_all_of,
comparison,
ChangeClass::Unhandled,
ChangeDetails::UnknownDifference,
);
)
} else {
Ok(true)
}

let old_single_schema = old_all_of.append_deref(old_all_of.first().unwrap(), "0");
let new_single_schema = new_all_of.append_deref(new_all_of.first().unwrap(), "0");

self.compare_schema_ref_helper(dry_run, comparison, old_single_schema, new_single_schema)
}

#[allow(clippy::too_many_arguments)]
Expand Down
54 changes: 54 additions & 0 deletions tests/cases/simple/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,60 @@
}
}
}
},
"/oneof": {
"get": {
"operationId": "get_oneof",
"summary": "Get oneOf schema",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MultiOneOf"
}
}
}
}
}
}
},
"/anyof": {
"get": {
"operationId": "get_anyof",
"summary": "Get anyOf schema",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AnyOfExample"
}
}
}
}
}
}
},
"/allof": {
"get": {
"operationId": "get_allof",
"summary": "Get allOf schema",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MultiAllOf"
}
}
}
}
}
}
}
},
"components": {
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-cookie-parameter.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-cookie-parameter.json
+++ patched
@@ -311,6 +311,16 @@
@@ -365,6 +365,16 @@
"get": {
"description": "A simple ping endpoint that does nothing.",
"operationId": "ping",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-default-response.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-default-response.json
+++ patched
@@ -314,6 +314,16 @@
@@ -368,6 +368,16 @@
"responses": {
"200": {
"description": "Ping successful"
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-header-parameter.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-header-parameter.json
+++ patched
@@ -311,6 +311,16 @@
@@ -365,6 +365,16 @@
"get": {
"description": "A simple ping endpoint that does nothing.",
"operationId": "ping",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-operation-with-id.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-operation-with-id.json
+++ patched
@@ -278,6 +278,17 @@
@@ -314,6 +314,17 @@
"summary": "Update an item"
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-operation.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-operation.json
+++ patched
@@ -202,6 +202,16 @@
@@ -238,6 +238,16 @@
"summary": "Get arrays"
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-optional-body.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-optional-body.json
+++ patched
@@ -281,6 +281,21 @@
@@ -317,6 +317,21 @@
"/no-body": {
"post": {
"operationId": "no_body",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-optional-parameter.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-optional-parameter.json
+++ patched
@@ -221,6 +221,15 @@
@@ -257,6 +257,15 @@
"schema": {
"type": "string"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-required-body.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-required-body.json
+++ patched
@@ -281,6 +281,21 @@
@@ -317,6 +317,21 @@
"/no-body": {
"post": {
"operationId": "no_body",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-required-parameter.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-required-parameter.json
+++ patched
@@ -221,6 +221,15 @@
@@ -257,6 +257,15 @@
"schema": {
"type": "string"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/add-response-code.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- add-response-code.json
+++ patched
@@ -314,6 +314,9 @@
@@ -368,6 +368,9 @@
"responses": {
"200": {
"description": "Ping successful"
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/body-description-change.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- body-description-change.json
+++ patched
@@ -249,6 +249,7 @@
@@ -285,6 +285,7 @@
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/body-extension-change.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- body-extension-change.json
+++ patched
@@ -249,7 +249,8 @@
@@ -285,7 +285,8 @@
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/body-optional-to-required.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- body-optional-to-required.json
+++ patched
@@ -268,7 +268,7 @@
@@ -304,7 +304,7 @@
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/body-required-to-optional.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- body-required-to-optional.json
+++ patched
@@ -249,7 +249,7 @@
@@ -285,7 +285,7 @@
}
}
},
Expand Down
31 changes: 31 additions & 0 deletions tests/cases/simple/output/boolean-enum-change.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--- boolean-enum-change.json
+++ patched
@@ -159,6 +159,9 @@
"type": "integer"
},
"enabled": {
+ "enum": [
+ true
+ ],
"type": "boolean"
},
"ratio": {


Result for patch:
[
Change {
message: "boolean schema changed",
old_path: [
"#/components/schemas/TypedProperties/properties/enabled",
"#/paths/~1typed/get/responses/200/content/application~1json/schema/$ref",
],
new_path: [
"#/components/schemas/TypedProperties/properties/enabled",
"#/paths/~1typed/get/responses/200/content/application~1json/schema/$ref",
],
comparison: Output,
class: Unhandled,
details: UnknownDifference,
},
]
2 changes: 1 addition & 1 deletion tests/cases/simple/output/change-default-response.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- change-default-response.json
+++ patched
@@ -397,7 +397,7 @@
@@ -451,7 +451,7 @@
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/change-header-parameter.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- change-header-parameter.json
+++ patched
@@ -412,7 +412,7 @@
@@ -466,7 +466,7 @@
"name": "X-Request-Id",
"required": true,
"schema": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- change-operation-parameter-requirement.json
+++ patched
@@ -217,7 +217,7 @@
@@ -253,7 +253,7 @@
"description": "Language for the greeting",
"in": "query",
"name": "language",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- change-operation-parameter-type.json
+++ patched
@@ -219,7 +219,7 @@
@@ -255,7 +255,7 @@
"name": "language",
"required": false,
"schema": {
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/simple/output/inline-to-allof.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- inline-to-allof.json
+++ patched
@@ -210,7 +210,12 @@
@@ -246,7 +246,12 @@
"in": "path",
"name": "name",
"schema": {
Expand Down
30 changes: 30 additions & 0 deletions tests/cases/simple/output/multi-allof-variant-change.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- multi-allof-variant-change.json
+++ patched
@@ -95,7 +95,7 @@
{
"properties": {
"id": {
- "type": "string"
+ "type": "integer"
}
},
"type": "object"


Result for patch:
[
Change {
message: "unhandled, 'allOf' schema",
old_path: [
"#/components/schemas/MultiAllOf/allOf",
"#/paths/~1allof/get/responses/200/content/application~1json/schema/$ref",
],
new_path: [
"#/components/schemas/MultiAllOf/allOf",
"#/paths/~1allof/get/responses/200/content/application~1json/schema/$ref",
],
comparison: Output,
class: Unhandled,
details: UnknownDifference,
},
]
30 changes: 30 additions & 0 deletions tests/cases/simple/output/multi-anyof-variant-change.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- multi-anyof-variant-change.json
+++ patched
@@ -4,7 +4,7 @@
"AnyOfExample": {
"anyOf": [
{
- "type": "string"
+ "type": "integer"
},
{
"type": "number"


Result for patch:
[
Change {
message: "unhandled, 'anyOf' schema",
old_path: [
"#/components/schemas/AnyOfExample",
"#/paths/~1anyof/get/responses/200/content/application~1json/schema/$ref",
],
new_path: [
"#/components/schemas/AnyOfExample",
"#/paths/~1anyof/get/responses/200/content/application~1json/schema/$ref",
],
comparison: Output,
class: Unhandled,
details: UnknownDifference,
},
]
Loading
Loading