Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use builtin UUID type for uuid format in schemas #11

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

PhilipTrauner
Copy link
Contributor

Formats such as "email", "uuid", and so on, MAY be used even though undefined by this specification.
Specification

The builtin UUID type is already Codable, so unless I'm missing something this should just work.

import Foundation

struct Model: Codable {
    let id: UUID
}

let json = """
{
    "id": "f44d74e7-a8ca-4d5d-9d7d-6b28fc28b552"
}
"""

let decoder = JSONDecoder()
let decoded = try! decoder.decode(Model.self, from: json.data(using: .utf8)!)

let encoder = JSONEncoder()
let encodedData = try! encoder.encode(decoded)
let encodedString = String(data: encodedData, encoding: .utf8)

@kean
Copy link
Member

kean commented Jan 28, 2022

Looks good, thanks @PhilipTrauner. I'll review the other MR later today too.

@kean kean merged commit 734a8e7 into CreateAPI:main Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants