Skip to content

Commit

Permalink
Merge pull request #7 from mattpolzin/a-few-more-diffs
Browse files Browse the repository at this point in the history
fill out a bit more code to diff things that weren't yet being compared.
  • Loading branch information
mattpolzin authored May 11, 2024
2 parents d2ac032 + bdcb9fb commit 6887e65
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -214,15 +241,15 @@ 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: [
openAPIVersion.compare(to: other.openAPIVersion, in: "OpenAPI Spec Version"),
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")
Expand All @@ -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)**" }
Expand Down
26 changes: 26 additions & 0 deletions Tests/OpenAPIDiffTests/OpenAPIDiffTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XCTest
import OpenAPIKit
import OpenAPIDiff

final class OpenAPIDiffTests: XCTestCase {
Expand Down Expand Up @@ -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")
]
)
)
}
}

0 comments on commit 6887e65

Please sign in to comment.