From 23ac470f1d2c1ecf22af9dfaf258143e72163da1 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sat, 11 May 2024 17:01:41 -0500 Subject: [PATCH 1/3] fill out a bit more code to diff things that weren't yet being compared. --- .../OpenAPI+ApiComparable.swift | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/Sources/OpenAPIDiff/Comparable Conformances/OpenAPI Comparables/OpenAPI+ApiComparable.swift b/Sources/OpenAPIDiff/Comparable Conformances/OpenAPI Comparables/OpenAPI+ApiComparable.swift index 877d57f..85d2294 100644 --- a/Sources/OpenAPIDiff/Comparable Conformances/OpenAPI Comparables/OpenAPI+ApiComparable.swift +++ b/Sources/OpenAPIDiff/Comparable Conformances/OpenAPI Comparables/OpenAPI+ApiComparable.swift @@ -14,27 +14,54 @@ extension OpenAPI.Content: ApiComparable { context: context, changes: [ schema.compare(to: other.schema, in: "schema"), -// example.compare(to: other.example, in: "example"), -// examples.compare(to: other.examples, in: "examples"), + String(describing: example).compare(to: String(describing: other.example), in: "example"), + examples.compare(to: other.examples, in: "examples"), // encoding.compare(to: other.encoding, in: "encoding") ] ) } } +extension OpenAPI.Example: ApiComparable { + public func compare(to other: OpenAPI.Example, in context: String?) -> ApiDiff { + return .init( + context: context, + changes: [ + summary.compare(to: other.summary, in: "summary"), + description.compare(to: other.description, in: "description"), + String(describing: value).compare(to: String(describing: other.value), in: "value") + ] + ) + } +} + extension OpenAPI.Response: ApiComparable { public func compare(to other: OpenAPI.Response, in context: String?) -> ApiDiff { return .init( context: context, changes: [ description.compare(to: other.description, in: "description"), -// headers.compare(to: other.headers, in: "headers"), + headers.compare(to: other.headers, in: "headers"), content.compare(to: other.content, in: "content") ] ) } } +extension OpenAPI.Header: ApiComparable { + public func compare(to other: OpenAPI.Header, in context: String?) -> ApiDiff { + return .init( + context: context, + changes: [ + description.compare(to: other.description, in: "description"), + required.compare(to: other.required, in: "required"), + deprecated.compare(to: other.deprecated, in: "deprecated"), + schemaOrContent.compare(to: other.schemaOrContent, in: "schema or content") + ] + ) + } +} + extension OpenAPI.Request: ApiComparable { public func compare(to other: OpenAPI.Request, in context: String?) -> ApiDiff { return .init( @@ -214,7 +241,6 @@ extension OpenAPI.Tag: ApiComparable { extension OpenAPI.Document: ApiComparable { public func compare(to other: OpenAPI.Document, in context: String? = nil) -> ApiDiff { - // TODO: finish differ return .init( context: context ?? apiContext, changes: [ @@ -222,7 +248,8 @@ extension OpenAPI.Document: ApiComparable { info.compare(to: other.info, in: "info"), servers.compare(to: other.servers, in: "servers"), paths.compare(to: other.paths, in: "paths"), -// components.compare(to: other.components, in: "components"), + components.compare(to: other.components, in: "components"), + webhooks.compare(to: other.webhooks, in: "webhooks"), security.compare(to: other.security, in: "security"), tags.compare(to: other.tags, in: "tags"), externalDocs.compare(to: other.externalDocs, in: "external docs") @@ -231,6 +258,27 @@ extension OpenAPI.Document: ApiComparable { } } +extension OpenAPI.Components: ApiComparable { + public func compare(to other: OpenAPI.Components, in context: String? = nil) -> ApiDiff { + // TODO: finish implementation + return .init( + context: context ?? "components", + changes: [ + schemas.compare(to: other.schemas, in: "schemas"), + responses.compare(to: other.responses, in: "responses"), + parameters.compare(to: other.parameters, in: "parameters"), + examples.compare(to: other.examples, in: "examples"), + requestBodies.compare(to: other.requestBodies, in: "requestBodies"), + headers.compare(to: other.headers, in: "headers"), + securitySchemes.compare(to: other.securitySchemes, in: "securitySchemes"), +// links.compare(to: other.links, in: "links"), + callbacks.compare(to: other.callbacks, in: "callbacks"), + pathItems.compare(to: other.pathItems, in: "path items") + ] + ) + } +} + // MARK: - ApiContext extension OpenAPI.Path: ApiContext { public var apiContext: String { "**\(rawValue)**" } From 1f6a25e2f4c43dbb5fa5866414071083dd54dda4 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sat, 11 May 2024 17:03:10 -0500 Subject: [PATCH 2/3] Add Swift 5.10 to test matrix --- .github/workflows/codecov.yml | 2 +- .github/workflows/tests.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 4a583d9..faffbe2 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -5,7 +5,7 @@ on: [pull_request] jobs: codecov: container: - image: swift:5.8-focal + image: swift:5.9-focal runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9429e1d..a5caa4f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,6 +20,9 @@ jobs: - swift:5.9-focal - swift:5.9-jammy - swift:5.9-amazonlinux2 + - swift:5.10-focal + - swift:5.10-jammy + - swift:5.10-amazonlinux2 container: ${{ matrix.image }} steps: - name: Checkout code From bdcb9fbd15fd2bd72135c6caa16bc5635892b15c Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sat, 11 May 2024 17:12:23 -0500 Subject: [PATCH 3/3] Add a test for tag differences --- Tests/OpenAPIDiffTests/OpenAPIDiffTests.swift | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tests/OpenAPIDiffTests/OpenAPIDiffTests.swift b/Tests/OpenAPIDiffTests/OpenAPIDiffTests.swift index 0f42efc..891c085 100644 --- a/Tests/OpenAPIDiffTests/OpenAPIDiffTests.swift +++ b/Tests/OpenAPIDiffTests/OpenAPIDiffTests.swift @@ -1,4 +1,5 @@ import XCTest +import OpenAPIKit import OpenAPIDiff final class OpenAPIDiffTests: XCTestCase { @@ -49,4 +50,29 @@ final class OpenAPIDiffTests: XCTestCase { XCTAssertEqual(comparison2.diff, .changed([.same("2nd item - world"), .changed(context: "1st item - hello", from: "hello", to: "big")])) } + + func test_tagDifference() { + let before = OpenAPI.Tag( + name: "tag 1", + description: "first tag" + ) + let after = OpenAPI.Tag( + name: "tag 1 (new)", + description: "first tag for now" + ) + + let comparison = before.compare(to: after, in: "tags") + + XCTAssertEqual( + comparison, + .changed( + "tags", + diff: [ + .same("external docs"), + .changed(context: "name", from: "tag 1", to: "tag 1 (new)"), + .changed(context: "description", from: "first tag", to: "first tag for now") + ] + ) + ) + } }