@seamapi/nextlove-sdk-generator 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/generate-php-sdk/templates/readme.md.template.js +1 -1
- package/lib/generate-php-sdk/templates/smoke-test.template.js +2 -2
- package/lib/generate-php-sdk/templates/test-fixture.template.js +1 -1
- package/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.js +10 -0
- package/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.js.map +1 -1
- package/lib/generate-php-sdk/utils/generate-resource-object-class.js +9 -7
- package/lib/generate-php-sdk/utils/generate-resource-object-class.js.map +1 -1
- package/lib/types.d.ts +5 -0
- package/package.json +1 -1
- package/src/lib/generate-php-sdk/templates/readme.md.template.ts +1 -1
- package/src/lib/generate-php-sdk/templates/smoke-test.template.ts +2 -2
- package/src/lib/generate-php-sdk/templates/test-fixture.template.ts +1 -1
- package/src/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.ts +10 -0
- package/src/lib/generate-php-sdk/utils/generate-resource-object-class.ts +14 -7
- package/src/lib/types.ts +9 -4
|
@@ -7,7 +7,7 @@ Check out [the documentation](https://docs.seam.co) or the usage below.
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
\`\`\`php
|
|
10
|
-
$seam = new Seam
|
|
10
|
+
$seam = new Seam\\SeamClient("YOUR_API_KEY");
|
|
11
11
|
|
|
12
12
|
# Create a Connect Webview to login to a provider
|
|
13
13
|
$connect_webview = $seam->connect_webviews->create(
|
|
@@ -9,14 +9,14 @@ final class SmokeTest extends TestCase
|
|
|
9
9
|
{
|
|
10
10
|
public function testGetDevices(): void
|
|
11
11
|
{
|
|
12
|
-
$seam = Fixture::
|
|
12
|
+
$seam = Fixture::getTestServer();
|
|
13
13
|
|
|
14
14
|
$devices_response = $seam->devices->list();
|
|
15
15
|
$this->assertIsString($devices_response[0]->device_id);
|
|
16
16
|
}
|
|
17
17
|
public function testCreateAccessCode(): void
|
|
18
18
|
{
|
|
19
|
-
$seam = Fixture::
|
|
19
|
+
$seam = Fixture::getTestServer();
|
|
20
20
|
|
|
21
21
|
$access_code = $seam->access_codes->create(
|
|
22
22
|
device_id:"august_device_1", code:"1234"
|
|
@@ -6,7 +6,7 @@ use Seam\\SeamClient;
|
|
|
6
6
|
|
|
7
7
|
final class Fixture
|
|
8
8
|
{
|
|
9
|
-
public static function
|
|
9
|
+
public static function getTestServer()
|
|
10
10
|
{
|
|
11
11
|
$random_string = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 10);
|
|
12
12
|
$api_url = "https://{$random_string}.fakeseamconnect.seam.vc";
|
|
@@ -28,10 +28,14 @@ export function deepExtractResourceObjectSchemas({ schema_name, schema_body, })
|
|
|
28
28
|
property_schema.type === "array" &&
|
|
29
29
|
"items" in property_schema &&
|
|
30
30
|
"properties" in property_schema.items;
|
|
31
|
+
const is_nullable_set = "nullable" in property_schema;
|
|
31
32
|
if (is_object_schema) {
|
|
32
33
|
property_schemas_with_type_references[property_name] = {
|
|
33
34
|
type: "object",
|
|
34
35
|
reference_object_type_name,
|
|
36
|
+
...(is_nullable_set && {
|
|
37
|
+
nullable: property_schema.nullable,
|
|
38
|
+
}),
|
|
35
39
|
};
|
|
36
40
|
createResourceSchema({
|
|
37
41
|
name: reference_object_type_name,
|
|
@@ -43,6 +47,9 @@ export function deepExtractResourceObjectSchemas({ schema_name, schema_body, })
|
|
|
43
47
|
property_schemas_with_type_references[property_name] = {
|
|
44
48
|
type: "array",
|
|
45
49
|
reference_object_type_name,
|
|
50
|
+
...(is_nullable_set && {
|
|
51
|
+
nullable: property_schema.nullable,
|
|
52
|
+
}),
|
|
46
53
|
};
|
|
47
54
|
createResourceSchema({
|
|
48
55
|
name: reference_object_type_name,
|
|
@@ -72,6 +79,9 @@ export function deepExtractResourceObjectSchemas({ schema_name, schema_body, })
|
|
|
72
79
|
else {
|
|
73
80
|
property_schemas_with_type_references[property_name] = {
|
|
74
81
|
type: property_schema.type,
|
|
82
|
+
...(is_nullable_set && {
|
|
83
|
+
nullable: property_schema.nullable,
|
|
84
|
+
}),
|
|
75
85
|
};
|
|
76
86
|
}
|
|
77
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-extract-resource-object-schemas.js","sourceRoot":"","sources":["../../../src/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA8BxC,MAAM,UAAU,gCAAgC,CAAC,EAC/C,WAAW,EACX,WAAW,GAC4B;IACvC,MAAM,kCAAkC,GAGpC,EAAE,CAAA;IAEN,SAAS,oBAAoB,CAAC,EAC5B,IAAI,EACJ,UAAU,EACV,uBAAuB,GAAG,EAAE,GACD;QAC3B,IAAI,CAAC,kCAAkC,CAAC,IAAI,CAAC,EAAE;YAC7C,kCAAkC,CAAC,IAAI,CAAC,GAAG;gBACzC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;gBACtB,UAAU,EAAE,sBAAsB,CAAC,UAAU,CAAC;gBAC9C,uBAAuB,EAAE,uBAAuB;aACjD,CAAA;SACF;IACH,CAAC;IAED,SAAS,sBAAsB,CAC7B,gBAA0C;QAE1C,MAAM,qCAAqC,GAGvC,EAAE,CAAA;QAEN,KAAK,MAAM,aAAa,IAAI,gBAAgB,EAAE;YAC5C,MAAM,eAAe,GAAG,gBAAgB,CAAC,aAAa,CAAmB,CAAA;YACzE,MAAM,0BAA0B,GAAG,UAAU,CAC3C,GAAG,WAAW,IAAI,aAAa,EAAE,CAClC,CAAA;YACD,IAAI,MAAM,IAAI,eAAe,EAAE;gBAC7B,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAA;gBACrE,SAAQ;aACT;YAED,MAAM,0BAA0B,GAC9B,OAAO,IAAI,eAAe,IAAI,OAAO,IAAI,eAAe,CAAA;YAC1D,MAAM,gBAAgB,GACpB,CAAC,0BAA0B;gBAC3B,eAAe,CAAC,IAAI,KAAK,QAAQ;gBACjC,YAAY,IAAI,eAAe,CAAA;YACjC,MAAM,6BAA6B,GACjC,CAAC,0BAA0B;gBAC3B,eAAe,CAAC,IAAI,KAAK,OAAO;gBAChC,OAAO,IAAI,eAAe;gBAC1B,YAAY,IAAI,eAAe,CAAC,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"deep-extract-resource-object-schemas.js","sourceRoot":"","sources":["../../../src/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA8BxC,MAAM,UAAU,gCAAgC,CAAC,EAC/C,WAAW,EACX,WAAW,GAC4B;IACvC,MAAM,kCAAkC,GAGpC,EAAE,CAAA;IAEN,SAAS,oBAAoB,CAAC,EAC5B,IAAI,EACJ,UAAU,EACV,uBAAuB,GAAG,EAAE,GACD;QAC3B,IAAI,CAAC,kCAAkC,CAAC,IAAI,CAAC,EAAE;YAC7C,kCAAkC,CAAC,IAAI,CAAC,GAAG;gBACzC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;gBACtB,UAAU,EAAE,sBAAsB,CAAC,UAAU,CAAC;gBAC9C,uBAAuB,EAAE,uBAAuB;aACjD,CAAA;SACF;IACH,CAAC;IAED,SAAS,sBAAsB,CAC7B,gBAA0C;QAE1C,MAAM,qCAAqC,GAGvC,EAAE,CAAA;QAEN,KAAK,MAAM,aAAa,IAAI,gBAAgB,EAAE;YAC5C,MAAM,eAAe,GAAG,gBAAgB,CAAC,aAAa,CAAmB,CAAA;YACzE,MAAM,0BAA0B,GAAG,UAAU,CAC3C,GAAG,WAAW,IAAI,aAAa,EAAE,CAClC,CAAA;YACD,IAAI,MAAM,IAAI,eA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EAAE;KACxD,CAAC,CAAA;IAEF,OAAO,kCAAkC,CAAA;AAC3C,CAAC"}
|
|
@@ -7,8 +7,11 @@ export const generateResourceObjectClass = ({ resource_name, resource_properties
|
|
|
7
7
|
const is_array_referencing_resource = "type" in prop_schema &&
|
|
8
8
|
prop_schema.type === "array" &&
|
|
9
9
|
"reference_object_type_name" in prop_schema;
|
|
10
|
+
const is_property_required = "nullable" in prop_schema
|
|
11
|
+
? !prop_schema.nullable
|
|
12
|
+
: required_property_names.includes(prop_name);
|
|
10
13
|
if (is_object_referencing_resource) {
|
|
11
|
-
return `${prop_name}: ${prop_schema.reference_object_type_name}::from_json($json->${prop_name})${
|
|
14
|
+
return `${prop_name}: ${is_property_required ? "" : `isset($json->${prop_name}) ? `}${prop_schema.reference_object_type_name}::from_json($json->${prop_name})${is_property_required ? "," : " : null,"}`;
|
|
12
15
|
}
|
|
13
16
|
else if (is_array_referencing_resource) {
|
|
14
17
|
return `${prop_name}: array_map(
|
|
@@ -17,7 +20,7 @@ export const generateResourceObjectClass = ({ resource_name, resource_properties
|
|
|
17
20
|
),`;
|
|
18
21
|
}
|
|
19
22
|
else {
|
|
20
|
-
return `${prop_name}: $json->${prop_name}${
|
|
23
|
+
return `${prop_name}: $json->${prop_name}${is_property_required ? "," : " ?? null,"}`;
|
|
21
24
|
}
|
|
22
25
|
};
|
|
23
26
|
const generateFromJsonMethod = () => {
|
|
@@ -46,11 +49,10 @@ export const generateResourceObjectClass = ({ resource_name, resource_properties
|
|
|
46
49
|
const php_type = is_object_referencing_resource
|
|
47
50
|
? prop_schema.reference_object_type_name
|
|
48
51
|
: getPhpType("type" in prop_schema ? prop_schema.type : "mixed");
|
|
49
|
-
|
|
50
|
-
?
|
|
51
|
-
: required_property_names.includes(prop_name)
|
|
52
|
-
|
|
53
|
-
: " | null"} $${prop_name},`;
|
|
52
|
+
const is_property_required = "nullable" in prop_schema
|
|
53
|
+
? !prop_schema.nullable
|
|
54
|
+
: required_property_names.includes(prop_name);
|
|
55
|
+
return `public ${php_type}${php_type === "mixed" ? "" : is_property_required ? "" : " | null"} $${prop_name},`;
|
|
54
56
|
})
|
|
55
57
|
.join("\n ")}
|
|
56
58
|
) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-resource-object-class.js","sourceRoot":"","sources":["../../../src/lib/generate-php-sdk/utils/generate-resource-object-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQ9C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,aAAa,EACb,mBAAmB,EACnB,uBAAuB,GAChB,EAAE,EAAE;IACX,MAAM,sBAAsB,GAAG,CAC7B,SAAiB,EACjB,WAA8C,EAC9C,EAAE;QACF,MAAM,8BAA8B,GAClC,MAAM,IAAI,WAAW;YACrB,WAAW,CAAC,IAAI,KAAK,QAAQ;YAC7B,4BAA4B,IAAI,WAAW,CAAA;QAE7C,MAAM,6BAA6B,GACjC,MAAM,IAAI,WAAW;YACrB,WAAW,CAAC,IAAI,KAAK,OAAO;YAC5B,4BAA4B,IAAI,WAAW,CAAA;QAE7C,IAAI,8BAA8B,EAAE;YAClC,OAAO,GAAG,SAAS,KACjB,
|
|
1
|
+
{"version":3,"file":"generate-resource-object-class.js","sourceRoot":"","sources":["../../../src/lib/generate-php-sdk/utils/generate-resource-object-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQ9C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,aAAa,EACb,mBAAmB,EACnB,uBAAuB,GAChB,EAAE,EAAE;IACX,MAAM,sBAAsB,GAAG,CAC7B,SAAiB,EACjB,WAA8C,EAC9C,EAAE;QACF,MAAM,8BAA8B,GAClC,MAAM,IAAI,WAAW;YACrB,WAAW,CAAC,IAAI,KAAK,QAAQ;YAC7B,4BAA4B,IAAI,WAAW,CAAA;QAE7C,MAAM,6BAA6B,GACj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AE,WAAW,CAAC,EAAE,EAAE;YAChC,MAAM,8BAA8B,GAClC,MAAM,IAAI,WAAW;gBACrB,WAAW,CAAC,IAAI,KAAK,QAAQ;gBAC7B,4BAA4B,IAAI,WAAW,CAAA;YAC7C,MAAM,QAAQ,GAAG,8BAA8B;gBAC7C,CAAC,CAAC,WAAW,CAAC,0BAA0B;gBACxC,CAAC,CAAC,UAAU,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;YAClE,MAAM,oBAAoB,GACxB,UAAU,IAAI,WAAW;gBACvB,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ;gBACvB,CAAC,CAAC,uBAAuB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;YAEjD,OAAO,UAAU,QAAQ,GACvB,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAC1D,KAAK,SAAS,GAAG,CAAA;QACnB,CAAC,CAAC;aACD,IAAI,CAAC,YAAY,CAAC;;;GAG1B,CAAA;IACD,CAAC,CAAA;IAED,MAAM,QAAQ,GAAG;;;;QAIX,aAAa;;MAEf,sBAAsB,EAAE;;MAExB,mBAAmB,EAAE;;CAE1B,CAAA;IAEC,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
package/lib/types.d.ts
CHANGED
|
@@ -39,20 +39,25 @@ export type PrimitiveSchema = {
|
|
|
39
39
|
} | {
|
|
40
40
|
type: "boolean";
|
|
41
41
|
enum?: boolean[];
|
|
42
|
+
nullable?: boolean;
|
|
42
43
|
} | {
|
|
43
44
|
type: "integer";
|
|
44
45
|
enum?: number[];
|
|
46
|
+
nullable?: boolean;
|
|
45
47
|
} | {
|
|
46
48
|
type: "number";
|
|
49
|
+
nullable?: boolean;
|
|
47
50
|
};
|
|
48
51
|
export type ArraySchema = {
|
|
49
52
|
type: "array";
|
|
50
53
|
items: PropertySchema;
|
|
54
|
+
nullable?: boolean;
|
|
51
55
|
};
|
|
52
56
|
export type ObjSchema = {
|
|
53
57
|
type: "object";
|
|
54
58
|
properties: Record<string, PropertySchema>;
|
|
55
59
|
required: string[];
|
|
60
|
+
nullable?: boolean;
|
|
56
61
|
};
|
|
57
62
|
export type RefSchema = {
|
|
58
63
|
$ref: string;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ Check out [the documentation](https://docs.seam.co) or the usage below.
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
\`\`\`php
|
|
10
|
-
$seam = new Seam
|
|
10
|
+
$seam = new Seam\\SeamClient("YOUR_API_KEY");
|
|
11
11
|
|
|
12
12
|
# Create a Connect Webview to login to a provider
|
|
13
13
|
$connect_webview = $seam->connect_webviews->create(
|
|
@@ -9,14 +9,14 @@ final class SmokeTest extends TestCase
|
|
|
9
9
|
{
|
|
10
10
|
public function testGetDevices(): void
|
|
11
11
|
{
|
|
12
|
-
$seam = Fixture::
|
|
12
|
+
$seam = Fixture::getTestServer();
|
|
13
13
|
|
|
14
14
|
$devices_response = $seam->devices->list();
|
|
15
15
|
$this->assertIsString($devices_response[0]->device_id);
|
|
16
16
|
}
|
|
17
17
|
public function testCreateAccessCode(): void
|
|
18
18
|
{
|
|
19
|
-
$seam = Fixture::
|
|
19
|
+
$seam = Fixture::getTestServer();
|
|
20
20
|
|
|
21
21
|
$access_code = $seam->access_codes->create(
|
|
22
22
|
device_id:"august_device_1", code:"1234"
|
|
@@ -6,7 +6,7 @@ use Seam\\SeamClient;
|
|
|
6
6
|
|
|
7
7
|
final class Fixture
|
|
8
8
|
{
|
|
9
|
-
public static function
|
|
9
|
+
public static function getTestServer()
|
|
10
10
|
{
|
|
11
11
|
$random_string = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 10);
|
|
12
12
|
$api_url = "https://{$random_string}.fakeseamconnect.seam.vc";
|
|
@@ -82,11 +82,15 @@ export function deepExtractResourceObjectSchemas({
|
|
|
82
82
|
property_schema.type === "array" &&
|
|
83
83
|
"items" in property_schema &&
|
|
84
84
|
"properties" in property_schema.items
|
|
85
|
+
const is_nullable_set = "nullable" in property_schema
|
|
85
86
|
|
|
86
87
|
if (is_object_schema) {
|
|
87
88
|
property_schemas_with_type_references[property_name] = {
|
|
88
89
|
type: "object",
|
|
89
90
|
reference_object_type_name,
|
|
91
|
+
...(is_nullable_set && {
|
|
92
|
+
nullable: property_schema.nullable,
|
|
93
|
+
}),
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
createResourceSchema({
|
|
@@ -98,6 +102,9 @@ export function deepExtractResourceObjectSchemas({
|
|
|
98
102
|
property_schemas_with_type_references[property_name] = {
|
|
99
103
|
type: "array",
|
|
100
104
|
reference_object_type_name,
|
|
105
|
+
...(is_nullable_set && {
|
|
106
|
+
nullable: property_schema.nullable,
|
|
107
|
+
}),
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
createResourceSchema({
|
|
@@ -127,6 +134,9 @@ export function deepExtractResourceObjectSchemas({
|
|
|
127
134
|
} else {
|
|
128
135
|
property_schemas_with_type_references[property_name] = {
|
|
129
136
|
type: property_schema.type as any,
|
|
137
|
+
...(is_nullable_set && {
|
|
138
|
+
nullable: property_schema.nullable,
|
|
139
|
+
}),
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
142
|
}
|
|
@@ -26,11 +26,18 @@ export const generateResourceObjectClass = ({
|
|
|
26
26
|
prop_schema.type === "array" &&
|
|
27
27
|
"reference_object_type_name" in prop_schema
|
|
28
28
|
|
|
29
|
+
const is_property_required =
|
|
30
|
+
"nullable" in prop_schema
|
|
31
|
+
? !prop_schema.nullable
|
|
32
|
+
: required_property_names.includes(prop_name)
|
|
33
|
+
|
|
29
34
|
if (is_object_referencing_resource) {
|
|
30
35
|
return `${prop_name}: ${
|
|
36
|
+
is_property_required ? "" : `isset($json->${prop_name}) ? `
|
|
37
|
+
}${
|
|
31
38
|
prop_schema.reference_object_type_name
|
|
32
39
|
}::from_json($json->${prop_name})${
|
|
33
|
-
|
|
40
|
+
is_property_required ? "," : " : null,"
|
|
34
41
|
}`
|
|
35
42
|
} else if (is_array_referencing_resource) {
|
|
36
43
|
return `${prop_name}: array_map(
|
|
@@ -39,7 +46,7 @@ export const generateResourceObjectClass = ({
|
|
|
39
46
|
),`
|
|
40
47
|
} else {
|
|
41
48
|
return `${prop_name}: $json->${prop_name}${
|
|
42
|
-
|
|
49
|
+
is_property_required ? "," : " ?? null,"
|
|
43
50
|
}`
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -74,13 +81,13 @@ export const generateResourceObjectClass = ({
|
|
|
74
81
|
const php_type = is_object_referencing_resource
|
|
75
82
|
? prop_schema.reference_object_type_name
|
|
76
83
|
: getPhpType("type" in prop_schema ? prop_schema.type : "mixed")
|
|
84
|
+
const is_property_required =
|
|
85
|
+
"nullable" in prop_schema
|
|
86
|
+
? !prop_schema.nullable
|
|
87
|
+
: required_property_names.includes(prop_name)
|
|
77
88
|
|
|
78
89
|
return `public ${php_type}${
|
|
79
|
-
php_type === "mixed"
|
|
80
|
-
? ""
|
|
81
|
-
: required_property_names.includes(prop_name)
|
|
82
|
-
? ""
|
|
83
|
-
: " | null"
|
|
90
|
+
php_type === "mixed" ? "" : is_property_required ? "" : " | null"
|
|
84
91
|
} $${prop_name},`
|
|
85
92
|
})
|
|
86
93
|
.join("\n ")}
|
package/src/lib/types.ts
CHANGED
|
@@ -43,16 +43,21 @@ export type PrimitiveSchema =
|
|
|
43
43
|
format?: "uuid" | "date-time" | "uri"
|
|
44
44
|
nullable?: boolean
|
|
45
45
|
}
|
|
46
|
-
| { type: "boolean"; enum?: boolean[] }
|
|
47
|
-
| { type: "integer"; enum?: number[] }
|
|
48
|
-
| { type: "number" }
|
|
46
|
+
| { type: "boolean"; enum?: boolean[]; nullable?: boolean }
|
|
47
|
+
| { type: "integer"; enum?: number[]; nullable?: boolean }
|
|
48
|
+
| { type: "number"; nullable?: boolean }
|
|
49
49
|
|
|
50
|
-
export type ArraySchema = {
|
|
50
|
+
export type ArraySchema = {
|
|
51
|
+
type: "array"
|
|
52
|
+
items: PropertySchema
|
|
53
|
+
nullable?: boolean
|
|
54
|
+
}
|
|
51
55
|
|
|
52
56
|
export type ObjSchema = {
|
|
53
57
|
type: "object"
|
|
54
58
|
properties: Record<string, PropertySchema>
|
|
55
59
|
required: string[]
|
|
60
|
+
nullable?: boolean
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
export type RefSchema = {
|