forked from dylanshine/openai-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonSchema.swift
63 lines (55 loc) · 1.31 KB
/
JsonSchema.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// JsonSchema.swift
//
//
// Created by Peter Liddle on 8/27/24.
//
import Foundation
// Define the top-level JSON schema struct
struct JsonSchema: Codable {
let schema: String
let type: String
let items: Items
enum CodingKeys: String, CodingKey {
case schema = "$schema"
case type
case items
}
}
// Define the Items struct
struct Items: Codable {
let type: String
let properties: Properties
let required: [String]
let additionalProperties: Bool
}
// Define the Properties struct
struct Properties: Codable {
let id: PropertyType
let context: PropertyType
}
// Define the PropertyType struct
struct PropertyType: Codable {
let type: String
}
//// Example usage
//let jsonSchema = JSONSchema(
// schema: "http://json-schema.org/draft-07/schema#",
// type: "array",
// items: Items(
// type: "object",
// properties: Properties(
// id: PropertyType(type: "string"),
// context: PropertyType(type: "string")
// ),
// required: ["id", "context"],
// additionalProperties: false
// )
//)
//
//// Encode the JSONSchema instance to JSON
//if let jsonData = try? JSONEncoder().encode(jsonSchema),
// let jsonString = String(data: jsonData, encoding: .utf8) {
// print(jsonString)
//}
//