@goast/core 0.7.0 → 0.7.1
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/dist/src/ast/node.d.ts +43 -0
- package/dist/src/ast/node.js +29 -0
- package/dist/src/codegen/config.d.ts +9 -0
- package/dist/src/codegen/config.js +4 -0
- package/dist/src/codegen/endpoints-generator.d.ts +32 -0
- package/dist/src/codegen/endpoints-generator.js +19 -0
- package/dist/src/codegen/generator.d.ts +108 -0
- package/dist/src/codegen/generator.js +103 -0
- package/dist/src/codegen/internal-utils.d.ts +8 -0
- package/dist/src/codegen/internal-utils.js +8 -0
- package/dist/src/codegen/schemas-generator.d.ts +33 -0
- package/dist/src/codegen/schemas-generator.js +20 -0
- package/dist/src/codegen/services-generator.d.ts +24 -0
- package/dist/src/codegen/services-generator.js +11 -0
- package/dist/src/codegen/types.d.ts +56 -0
- package/dist/src/collect/collector.d.ts +8 -0
- package/dist/src/collect/collector.js +8 -0
- package/dist/src/collect/helpers.d.ts +16 -0
- package/dist/src/collect/helpers.js +16 -0
- package/dist/src/collect/types.d.ts +28 -0
- package/dist/src/internal-utils.d.ts +7 -0
- package/dist/src/internal-utils.js +7 -0
- package/dist/src/parse/deref-proxy.d.ts +19 -0
- package/dist/src/parse/deref-proxy.js +19 -0
- package/dist/src/parse/openapi-types.d.ts +168 -0
- package/dist/src/parse/parser.d.ts +38 -0
- package/dist/src/parse/parser.js +38 -0
- package/dist/src/parse/types.d.ts +37 -0
- package/dist/src/parse/types.js +4 -0
- package/dist/src/transform/api-types.d.ts +408 -0
- package/dist/src/transform/helpers.d.ts +73 -0
- package/dist/src/transform/helpers.js +73 -0
- package/dist/src/transform/transform-document.d.ts +7 -0
- package/dist/src/transform/transform-document.js +7 -0
- package/dist/src/transform/transform-endpoint.d.ts +8 -0
- package/dist/src/transform/transform-endpoint.js +8 -0
- package/dist/src/transform/transform-schema.d.ts +10 -0
- package/dist/src/transform/transform-schema.js +10 -0
- package/dist/src/transform/transformer.d.ts +7 -0
- package/dist/src/transform/transformer.js +7 -0
- package/dist/src/transform/types.d.ts +61 -0
- package/dist/src/transform/types.js +4 -0
- package/dist/src/utils/action-provider.d.ts +38 -0
- package/dist/src/utils/action-provider.js +38 -0
- package/dist/src/utils/api-data.utils.d.ts +9 -0
- package/dist/src/utils/api-data.utils.js +9 -0
- package/dist/src/utils/array.utils.d.ts +7 -0
- package/dist/src/utils/array.utils.js +7 -0
- package/dist/src/utils/asset-manager.d.ts +22 -0
- package/dist/src/utils/asset-manager.js +22 -0
- package/dist/src/utils/class.utils.d.ts +22 -0
- package/dist/src/utils/class.utils.js +22 -0
- package/dist/src/utils/common.utils.d.ts +81 -0
- package/dist/src/utils/common.utils.js +81 -0
- package/dist/src/utils/condition.d.ts +22 -0
- package/dist/src/utils/endpoint.utils.d.ts +12 -0
- package/dist/src/utils/endpoint.utils.js +12 -0
- package/dist/src/utils/error.utils.d.ts +6 -0
- package/dist/src/utils/error.utils.js +6 -0
- package/dist/src/utils/factory.d.ts +45 -0
- package/dist/src/utils/factory.js +45 -0
- package/dist/src/utils/file-system.utils.d.ts +37 -0
- package/dist/src/utils/file-system.utils.js +20 -0
- package/dist/src/utils/generator.utils.d.ts +7 -0
- package/dist/src/utils/generator.utils.js +7 -0
- package/dist/src/utils/object.utils.d.ts +16 -0
- package/dist/src/utils/object.utils.js +16 -0
- package/dist/src/utils/schema-factory.d.ts +197 -0
- package/dist/src/utils/schema-factory.js +146 -0
- package/dist/src/utils/schema.utils.d.ts +15 -0
- package/dist/src/utils/schema.utils.js +15 -0
- package/dist/src/utils/source-builder.d.ts +103 -0
- package/dist/src/utils/source-builder.js +58 -0
- package/dist/src/utils/string-builder/string-builder.d.ts +24 -0
- package/dist/src/utils/string-builder/string-builder.js +11 -0
- package/dist/src/utils/string-builder/utils.d.ts +68 -0
- package/dist/src/utils/string-builder/utils.js +33 -0
- package/dist/src/utils/string.utils.d.ts +78 -0
- package/dist/src/utils/string.utils.js +64 -0
- package/dist/src/utils/string.utils.types.d.ts +34 -0
- package/dist/src/utils/type.utils.d.ts +132 -0
- package/dist/src/utils/type.utils.js +19 -0
- package/dist/src/utils/yaml-info.d.ts +35 -0
- package/dist/src/utils/yaml-info.js +25 -0
- package/package.json +1 -1
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the specified value if it has been initialized. Throws an error if the value is `undefined`, which is used as
|
|
3
|
+
* the marker for a generator field that has not been set yet. Other values, including `null`, are returned as-is.
|
|
4
|
+
* @template T The type of the value.
|
|
5
|
+
* @param value The value to check.
|
|
6
|
+
* @returns The initialized value.
|
|
7
|
+
*/
|
|
1
8
|
export declare function getInitializedValue<T>(value: T | undefined): T;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the specified value if it has been initialized. Throws an error if the value is `undefined`, which is used as
|
|
3
|
+
* the marker for a generator field that has not been set yet. Other values, including `null`, are returned as-is.
|
|
4
|
+
* @template T The type of the value.
|
|
5
|
+
* @param value The value to check.
|
|
6
|
+
* @returns The initialized value.
|
|
7
|
+
*/
|
|
1
8
|
export function getInitializedValue(value) {
|
|
2
9
|
if (value === undefined) {
|
|
3
10
|
throw new Error('Generator not initialized.');
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a proxy around an object whose property writes are stored separately, so the target is never modified.
|
|
3
|
+
* A read returns the written value, unless it is nullish. In that case the value of the target is returned.
|
|
4
|
+
* Only property reads and writes are intercepted. Other operations, such as `in` or `Object.keys`, use the target.
|
|
5
|
+
* @template T The type of the object.
|
|
6
|
+
* @param target The object to wrap.
|
|
7
|
+
* @param values The properties to write to the proxy right away.
|
|
8
|
+
* @returns A proxy that behaves like the target with the written values overriding it.
|
|
9
|
+
*/
|
|
1
10
|
export declare function createOverwriteProxy<T extends object>(target: T, values?: Partial<T>): T;
|
|
11
|
+
/**
|
|
12
|
+
* Gets a nested property by following a path of keys.
|
|
13
|
+
* @param obj The object to read from.
|
|
14
|
+
* @param path The keys to follow, one per level. An empty path returns `obj` itself.
|
|
15
|
+
* @returns The value at the end of the path, or `undefined` if a value along the way is not an object, for example a
|
|
16
|
+
* primitive, `null` or a function, or if a key does not exist.
|
|
17
|
+
*/
|
|
2
18
|
export declare function getDeepProperty(obj: object, path: string[]): unknown;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a proxy around an object whose property writes are stored separately, so the target is never modified.
|
|
3
|
+
* A read returns the written value, unless it is nullish. In that case the value of the target is returned.
|
|
4
|
+
* Only property reads and writes are intercepted. Other operations, such as `in` or `Object.keys`, use the target.
|
|
5
|
+
* @template T The type of the object.
|
|
6
|
+
* @param target The object to wrap.
|
|
7
|
+
* @param values The properties to write to the proxy right away.
|
|
8
|
+
* @returns A proxy that behaves like the target with the written values overriding it.
|
|
9
|
+
*/
|
|
1
10
|
export function createOverwriteProxy(target, values) {
|
|
2
11
|
const proxy = new Proxy(target, new OverwriteProxyHandler());
|
|
3
12
|
if (values) {
|
|
@@ -5,6 +14,13 @@ export function createOverwriteProxy(target, values) {
|
|
|
5
14
|
}
|
|
6
15
|
return proxy;
|
|
7
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets a nested property by following a path of keys.
|
|
19
|
+
* @param obj The object to read from.
|
|
20
|
+
* @param path The keys to follow, one per level. An empty path returns `obj` itself.
|
|
21
|
+
* @returns The value at the end of the path, or `undefined` if a value along the way is not an object, for example a
|
|
22
|
+
* primitive, `null` or a function, or if a key does not exist.
|
|
23
|
+
*/
|
|
8
24
|
export function getDeepProperty(obj, path) {
|
|
9
25
|
let current = obj;
|
|
10
26
|
for (const key of path) {
|
|
@@ -1,41 +1,238 @@
|
|
|
1
1
|
import type { ApiSchema, ApiSchemaBase, ApiSchemaComponent, ApiSchemaExtensions, ApiSchemaProperty } from '../transform/api-types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Base arguments accepted by every `create*Schema` and `create*Property` helper in this file. `required` is a list of
|
|
4
|
+
* property names that the helpers turn into a `Set`. A missing `name` is generated as `schema-<n>`, `id` defaults to
|
|
5
|
+
* the name, and `isNameGenerated` defaults to whether an `id` was given.
|
|
6
|
+
*/
|
|
2
7
|
export type TestSchema = Partial<Omit<ApiSchemaBase, 'required'>> & Partial<ApiSchemaComponent> & {
|
|
3
8
|
required?: string[];
|
|
4
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Arguments for `createOneOfSchema`: the base fields plus the `oneOf` branches to choose from.
|
|
12
|
+
* @see createOneOfSchema
|
|
13
|
+
*/
|
|
5
14
|
export type TestOneofSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'oneOf'>, 'kind'>>;
|
|
15
|
+
/**
|
|
16
|
+
* Arguments for `createMultiTypeSchema`: the base fields, the `type` list, `properties` as a list of properties, and
|
|
17
|
+
* the keywords of the array, object, number and string kinds, since a `multi-type` schema can carry all of them.
|
|
18
|
+
* @see createMultiTypeSchema
|
|
19
|
+
*/
|
|
6
20
|
export type TestMultiTypeSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'multi-type'>, 'kind' | 'properties'>> & {
|
|
7
21
|
properties?: ApiSchemaProperty[];
|
|
8
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Arguments for `createStringSchema`: the base fields plus `pattern`, `minLength`, `maxLength` and `format`.
|
|
25
|
+
* @see createStringSchema
|
|
26
|
+
*/
|
|
9
27
|
export type TestStringSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'string'>, 'kind' | 'type'>>;
|
|
28
|
+
/**
|
|
29
|
+
* Arguments for `createBooleanSchema`: the base fields plus `format`.
|
|
30
|
+
* @see createBooleanSchema
|
|
31
|
+
*/
|
|
10
32
|
export type TestBooleanSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'boolean'>, 'kind' | 'type'>>;
|
|
33
|
+
/**
|
|
34
|
+
* Arguments for `createNullSchema`. A `null` schema has no keywords beyond the base fields.
|
|
35
|
+
* @see createNullSchema
|
|
36
|
+
*/
|
|
11
37
|
export type TestNullSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'null'>, 'kind' | 'type'>>;
|
|
38
|
+
/**
|
|
39
|
+
* Arguments for `createNumberSchema`: the base fields plus `minimum`, `maximum` and `format`.
|
|
40
|
+
* @see createNumberSchema
|
|
41
|
+
*/
|
|
12
42
|
export type TestNumberSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'number'>, 'kind' | 'type'>>;
|
|
43
|
+
/**
|
|
44
|
+
* Arguments for `createIntegerSchema`: the same fields as `createNumberSchema`.
|
|
45
|
+
* @see createIntegerSchema
|
|
46
|
+
*/
|
|
13
47
|
export type TestIntegerSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'integer'>, 'kind' | 'type'>>;
|
|
48
|
+
/**
|
|
49
|
+
* Arguments for `createArraySchema`: the base fields plus `items`, `minItems` and `maxItems`.
|
|
50
|
+
* @see createArraySchema
|
|
51
|
+
*/
|
|
14
52
|
export type TestArraySchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'array'>, 'kind' | 'type'>>;
|
|
53
|
+
/**
|
|
54
|
+
* Arguments for `createObjectSchema`: the base fields plus `properties` as a list, `additionalProperties`, and the
|
|
55
|
+
* `allOf` and `anyOf` branches.
|
|
56
|
+
* @see createObjectSchema
|
|
57
|
+
*/
|
|
15
58
|
export type TestObjectSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'object'>, 'kind' | 'type' | 'properties'>> & {
|
|
16
59
|
properties?: ApiSchemaProperty[];
|
|
17
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Arguments for `createCombinedSchema`: the base fields plus the `allOf` and `anyOf` branches.
|
|
63
|
+
* @see createCombinedSchema
|
|
64
|
+
*/
|
|
18
65
|
export type TestCombinedSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'combined'>, 'kind'>>;
|
|
66
|
+
/**
|
|
67
|
+
* Arguments for `createUnknownSchema`. An `unknown` schema has no keywords beyond the base fields.
|
|
68
|
+
* @see createUnknownSchema
|
|
69
|
+
*/
|
|
19
70
|
export type TestUnknownSchema = TestSchema & Partial<Omit<ApiSchemaExtensions<'unknown'>, 'kind'>>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a `oneOf` schema (kind `'oneOf'`) that matches exactly one of its `oneOf` branches. The branches default to
|
|
73
|
+
* an empty list.
|
|
74
|
+
* @param schema The base fields and the `oneOf` branches of the schema.
|
|
75
|
+
* @returns A `oneOf` schema with the given fields.
|
|
76
|
+
*/
|
|
20
77
|
export declare function createOneOfSchema(schema?: TestOneofSchema): ApiSchema<'oneOf'>;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a `multi-type` schema (kind `'multi-type'`) for a schema whose `type` lists several types. `type`, `allOf`
|
|
80
|
+
* and `anyOf` default to empty lists, and `properties` is converted into a map keyed by property name.
|
|
81
|
+
* @param schema The base fields and the keywords of the schema.
|
|
82
|
+
* @returns A `multi-type` schema with the given fields.
|
|
83
|
+
*/
|
|
21
84
|
export declare function createMultiTypeSchema(schema?: TestMultiTypeSchema): ApiSchema<'multi-type'>;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a `string` schema (kind and type `'string'`). Only the base fields and the `pattern`, `minLength`,
|
|
87
|
+
* `maxLength` and `format` keywords are read from the argument.
|
|
88
|
+
* @param schema The base fields and the string keywords of the schema.
|
|
89
|
+
* @returns A `string` schema with the given fields.
|
|
90
|
+
*/
|
|
22
91
|
export declare function createStringSchema(schema?: TestStringSchema): ApiSchema<'string'>;
|
|
92
|
+
/**
|
|
93
|
+
* Creates a `boolean` schema (kind and type `'boolean'`). Only the base fields and `format` are read from the argument.
|
|
94
|
+
* @param schema The base fields and the `format` of the schema.
|
|
95
|
+
* @returns A `boolean` schema with the given fields.
|
|
96
|
+
*/
|
|
23
97
|
export declare function createBooleanSchema(schema?: TestBooleanSchema): ApiSchema<'boolean'>;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a `null` schema (kind and type `'null'`). Since `null` has no keywords, only the base fields are read from
|
|
100
|
+
* the argument.
|
|
101
|
+
* @param schema The base fields of the schema.
|
|
102
|
+
* @returns A `null` schema with the given fields.
|
|
103
|
+
*/
|
|
24
104
|
export declare function createNullSchema(schema?: TestNullSchema): ApiSchema<'null'>;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a `number` schema (kind and type `'number'`) for any numeric value, fractions included. Only the base fields
|
|
107
|
+
* and the `minimum`, `maximum` and `format` keywords are read from the argument.
|
|
108
|
+
* @param schema The base fields and the numeric keywords of the schema.
|
|
109
|
+
* @returns A `number` schema with the given fields.
|
|
110
|
+
* @see createIntegerSchema
|
|
111
|
+
*/
|
|
25
112
|
export declare function createNumberSchema(schema?: TestNumberSchema): ApiSchema<'number'>;
|
|
113
|
+
/**
|
|
114
|
+
* Creates an `integer` schema (kind and type `'integer'`) for whole numbers. It reads the same keywords as
|
|
115
|
+
* {@link createNumberSchema}: `minimum`, `maximum` and `format`.
|
|
116
|
+
* @param schema The base fields and the numeric keywords of the schema.
|
|
117
|
+
* @returns An `integer` schema with the given fields.
|
|
118
|
+
* @see createNumberSchema
|
|
119
|
+
*/
|
|
26
120
|
export declare function createIntegerSchema(schema?: TestIntegerSchema): ApiSchema<'integer'>;
|
|
121
|
+
/**
|
|
122
|
+
* Creates an `array` schema (kind and type `'array'`). `items` is taken as given, so leaving it out leaves the elements
|
|
123
|
+
* unconstrained, and `minItems` and `maxItems` are read from the argument.
|
|
124
|
+
* @param schema The base fields and the array keywords of the schema.
|
|
125
|
+
* @returns An `array` schema with the given fields.
|
|
126
|
+
*/
|
|
27
127
|
export declare function createArraySchema(schema?: TestArraySchema): ApiSchema<'array'>;
|
|
128
|
+
/**
|
|
129
|
+
* Creates an `object` schema (kind and type `'object'`). `properties` is turned into a map keyed by property name,
|
|
130
|
+
* where a later property with the same name replaces an earlier one. `allOf` and `anyOf` default to empty lists.
|
|
131
|
+
* @param schema The base fields, properties and branches of the schema.
|
|
132
|
+
* @returns An `object` schema with the given fields.
|
|
133
|
+
*/
|
|
28
134
|
export declare function createObjectSchema(schema?: TestObjectSchema): ApiSchema<'object'>;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a `combined` schema (kind `'combined'`, with no `type`) composed of its `allOf` and `anyOf` branches. Both
|
|
137
|
+
* branch lists default to empty.
|
|
138
|
+
* @param schema The base fields and the branches of the schema.
|
|
139
|
+
* @returns A `combined` schema with the given fields.
|
|
140
|
+
*/
|
|
29
141
|
export declare function createCombinedSchema(schema?: TestCombinedSchema): ApiSchema<'combined'>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates an `unknown` schema (kind `'unknown'`), which has no kind-specific keywords. Only the base fields are read
|
|
144
|
+
* from the argument.
|
|
145
|
+
* @param schema The base fields of the schema.
|
|
146
|
+
* @returns An `unknown` schema with the given fields.
|
|
147
|
+
*/
|
|
30
148
|
export declare function createUnknownSchema(schema?: TestUnknownSchema): ApiSchema<'unknown'>;
|
|
149
|
+
/**
|
|
150
|
+
* Creates a property whose schema is a `oneOf` schema with the branches given in `schema.oneOf`.
|
|
151
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
152
|
+
* @param schema The arguments of the `oneOf` schema, as for {@link createOneOfSchema}.
|
|
153
|
+
* @returns The property with the given name and a `oneOf` schema.
|
|
154
|
+
* @see createOneOfSchema
|
|
155
|
+
*/
|
|
31
156
|
export declare function createOneOfProperty(name: string, schema?: TestOneofSchema): ApiSchemaProperty;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a property whose schema is a `multi-type` schema with the `type` list and keywords given in `schema`.
|
|
159
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
160
|
+
* @param schema The arguments of the `multi-type` schema, as for {@link createMultiTypeSchema}.
|
|
161
|
+
* @returns The property with the given name and a `multi-type` schema.
|
|
162
|
+
* @see createMultiTypeSchema
|
|
163
|
+
*/
|
|
32
164
|
export declare function createMultiTypeProperty(name: string, schema?: TestMultiTypeSchema): ApiSchemaProperty;
|
|
165
|
+
/**
|
|
166
|
+
* Creates a property whose schema is a `string` schema with `pattern`, `minLength`, `maxLength` and `format` taken
|
|
167
|
+
* from `schema`.
|
|
168
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
169
|
+
* @param schema The arguments of the `string` schema, as for {@link createStringSchema}.
|
|
170
|
+
* @returns The property with the given name and a `string` schema.
|
|
171
|
+
* @see createStringSchema
|
|
172
|
+
*/
|
|
33
173
|
export declare function createStringProperty(name: string, schema?: TestStringSchema): ApiSchemaProperty;
|
|
174
|
+
/**
|
|
175
|
+
* Creates a property whose schema is a `boolean` schema. Only the base fields and `format` of `schema` apply.
|
|
176
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
177
|
+
* @param schema The arguments of the `boolean` schema, as for {@link createBooleanSchema}.
|
|
178
|
+
* @returns The property with the given name and a `boolean` schema.
|
|
179
|
+
* @see createBooleanSchema
|
|
180
|
+
*/
|
|
34
181
|
export declare function createBooleanProperty(name: string, schema?: TestBooleanSchema): ApiSchemaProperty;
|
|
182
|
+
/**
|
|
183
|
+
* Creates a property whose schema is a `null` schema. Only the base fields of `schema` apply.
|
|
184
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
185
|
+
* @param schema The arguments of the `null` schema, as for {@link createNullSchema}.
|
|
186
|
+
* @returns The property with the given name and a `null` schema.
|
|
187
|
+
* @see createNullSchema
|
|
188
|
+
*/
|
|
35
189
|
export declare function createNullProperty(name: string, schema?: TestNullSchema): ApiSchemaProperty;
|
|
190
|
+
/**
|
|
191
|
+
* Creates a property whose schema is a `number` schema with `minimum`, `maximum` and `format` taken from `schema`.
|
|
192
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
193
|
+
* @param schema The arguments of the `number` schema, as for {@link createNumberSchema}.
|
|
194
|
+
* @returns The property with the given name and a `number` schema.
|
|
195
|
+
* @see createNumberSchema
|
|
196
|
+
*/
|
|
36
197
|
export declare function createNumberProperty(name: string, schema?: TestNumberSchema): ApiSchemaProperty;
|
|
198
|
+
/**
|
|
199
|
+
* Creates a property whose schema is an `integer` schema with `minimum`, `maximum` and `format` taken from `schema`.
|
|
200
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
201
|
+
* @param schema The arguments of the `integer` schema, as for {@link createIntegerSchema}.
|
|
202
|
+
* @returns The property with the given name and an `integer` schema.
|
|
203
|
+
* @see createIntegerSchema
|
|
204
|
+
*/
|
|
37
205
|
export declare function createIntegerProperty(name: string, schema?: TestIntegerSchema): ApiSchemaProperty;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a property whose schema is an `array` schema with `items`, `minItems` and `maxItems` taken from `schema`.
|
|
208
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
209
|
+
* @param schema The arguments of the `array` schema, as for {@link createArraySchema}.
|
|
210
|
+
* @returns The property with the given name and an `array` schema.
|
|
211
|
+
* @see createArraySchema
|
|
212
|
+
*/
|
|
38
213
|
export declare function createArrayProperty(name: string, schema?: TestArraySchema): ApiSchemaProperty;
|
|
214
|
+
/**
|
|
215
|
+
* Creates a property whose schema is an `object` schema with `properties`, `additionalProperties`, `allOf` and `anyOf`
|
|
216
|
+
* taken from `schema`.
|
|
217
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
218
|
+
* @param schema The arguments of the `object` schema, as for {@link createObjectSchema}.
|
|
219
|
+
* @returns The property with the given name and an `object` schema.
|
|
220
|
+
* @see createObjectSchema
|
|
221
|
+
*/
|
|
39
222
|
export declare function createObjectProperty(name: string, schema?: TestObjectSchema): ApiSchemaProperty;
|
|
223
|
+
/**
|
|
224
|
+
* Creates a property whose schema is a `combined` schema composed of the `allOf` and `anyOf` branches in `schema`.
|
|
225
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
226
|
+
* @param schema The arguments of the `combined` schema, as for {@link createCombinedSchema}.
|
|
227
|
+
* @returns The property with the given name and a `combined` schema.
|
|
228
|
+
* @see createCombinedSchema
|
|
229
|
+
*/
|
|
40
230
|
export declare function createCombinedProperty(name: string, schema?: TestCombinedSchema): ApiSchemaProperty;
|
|
231
|
+
/**
|
|
232
|
+
* Creates a property whose schema is an `unknown` schema, which carries only the base fields of `schema`.
|
|
233
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
234
|
+
* @param schema The arguments of the `unknown` schema, as for {@link createUnknownSchema}.
|
|
235
|
+
* @returns The property with the given name and an `unknown` schema.
|
|
236
|
+
* @see createUnknownSchema
|
|
237
|
+
*/
|
|
41
238
|
export declare function createUnknownProperty(name: string, schema?: TestUnknownSchema): ApiSchemaProperty;
|
|
@@ -13,6 +13,12 @@ function createSchemaBase(schema) {
|
|
|
13
13
|
custom: {},
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a `oneOf` schema (kind `'oneOf'`) that matches exactly one of its `oneOf` branches. The branches default to
|
|
18
|
+
* an empty list.
|
|
19
|
+
* @param schema The base fields and the `oneOf` branches of the schema.
|
|
20
|
+
* @returns A `oneOf` schema with the given fields.
|
|
21
|
+
*/
|
|
16
22
|
export function createOneOfSchema(schema = {}) {
|
|
17
23
|
return {
|
|
18
24
|
...createSchemaBase(schema),
|
|
@@ -20,6 +26,12 @@ export function createOneOfSchema(schema = {}) {
|
|
|
20
26
|
oneOf: schema.oneOf ?? [],
|
|
21
27
|
};
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a `multi-type` schema (kind `'multi-type'`) for a schema whose `type` lists several types. `type`, `allOf`
|
|
31
|
+
* and `anyOf` default to empty lists, and `properties` is converted into a map keyed by property name.
|
|
32
|
+
* @param schema The base fields and the keywords of the schema.
|
|
33
|
+
* @returns A `multi-type` schema with the given fields.
|
|
34
|
+
*/
|
|
23
35
|
export function createMultiTypeSchema(schema = {}) {
|
|
24
36
|
return {
|
|
25
37
|
...createSchemaBase(schema),
|
|
@@ -30,6 +42,12 @@ export function createMultiTypeSchema(schema = {}) {
|
|
|
30
42
|
anyOf: schema.anyOf ?? [],
|
|
31
43
|
};
|
|
32
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a `string` schema (kind and type `'string'`). Only the base fields and the `pattern`, `minLength`,
|
|
47
|
+
* `maxLength` and `format` keywords are read from the argument.
|
|
48
|
+
* @param schema The base fields and the string keywords of the schema.
|
|
49
|
+
* @returns A `string` schema with the given fields.
|
|
50
|
+
*/
|
|
33
51
|
export function createStringSchema(schema = {}) {
|
|
34
52
|
return {
|
|
35
53
|
...createSchemaBase(schema),
|
|
@@ -37,6 +55,11 @@ export function createStringSchema(schema = {}) {
|
|
|
37
55
|
type: 'string',
|
|
38
56
|
};
|
|
39
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a `boolean` schema (kind and type `'boolean'`). Only the base fields and `format` are read from the argument.
|
|
60
|
+
* @param schema The base fields and the `format` of the schema.
|
|
61
|
+
* @returns A `boolean` schema with the given fields.
|
|
62
|
+
*/
|
|
40
63
|
export function createBooleanSchema(schema = {}) {
|
|
41
64
|
return {
|
|
42
65
|
...createSchemaBase(schema),
|
|
@@ -44,6 +67,12 @@ export function createBooleanSchema(schema = {}) {
|
|
|
44
67
|
type: 'boolean',
|
|
45
68
|
};
|
|
46
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a `null` schema (kind and type `'null'`). Since `null` has no keywords, only the base fields are read from
|
|
72
|
+
* the argument.
|
|
73
|
+
* @param schema The base fields of the schema.
|
|
74
|
+
* @returns A `null` schema with the given fields.
|
|
75
|
+
*/
|
|
47
76
|
export function createNullSchema(schema = {}) {
|
|
48
77
|
return {
|
|
49
78
|
...createSchemaBase(schema),
|
|
@@ -51,6 +80,13 @@ export function createNullSchema(schema = {}) {
|
|
|
51
80
|
type: 'null',
|
|
52
81
|
};
|
|
53
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a `number` schema (kind and type `'number'`) for any numeric value, fractions included. Only the base fields
|
|
85
|
+
* and the `minimum`, `maximum` and `format` keywords are read from the argument.
|
|
86
|
+
* @param schema The base fields and the numeric keywords of the schema.
|
|
87
|
+
* @returns A `number` schema with the given fields.
|
|
88
|
+
* @see createIntegerSchema
|
|
89
|
+
*/
|
|
54
90
|
export function createNumberSchema(schema = {}) {
|
|
55
91
|
return {
|
|
56
92
|
...createSchemaBase(schema),
|
|
@@ -58,6 +94,13 @@ export function createNumberSchema(schema = {}) {
|
|
|
58
94
|
type: 'number',
|
|
59
95
|
};
|
|
60
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates an `integer` schema (kind and type `'integer'`) for whole numbers. It reads the same keywords as
|
|
99
|
+
* {@link createNumberSchema}: `minimum`, `maximum` and `format`.
|
|
100
|
+
* @param schema The base fields and the numeric keywords of the schema.
|
|
101
|
+
* @returns An `integer` schema with the given fields.
|
|
102
|
+
* @see createNumberSchema
|
|
103
|
+
*/
|
|
61
104
|
export function createIntegerSchema(schema = {}) {
|
|
62
105
|
return {
|
|
63
106
|
...createSchemaBase(schema),
|
|
@@ -65,6 +108,12 @@ export function createIntegerSchema(schema = {}) {
|
|
|
65
108
|
type: 'integer',
|
|
66
109
|
};
|
|
67
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates an `array` schema (kind and type `'array'`). `items` is taken as given, so leaving it out leaves the elements
|
|
113
|
+
* unconstrained, and `minItems` and `maxItems` are read from the argument.
|
|
114
|
+
* @param schema The base fields and the array keywords of the schema.
|
|
115
|
+
* @returns An `array` schema with the given fields.
|
|
116
|
+
*/
|
|
68
117
|
export function createArraySchema(schema = {}) {
|
|
69
118
|
return {
|
|
70
119
|
...createSchemaBase(schema),
|
|
@@ -73,6 +122,12 @@ export function createArraySchema(schema = {}) {
|
|
|
73
122
|
items: schema.items ?? undefined,
|
|
74
123
|
};
|
|
75
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates an `object` schema (kind and type `'object'`). `properties` is turned into a map keyed by property name,
|
|
127
|
+
* where a later property with the same name replaces an earlier one. `allOf` and `anyOf` default to empty lists.
|
|
128
|
+
* @param schema The base fields, properties and branches of the schema.
|
|
129
|
+
* @returns An `object` schema with the given fields.
|
|
130
|
+
*/
|
|
76
131
|
export function createObjectSchema(schema = {}) {
|
|
77
132
|
return {
|
|
78
133
|
...createSchemaBase(schema),
|
|
@@ -83,6 +138,12 @@ export function createObjectSchema(schema = {}) {
|
|
|
83
138
|
anyOf: schema.anyOf ?? [],
|
|
84
139
|
};
|
|
85
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a `combined` schema (kind `'combined'`, with no `type`) composed of its `allOf` and `anyOf` branches. Both
|
|
143
|
+
* branch lists default to empty.
|
|
144
|
+
* @param schema The base fields and the branches of the schema.
|
|
145
|
+
* @returns A `combined` schema with the given fields.
|
|
146
|
+
*/
|
|
86
147
|
export function createCombinedSchema(schema = {}) {
|
|
87
148
|
return {
|
|
88
149
|
...createSchemaBase(schema),
|
|
@@ -91,42 +152,127 @@ export function createCombinedSchema(schema = {}) {
|
|
|
91
152
|
anyOf: schema.anyOf ?? [],
|
|
92
153
|
};
|
|
93
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates an `unknown` schema (kind `'unknown'`), which has no kind-specific keywords. Only the base fields are read
|
|
157
|
+
* from the argument.
|
|
158
|
+
* @param schema The base fields of the schema.
|
|
159
|
+
* @returns An `unknown` schema with the given fields.
|
|
160
|
+
*/
|
|
94
161
|
export function createUnknownSchema(schema = {}) {
|
|
95
162
|
return {
|
|
96
163
|
...createSchemaBase(schema),
|
|
97
164
|
kind: 'unknown',
|
|
98
165
|
};
|
|
99
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Creates a property whose schema is a `oneOf` schema with the branches given in `schema.oneOf`.
|
|
169
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
170
|
+
* @param schema The arguments of the `oneOf` schema, as for {@link createOneOfSchema}.
|
|
171
|
+
* @returns The property with the given name and a `oneOf` schema.
|
|
172
|
+
* @see createOneOfSchema
|
|
173
|
+
*/
|
|
100
174
|
export function createOneOfProperty(name, schema = {}) {
|
|
101
175
|
return { name, schema: createOneOfSchema(schema) };
|
|
102
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Creates a property whose schema is a `multi-type` schema with the `type` list and keywords given in `schema`.
|
|
179
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
180
|
+
* @param schema The arguments of the `multi-type` schema, as for {@link createMultiTypeSchema}.
|
|
181
|
+
* @returns The property with the given name and a `multi-type` schema.
|
|
182
|
+
* @see createMultiTypeSchema
|
|
183
|
+
*/
|
|
103
184
|
export function createMultiTypeProperty(name, schema = {}) {
|
|
104
185
|
return { name, schema: createMultiTypeSchema(schema) };
|
|
105
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Creates a property whose schema is a `string` schema with `pattern`, `minLength`, `maxLength` and `format` taken
|
|
189
|
+
* from `schema`.
|
|
190
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
191
|
+
* @param schema The arguments of the `string` schema, as for {@link createStringSchema}.
|
|
192
|
+
* @returns The property with the given name and a `string` schema.
|
|
193
|
+
* @see createStringSchema
|
|
194
|
+
*/
|
|
106
195
|
export function createStringProperty(name, schema = {}) {
|
|
107
196
|
return { name, schema: createStringSchema(schema) };
|
|
108
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates a property whose schema is a `boolean` schema. Only the base fields and `format` of `schema` apply.
|
|
200
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
201
|
+
* @param schema The arguments of the `boolean` schema, as for {@link createBooleanSchema}.
|
|
202
|
+
* @returns The property with the given name and a `boolean` schema.
|
|
203
|
+
* @see createBooleanSchema
|
|
204
|
+
*/
|
|
109
205
|
export function createBooleanProperty(name, schema = {}) {
|
|
110
206
|
return { name, schema: createBooleanSchema(schema) };
|
|
111
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Creates a property whose schema is a `null` schema. Only the base fields of `schema` apply.
|
|
210
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
211
|
+
* @param schema The arguments of the `null` schema, as for {@link createNullSchema}.
|
|
212
|
+
* @returns The property with the given name and a `null` schema.
|
|
213
|
+
* @see createNullSchema
|
|
214
|
+
*/
|
|
112
215
|
export function createNullProperty(name, schema = {}) {
|
|
113
216
|
return { name, schema: createNullSchema(schema) };
|
|
114
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Creates a property whose schema is a `number` schema with `minimum`, `maximum` and `format` taken from `schema`.
|
|
220
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
221
|
+
* @param schema The arguments of the `number` schema, as for {@link createNumberSchema}.
|
|
222
|
+
* @returns The property with the given name and a `number` schema.
|
|
223
|
+
* @see createNumberSchema
|
|
224
|
+
*/
|
|
115
225
|
export function createNumberProperty(name, schema = {}) {
|
|
116
226
|
return { name, schema: createNumberSchema(schema) };
|
|
117
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Creates a property whose schema is an `integer` schema with `minimum`, `maximum` and `format` taken from `schema`.
|
|
230
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
231
|
+
* @param schema The arguments of the `integer` schema, as for {@link createIntegerSchema}.
|
|
232
|
+
* @returns The property with the given name and an `integer` schema.
|
|
233
|
+
* @see createIntegerSchema
|
|
234
|
+
*/
|
|
118
235
|
export function createIntegerProperty(name, schema = {}) {
|
|
119
236
|
return { name, schema: createIntegerSchema(schema) };
|
|
120
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates a property whose schema is an `array` schema with `items`, `minItems` and `maxItems` taken from `schema`.
|
|
240
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
241
|
+
* @param schema The arguments of the `array` schema, as for {@link createArraySchema}.
|
|
242
|
+
* @returns The property with the given name and an `array` schema.
|
|
243
|
+
* @see createArraySchema
|
|
244
|
+
*/
|
|
121
245
|
export function createArrayProperty(name, schema = {}) {
|
|
122
246
|
return { name, schema: createArraySchema(schema) };
|
|
123
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Creates a property whose schema is an `object` schema with `properties`, `additionalProperties`, `allOf` and `anyOf`
|
|
250
|
+
* taken from `schema`.
|
|
251
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
252
|
+
* @param schema The arguments of the `object` schema, as for {@link createObjectSchema}.
|
|
253
|
+
* @returns The property with the given name and an `object` schema.
|
|
254
|
+
* @see createObjectSchema
|
|
255
|
+
*/
|
|
124
256
|
export function createObjectProperty(name, schema = {}) {
|
|
125
257
|
return { name, schema: createObjectSchema(schema) };
|
|
126
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Creates a property whose schema is a `combined` schema composed of the `allOf` and `anyOf` branches in `schema`.
|
|
261
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
262
|
+
* @param schema The arguments of the `combined` schema, as for {@link createCombinedSchema}.
|
|
263
|
+
* @returns The property with the given name and a `combined` schema.
|
|
264
|
+
* @see createCombinedSchema
|
|
265
|
+
*/
|
|
127
266
|
export function createCombinedProperty(name, schema = {}) {
|
|
128
267
|
return { name, schema: createCombinedSchema(schema) };
|
|
129
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Creates a property whose schema is an `unknown` schema, which carries only the base fields of `schema`.
|
|
271
|
+
* @param name The name of the property, used as its key in the `properties` of the parent schema.
|
|
272
|
+
* @param schema The arguments of the `unknown` schema, as for {@link createUnknownSchema}.
|
|
273
|
+
* @returns The property with the given name and an `unknown` schema.
|
|
274
|
+
* @see createUnknownSchema
|
|
275
|
+
*/
|
|
130
276
|
export function createUnknownProperty(name, schema = {}) {
|
|
131
277
|
return { name, schema: createUnknownSchema(schema) };
|
|
132
278
|
}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { OpenApiSchema } from '../parse/openapi-types.ts';
|
|
2
2
|
import type { ApiSchema } from '../transform/api-types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Merges the `allOf` and `anyOf` branches of a `combined` or `object` schema into one `object` schema, combining their
|
|
5
|
+
* properties, required names and additional properties. Required names from `anyOf` and composed `oneOf` branches are
|
|
6
|
+
* not taken over, and a property declared with conflicting kinds in different branches becomes a `oneOf` of both.
|
|
7
|
+
* @param schema The `combined` or `object` schema whose branches should be merged.
|
|
8
|
+
* @param ignoreNonObjectParts Whether non-object branches are tolerated. If `false`, a non-object branch makes the
|
|
9
|
+
* merge return `undefined`.
|
|
10
|
+
* @returns The merged `object` schema, or `undefined` if the merge is not possible or if there are no properties to
|
|
11
|
+
* merge and the additional properties do not change.
|
|
12
|
+
*/
|
|
3
13
|
export declare function resolveAnyOfAndAllOf(schema: ApiSchema<'combined' | 'object'>, ignoreNonObjectParts: boolean): ApiSchema<'object'> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The annotation keywords (`description`, `example` and `deprecated`) that do not count as defining a schema. A schema
|
|
16
|
+
* with a `$ref` that sets only these keywords is treated as a plain reference by {@link getSchemaReference}.
|
|
17
|
+
* @see getSchemaReference
|
|
18
|
+
*/
|
|
4
19
|
export declare const DEFAULT_IGNORED_SCHEMA_PROPERTIES: (keyof OpenApiSchema)[];
|
|
5
20
|
/**
|
|
6
21
|
* Retrieves the first schema reference and the reference chain of a given schema that
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { isOpenApiObjectProperty } from '../internal-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merges the `allOf` and `anyOf` branches of a `combined` or `object` schema into one `object` schema, combining their
|
|
4
|
+
* properties, required names and additional properties. Required names from `anyOf` and composed `oneOf` branches are
|
|
5
|
+
* not taken over, and a property declared with conflicting kinds in different branches becomes a `oneOf` of both.
|
|
6
|
+
* @param schema The `combined` or `object` schema whose branches should be merged.
|
|
7
|
+
* @param ignoreNonObjectParts Whether non-object branches are tolerated. If `false`, a non-object branch makes the
|
|
8
|
+
* merge return `undefined`.
|
|
9
|
+
* @returns The merged `object` schema, or `undefined` if the merge is not possible or if there are no properties to
|
|
10
|
+
* merge and the additional properties do not change.
|
|
11
|
+
*/
|
|
2
12
|
export function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
3
13
|
if (!ignoreNonObjectParts && (hasInvalidSubSchema(schema.anyOf) || hasInvalidSubSchema(schema.allOf))) {
|
|
4
14
|
return undefined;
|
|
@@ -182,6 +192,11 @@ function hasInvalidSubSchema(subSchemas) {
|
|
|
182
192
|
return subSchemas.some((x) => x.kind !== 'object' &&
|
|
183
193
|
(x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
|
|
184
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* The annotation keywords (`description`, `example` and `deprecated`) that do not count as defining a schema. A schema
|
|
197
|
+
* with a `$ref` that sets only these keywords is treated as a plain reference by {@link getSchemaReference}.
|
|
198
|
+
* @see getSchemaReference
|
|
199
|
+
*/
|
|
185
200
|
export const DEFAULT_IGNORED_SCHEMA_PROPERTIES = ['description', 'example', 'deprecated'];
|
|
186
201
|
/**
|
|
187
202
|
* Retrieves the first schema reference and the reference chain of a given schema that
|