Skip to content

Commit

Permalink
Add another test around vendor extensions for JSON Schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Oct 29, 2023
1 parent ddcae4a commit 5a937cb
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Tests/OpenAPIKit30Tests/Schema Object/JSONSchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,61 @@ extension SchemaObjectTests {
)
}

func test_decodeObjectWithVendorExtensions() throws {
let requiredPropertiesObjectData = """
{
"required": ["test"],
"properties": {
"test": {
"default": true,
"title": "Apply Watermark",
"type": "boolean",
"x-order": 15
}
},
"type": "object"
}
""".data(using: .utf8)!

let optionalPropertiesObjectData = """
{
"properties": {
"test": {
"default": true,
"title": "Apply Watermark",
"type": "boolean",
"x-order": 15
}
},
"type": "object"
}
""".data(using: .utf8)!

let requiredPropertiesObject = try orderUnstableDecode(JSONSchema.self, from: requiredPropertiesObjectData)
let optionalPropertiesObject = try orderUnstableDecode(JSONSchema.self, from: optionalPropertiesObjectData)

XCTAssertEqual(requiredPropertiesObject.objectContext?.properties["test"]?.vendorExtensions, [ "x-order": 15 ])
XCTAssertEqual(optionalPropertiesObject.objectContext?.properties["test"]?.vendorExtensions, [ "x-order": 15 ])

XCTAssertEqual(
requiredPropertiesObject,
JSONSchema.object(
properties: [
"test": JSONSchema(.boolean(required: true, title: "Apply Watermark", defaultValue: true), vendorExtensions: [ "x-order": 15 ])
]
)
)

XCTAssertEqual(
optionalPropertiesObject,
JSONSchema.object(
properties: [
"test": JSONSchema(.boolean(required: false, title: "Apply Watermark", defaultValue: true), vendorExtensions: [ "x-order": 15 ])
]
)
)
}

func test_encodeArray() {
let requiredArray = JSONSchema.array(.init(format: .unspecified, required: true), .init())
let optionalArray = JSONSchema.array(.init(format: .unspecified, required: false), .init())
Expand Down
55 changes: 55 additions & 0 deletions Tests/OpenAPIKitTests/Schema Object/JSONSchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3450,6 +3450,61 @@ extension SchemaObjectTests {
)
}

func test_decodeObjectWithVendorExtensions() throws {
let requiredPropertiesObjectData = """
{
"required": ["test"],
"properties": {
"test": {
"default": true,
"title": "Apply Watermark",
"type": "boolean",
"x-order": 15
}
},
"type": "object"
}
""".data(using: .utf8)!

let optionalPropertiesObjectData = """
{
"properties": {
"test": {
"default": true,
"title": "Apply Watermark",
"type": "boolean",
"x-order": 15
}
},
"type": "object"
}
""".data(using: .utf8)!

let requiredPropertiesObject = try orderUnstableDecode(JSONSchema.self, from: requiredPropertiesObjectData)
let optionalPropertiesObject = try orderUnstableDecode(JSONSchema.self, from: optionalPropertiesObjectData)

XCTAssertEqual(requiredPropertiesObject.objectContext?.properties["test"]?.vendorExtensions, [ "x-order": 15 ])
XCTAssertEqual(optionalPropertiesObject.objectContext?.properties["test"]?.vendorExtensions, [ "x-order": 15 ])

XCTAssertEqual(
requiredPropertiesObject,
JSONSchema.object(
properties: [
"test": JSONSchema.boolean(required: true, title: "Apply Watermark", defaultValue: true).with(vendorExtensions: [ "x-order": 15 ])
]
)
)

XCTAssertEqual(
optionalPropertiesObject,
JSONSchema.object(
properties: [
"test": JSONSchema.boolean(required: false, title: "Apply Watermark", defaultValue: true).with(vendorExtensions: [ "x-order": 15 ])
]
)
)
}

func test_encodeArray() {
let requiredArray = JSONSchema.array(.init(format: .unspecified, required: true), .init())
let optionalArray = JSONSchema.array(.init(format: .unspecified, required: false), .init())
Expand Down

0 comments on commit 5a937cb

Please sign in to comment.