Skip to content
Draft
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
6 changes: 5 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ on:

jobs:

api_breakage:
name: Check API breakage
uses: BinaryBirds/github-workflows/.github/workflows/api_breakage.yml@main

swiftlang_checks:
name: Swiftlang Checks
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.7
with:
license_header_check_project_name: "project"
format_check_enabled : true
Expand Down
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/BoolSchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ extension BoolSchemaRepresentable {
discriminator: nil,
externalDocs: nil,
allowedValues: nil,
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/DoubleSchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension DoubleSchemaRepresentable {
maximum: nil,
minimum: nil,
allowedValues: allowedValues?.map { .init($0) },
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/FloatSchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension FloatSchemaRepresentable {
maximum: nil,
minimum: nil,
allowedValues: allowedValues?.map { .init($0) },
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/Int32SchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension Int32SchemaRepresentable {
maximum: nil,
minimum: nil,
allowedValues: allowedValues?.map { .init($0) },
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/Int64SchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension Int64SchemaRepresentable {
maximum: nil,
minimum: nil,
allowedValues: allowedValues?.map { .init($0) },
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/IntSchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension IntSchemaRepresentable {
maximum: nil,
minimum: nil,
allowedValues: allowedValues?.map { .init($0) },
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
4 changes: 2 additions & 2 deletions Sources/FeatherOpenAPI/Schema/StringSchemaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension StringSchemaRepresentable {
maxLength: nil,
pattern: nil,
allowedValues: allowedValues?.map { .init($0) },
defaultValue: .init(defaultValue),
example: .init(example)
defaultValue: defaultValue.map { .init($0) },
example: example.map { .init($0) }
)
}
}
84 changes: 84 additions & 0 deletions Tests/FeatherOpenAPITests/SchemaSerializationTestSuite.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import OpenAPIKit30
import Testing
import Yams

@testable import FeatherOpenAPI

@Suite
struct SchemaSerializationTestSuite {

@Test
func omittedStringDefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder()
.encode(OmittedStringSchema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func omittedIntDefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder().encode(OmittedIntSchema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func omittedInt32DefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder()
.encode(OmittedInt32Schema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func omittedInt64DefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder()
.encode(OmittedInt64Schema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func omittedFloatDefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder()
.encode(OmittedFloatSchema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func omittedDoubleDefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder()
.encode(OmittedDoubleSchema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func omittedBoolDefaultAndExampleDoNotSerializeAsNull() throws {
let yaml = try YAMLEncoder().encode(OmittedBoolSchema().openAPISchema())
#expect(yaml.contains("default: null") == false)
#expect(yaml.contains("example: null") == false)
}

@Test
func explicitDefaultAndExampleStillSerialize() throws {
let yaml = try YAMLEncoder()
.encode(ExplicitStringSchema().openAPISchema())
#expect(yaml.contains("default: abc"))
#expect(yaml.contains("example: xyz"))
}
}

private struct OmittedStringSchema: StringSchemaRepresentable {}
private struct OmittedIntSchema: IntSchemaRepresentable {}
private struct OmittedInt32Schema: Int32SchemaRepresentable {}
private struct OmittedInt64Schema: Int64SchemaRepresentable {}
private struct OmittedFloatSchema: FloatSchemaRepresentable {}
private struct OmittedDoubleSchema: DoubleSchemaRepresentable {}
private struct OmittedBoolSchema: BoolSchemaRepresentable {}

private struct ExplicitStringSchema: StringSchemaRepresentable {
var defaultValue: String? { "abc" }
var example: String? { "xyz" }
}