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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

/// Example struct to be used instead of the default generated type.
/// This illustrates how to introduce a type performing additional validation during Decoding that cannot be expressed with OpenAPI
public struct CustomPrimeNumber: Codable, Hashable, RawRepresentable, Sendable {
public let rawValue: Int
public init?(rawValue: Int) {
struct CustomPrimeNumber: Codable, Hashable, RawRepresentable, Sendable {
let rawValue: Int
init?(rawValue: Int) {
if !rawValue.isPrime { return nil }
self.rawValue = rawValue
}

public init(from decoder: any Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let number = try container.decode(Int.self)
guard let value = Self(rawValue: number) else {
Expand All @@ -30,7 +30,7 @@ public struct CustomPrimeNumber: Codable, Hashable, RawRepresentable, Sendable {
self = value
}

public func encode(to encoder: any Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.rawValue)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/PetstoreConsumerTestCore/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import OpenAPIRuntime
import Foundation
import HTTPTypes

/// An error used by Petstore tests.
public enum TestError: Swift.Error, LocalizedError, CustomStringConvertible, Sendable {
case noHandlerFound(method: HTTPRequest.Method, path: String)
case invalidURLString(String)
Expand Down
Loading