Created
March 19, 2021 15:51
-
-
Save mihaelamj/de29510a1444c3ab307a2cc7fd284c9f to your computer and use it in GitHub Desktop.
Failing test when comparing JSONs (OpenAPiKit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a failing test: | |
func test_webhooks_encode() throws { | |
let op = OpenAPI.Operation(responses: [:]) | |
let document = OpenAPI.Document( | |
info: .init(title: "API", version: "1.0"), | |
servers: [], | |
paths: [:], | |
webhooks: [ | |
"webhook-test": .init(get: op, put: op, post: op, options: op, head: op, patch: op, trace: op) | |
], | |
components: .noComponents, | |
externalDocs: .init(url: URL(string: "http://google.com")!) | |
) | |
let encodedDocument = try orderUnstableTestStringFromEncoding(of: document) | |
let documentJSON: String? = | |
""" | |
{ | |
"externalDocs": { | |
"url": "http:\\/\\/google.com" | |
}, | |
"info": { | |
"title": "API", | |
"version": "1.0" | |
}, | |
"openapi": "3.0.0", | |
"paths": { | |
}, | |
"webhooks": { | |
"webhook-test": { | |
"delete": { | |
"responses": { | |
} | |
}, | |
"get": { | |
"responses": { | |
} | |
}, | |
"head": { | |
"responses": { | |
} | |
}, | |
"options": { | |
"responses": { | |
} | |
}, | |
"patch": { | |
"responses": { | |
} | |
}, | |
"post": { | |
"responses": { | |
} | |
}, | |
"put": { | |
"responses": { | |
} | |
}, | |
"trace": { | |
"responses": { | |
} | |
} | |
} | |
} | |
} | |
""" | |
assertJSONEquivalent(encodedDocument, documentJSON) | |
} | |
// I have changed the test to: | |
func test_webhooks_encode_decode() throws { | |
let op = OpenAPI.Operation(responses: [:]) | |
let document = OpenAPI.Document( | |
info: .init(title: "API", version: "1.0"), | |
servers: [], | |
paths: [:], | |
webhooks: [ | |
"webhook-test": .init(get: op, put: op, post: op, options: op, head: op, patch: op, trace: op) | |
], | |
components: .noComponents, | |
externalDocs: .init(url: URL(string: "http://google.com")!) | |
) | |
// INFO: `assertJSONEquivalent` was returning `false` for equivalent documets, so encode-decode was used for comparison - | |
let encodedDocumentString = try orderUnstableTestStringFromEncoding(of: document) | |
let encodedDocumentData = (encodedDocumentString?.data(using: .utf8)!)! | |
let decodedDocument = try orderUnstableDecode(OpenAPI.Document.self, from: encodedDocumentData) | |
XCTAssertEqual(document, decodedDocument) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment