Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"),

// Read OpenAPI documents
.package(url: "https://github.com/mattpolzin/OpenAPIKit.git", from: "3.0.1"),
.package(url: "https://github.com/mattpolzin/OpenAPIKit.git", from: "3.1.0"),
.package(url: "https://github.com/jpsim/Yams.git", "4.0.0"..<"6.0.0"),

// CLI Tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ extension FileTranslator {

let foundIn = "\(typeName.description)/\(key)"

// Properties that are only defined in the `required` list but don't
// have a proper definition in the `properties` map are skipped, as they
// often imply a typo or a mistake in the document. So emit a diagnostic as well.
guard !value.inferred else {
diagnostics.emit(
.warning(
message:
"A property name only appears in the required list, but not in the properties map - this is likely a typo; skipping this property.",
context: ["foundIn": foundIn]
)
)
return false
}

// We need to catch a special case here:
// type: string + format: binary.
// It means binary data (unlike format: byte, which means base64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,38 @@ final class SnippetBasedReferenceTests: XCTestCase {
)
}

func testComponentsSchemasObjectWithInferredProperty() throws {
try self.assertSchemasTranslation(
ignoredDiagnosticMessages: [
"A property name only appears in the required list, but not in the properties map - this is likely a typo; skipping this property."
],
"""
schemas:
MyObj:
type: object
properties:
fooRequired:
type: string
required:
- fooRequired
- fooInferred
""",
"""
public enum Schemas {
public struct MyObj: Codable, Hashable, Sendable {
public var fooRequired: Swift.String
public init(fooRequired: Swift.String) {
self.fooRequired = fooRequired
}
public enum CodingKeys: String, CodingKey {
case fooRequired
}
}
}
"""
)
}

func testComponentsObjectNoAdditionalProperties() throws {
try self.assertSchemasTranslation(
"""
Expand Down