@ts-pf/openapi 0.1.12 → 0.5.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/README.md +65 -5
- package/dist/close-inputs.d.ts +9 -0
- package/dist/close-inputs.d.ts.map +1 -0
- package/dist/close-inputs.js +102 -0
- package/dist/close-inputs.js.map +1 -0
- package/dist/const-enum.d.ts +7 -0
- package/dist/const-enum.d.ts.map +1 -0
- package/dist/const-enum.js +76 -0
- package/dist/const-enum.js.map +1 -0
- package/dist/discriminators.d.ts +9 -0
- package/dist/discriminators.d.ts.map +1 -0
- package/dist/discriminators.js +57 -0
- package/dist/discriminators.js.map +1 -0
- package/dist/document.d.ts +18 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +86 -0
- package/dist/document.js.map +1 -0
- package/dist/enum-names.d.ts +14 -0
- package/dist/enum-names.d.ts.map +1 -0
- package/dist/enum-names.js +103 -0
- package/dist/enum-names.js.map +1 -0
- package/dist/envelope.d.ts +5 -0
- package/dist/envelope.d.ts.map +1 -1
- package/dist/envelope.js +24 -0
- package/dist/envelope.js.map +1 -1
- package/dist/errors.d.ts +34 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +109 -42
- package/dist/errors.js.map +1 -1
- package/dist/format-patterns.d.ts +4 -0
- package/dist/format-patterns.d.ts.map +1 -0
- package/dist/format-patterns.js +39 -0
- package/dist/format-patterns.js.map +1 -0
- package/dist/hoist-objects.d.ts +15 -0
- package/dist/hoist-objects.d.ts.map +1 -0
- package/dist/hoist-objects.js +141 -0
- package/dist/hoist-objects.js.map +1 -0
- package/dist/hoist.d.ts +32 -0
- package/dist/hoist.d.ts.map +1 -0
- package/dist/hoist.js +189 -0
- package/dist/hoist.js.map +1 -0
- package/dist/names.d.ts +9 -0
- package/dist/names.d.ts.map +1 -1
- package/dist/names.js +21 -0
- package/dist/names.js.map +1 -1
- package/dist/naming.d.ts +13 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +95 -0
- package/dist/naming.js.map +1 -0
- package/dist/normalize.d.ts +11 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +18 -0
- package/dist/normalize.js.map +1 -0
- package/dist/openapi.d.ts +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +57 -17
- package/dist/openapi.js.map +1 -1
- package/dist/operation.d.ts +20 -2
- package/dist/operation.d.ts.map +1 -1
- package/dist/operation.js +46 -10
- package/dist/operation.js.map +1 -1
- package/dist/profile.d.ts +32 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +107 -0
- package/dist/profile.js.map +1 -0
- package/dist/refs.d.ts +13 -1
- package/dist/refs.d.ts.map +1 -1
- package/dist/refs.js +36 -27
- package/dist/refs.js.map +1 -1
- package/dist/shared-errors.d.ts +14 -0
- package/dist/shared-errors.d.ts.map +1 -0
- package/dist/shared-errors.js +73 -0
- package/dist/shared-errors.js.map +1 -0
- package/dist/streams.d.ts +13 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +26 -0
- package/dist/streams.js.map +1 -0
- package/dist/tags.d.ts +14 -0
- package/dist/tags.d.ts.map +1 -0
- package/dist/tags.js +40 -0
- package/dist/tags.js.map +1 -0
- package/dist/types.d.ts +100 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/walk.d.ts +13 -0
- package/dist/walk.d.ts.map +1 -0
- package/dist/walk.js +65 -0
- package/dist/walk.js.map +1 -0
- package/package.json +4 -4
- package/skills/ts-pf-openapi/SKILL.md +63 -5
package/dist/types.d.ts
CHANGED
|
@@ -34,6 +34,83 @@ export type OpenAPIOptions = {
|
|
|
34
34
|
* Default false — files are a codec, not in the catalog.
|
|
35
35
|
*/
|
|
36
36
|
multipart?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A preset for code generators. `'codegen'` sets every option below,
|
|
39
|
+
* except `streams`, `enumNames`, and `catalogHash`, to its
|
|
40
|
+
* generator-friendly value; an option you also pass wins.
|
|
41
|
+
*/
|
|
42
|
+
profile?: 'codegen';
|
|
43
|
+
/**
|
|
44
|
+
* `'components'` (default): `<path>.Request` / `<path>.Success` envelope
|
|
45
|
+
* components. `'inline'`: the envelopes are inline in each operation.
|
|
46
|
+
*/
|
|
47
|
+
envelopes?: 'components' | 'inline';
|
|
48
|
+
/**
|
|
49
|
+
* `'per-code'` (default): one failure envelope per code (`Error.<CODE>`,
|
|
50
|
+
* `TsPf.Error.<CODE>`, or `<path>.Error.<CODE>`). `'shared'`: one
|
|
51
|
+
* `RpcError` envelope, an `ErrorCode` enum, a `<Code>Data` schema per code
|
|
52
|
+
* with data, and `x-ts-pf-errors` on each operation. Throws when one code
|
|
53
|
+
* has two `data` shapes.
|
|
54
|
+
*/
|
|
55
|
+
errors?: 'per-code' | 'shared';
|
|
56
|
+
/**
|
|
57
|
+
* `'path'` (default): dotted names (`auth.verifyCode.Input`). `'pascal'`:
|
|
58
|
+
* `AuthVerifyCodeInput`; a procedure whose input or output is a
|
|
59
|
+
* `.meta({ id })` type uses the id. Throws when two schemas get one name.
|
|
60
|
+
*/
|
|
61
|
+
naming?: 'path' | 'pascal';
|
|
62
|
+
/**
|
|
63
|
+
* Add `additionalProperties: false` to objects reached only from inputs
|
|
64
|
+
* (stricter than the server, which strips unknown keys). Default false.
|
|
65
|
+
*/
|
|
66
|
+
closeInputs?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* `'exceptTags'`: rewrite `const: v` as `enum: [v]`, except on the tag
|
|
69
|
+
* property of a union of objects. Default false.
|
|
70
|
+
*/
|
|
71
|
+
constAsEnum?: false | 'exceptTags';
|
|
72
|
+
/** Drop `pattern` where a standard `format` says the same. Default false. */
|
|
73
|
+
dropFormatPatterns?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* A procedure with no input (or a `null` input) gets an inline
|
|
76
|
+
* `{ input: null }` request body and no `Input` component. Default false.
|
|
77
|
+
*/
|
|
78
|
+
emptyInputNull?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Add `discriminator: { propertyName, mapping }` to a `oneOf` / `anyOf`
|
|
81
|
+
* whose variants are all component `$ref`s with a distinct required string
|
|
82
|
+
* `const` (or one-value `enum`) on one property. Default false.
|
|
83
|
+
*/
|
|
84
|
+
discriminators?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* `'objects'`: nested inline objects with properties become named
|
|
87
|
+
* components (`BookFindOutputAuthor`, `…Item` for array items), identical
|
|
88
|
+
* shapes shared. Protocol envelopes are never hoisted. Default `'none'`.
|
|
89
|
+
*/
|
|
90
|
+
hoist?: 'none' | 'objects';
|
|
91
|
+
/**
|
|
92
|
+
* Sort the document's keys at every depth (`canonicalize` from
|
|
93
|
+
* `@ts-pf/docs`), so equal documents serialize byte for byte. Default false.
|
|
94
|
+
*/
|
|
95
|
+
canonical?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* `'operation'` (default): stream procedures are `POST … application/jsonl`
|
|
98
|
+
* operations. `'components'`: no path; their schemas are named in the
|
|
99
|
+
* document-level `x-ts-pf-streams` map. `'omit'`: left out entirely.
|
|
100
|
+
* Not set by `profile: 'codegen'`: only you know which streams are HTTP.
|
|
101
|
+
*/
|
|
102
|
+
streams?: 'operation' | 'components' | 'omit';
|
|
103
|
+
/**
|
|
104
|
+
* Names shared inline enums by value set: `{ BookStatus: ['available',
|
|
105
|
+
* 'loaned'] }` turns every inline `enum` with exactly those values (in any
|
|
106
|
+
* order) into a `$ref` to component `BookStatus`. Prefer `.meta({ id })`.
|
|
107
|
+
*/
|
|
108
|
+
enumNames?: Record<string, ReadonlyArray<string | number | boolean | null>>;
|
|
109
|
+
/**
|
|
110
|
+
* Written to `info['x-ts-pf-catalog-hash']`. Pass `catalogHash(catalog)`
|
|
111
|
+
* from `@ts-pf/codegen`.
|
|
112
|
+
*/
|
|
113
|
+
catalogHash?: string;
|
|
37
114
|
};
|
|
38
115
|
type OpenAPIMediaType = {
|
|
39
116
|
schema?: JsonSchema;
|
|
@@ -71,13 +148,33 @@ export type OpenAPIOperation = {
|
|
|
71
148
|
parameters?: Array<OpenAPIParameter | OpenAPIRef>;
|
|
72
149
|
requestBody?: OpenAPIRequestBody;
|
|
73
150
|
responses: Record<string, OpenAPIResponse>;
|
|
151
|
+
/** The error codes this operation can return (`errors: 'shared'`). */
|
|
152
|
+
'x-ts-pf-errors'?: string[];
|
|
74
153
|
};
|
|
75
154
|
export type PathItem = {
|
|
76
155
|
post?: OpenAPIOperation;
|
|
77
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* One stream procedure under `streams: 'components'`. Each schema is a
|
|
159
|
+
* `$ref` to the component the operation would have used.
|
|
160
|
+
*/
|
|
161
|
+
export type OpenAPIStreamEntry = {
|
|
162
|
+
/** The unary input. */
|
|
163
|
+
input?: JsonSchema;
|
|
164
|
+
/** Each item of a streamed input. */
|
|
165
|
+
inputItem?: JsonSchema;
|
|
166
|
+
/** Each item of a streamed output. */
|
|
167
|
+
item?: JsonSchema;
|
|
168
|
+
/** The unary output of a procedure whose input streams. */
|
|
169
|
+
output?: JsonSchema;
|
|
170
|
+
/** The error codes the procedure can return. */
|
|
171
|
+
errors: string[];
|
|
172
|
+
};
|
|
78
173
|
export type OpenAPIDocument = {
|
|
79
174
|
openapi: '3.1.0';
|
|
80
|
-
info: OpenAPIInfo
|
|
175
|
+
info: OpenAPIInfo & {
|
|
176
|
+
'x-ts-pf-catalog-hash'?: string;
|
|
177
|
+
};
|
|
81
178
|
jsonSchemaDialect?: string;
|
|
82
179
|
servers?: ReadonlyArray<OpenAPIServer>;
|
|
83
180
|
tags?: Array<{
|
|
@@ -88,6 +185,8 @@ export type OpenAPIDocument = {
|
|
|
88
185
|
schemas: Record<string, JsonSchema>;
|
|
89
186
|
parameters?: Record<string, OpenAPIParameter>;
|
|
90
187
|
};
|
|
188
|
+
/** Stream procedures by catalog key (`streams: 'components'`). */
|
|
189
|
+
'x-ts-pf-streams'?: Record<string, OpenAPIStreamEntry>;
|
|
91
190
|
};
|
|
92
191
|
export {};
|
|
93
192
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;IACD,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;CACF,CAAA;AAED,KAAK,aAAa,GAAG;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,OAAO,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;IACtC,6EAA6E;IAC7E,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,C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EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC/B,UAAU,EAAE;QACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QACnC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;KAC9C,CAAA;IACD,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;CACvD,CAAA"}
|
package/dist/walk.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JsonSchema } from '@ts-pf/docs';
|
|
2
|
+
export declare function isSchemaObject(value: unknown): value is JsonSchema;
|
|
3
|
+
type Visit = (node: JsonSchema, source: JsonSchema) => JsonSchema;
|
|
4
|
+
/**
|
|
5
|
+
* Copies a JSON Schema bottom-up, passing every schema object (children
|
|
6
|
+
* first) through `visit`, with the original object it was copied from as
|
|
7
|
+
* `source`. Boolean schemas and data keywords are copied as is.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mapSchema(schema: unknown, visit: Visit): unknown;
|
|
10
|
+
/** Calls `visit` with every schema object in `schema` (children first). */
|
|
11
|
+
export declare function forEachSchema(schema: unknown, visit: (node: JsonSchema) => void): void;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA2B7C,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAElE;AAED,KAAK,KAAK,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,KAAK,UAAU,CAAA;AAEjE;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAShE;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,GAChC,IAAI,CAKN"}
|
package/dist/walk.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Keywords whose values are subschemas. Everything else (`const`, `enum`,
|
|
2
|
+
// `default`, `examples`, …) is data and is never visited.
|
|
3
|
+
const SCHEMA_MAPS = new Set([
|
|
4
|
+
'properties',
|
|
5
|
+
'patternProperties',
|
|
6
|
+
'dependentSchemas',
|
|
7
|
+
'$defs',
|
|
8
|
+
'definitions',
|
|
9
|
+
]);
|
|
10
|
+
const SCHEMA_LISTS = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
|
|
11
|
+
const SCHEMA_ONE = new Set([
|
|
12
|
+
'items',
|
|
13
|
+
'additionalItems',
|
|
14
|
+
'additionalProperties',
|
|
15
|
+
'unevaluatedItems',
|
|
16
|
+
'unevaluatedProperties',
|
|
17
|
+
'propertyNames',
|
|
18
|
+
'contains',
|
|
19
|
+
'not',
|
|
20
|
+
'if',
|
|
21
|
+
'then',
|
|
22
|
+
'else',
|
|
23
|
+
'contentSchema',
|
|
24
|
+
]);
|
|
25
|
+
export function isSchemaObject(value) {
|
|
26
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Copies a JSON Schema bottom-up, passing every schema object (children
|
|
30
|
+
* first) through `visit`, with the original object it was copied from as
|
|
31
|
+
* `source`. Boolean schemas and data keywords are copied as is.
|
|
32
|
+
*/
|
|
33
|
+
export function mapSchema(schema, visit) {
|
|
34
|
+
if (!isSchemaObject(schema)) {
|
|
35
|
+
return schema;
|
|
36
|
+
}
|
|
37
|
+
const node = {};
|
|
38
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
39
|
+
node[key] = mapKeyword(key, value, visit);
|
|
40
|
+
}
|
|
41
|
+
return visit(node, schema);
|
|
42
|
+
}
|
|
43
|
+
/** Calls `visit` with every schema object in `schema` (children first). */
|
|
44
|
+
export function forEachSchema(schema, visit) {
|
|
45
|
+
mapSchema(schema, (node, source) => {
|
|
46
|
+
visit(source);
|
|
47
|
+
return node;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function mapKeyword(key, value, visit) {
|
|
51
|
+
if (SCHEMA_MAPS.has(key) && isSchemaObject(value)) {
|
|
52
|
+
return Object.fromEntries(Object.entries(value).map(([name, child]) => [
|
|
53
|
+
name,
|
|
54
|
+
mapSchema(child, visit),
|
|
55
|
+
]));
|
|
56
|
+
}
|
|
57
|
+
if ((SCHEMA_LISTS.has(key) || SCHEMA_ONE.has(key)) && Array.isArray(value)) {
|
|
58
|
+
return value.map((child) => mapSchema(child, visit));
|
|
59
|
+
}
|
|
60
|
+
if (SCHEMA_ONE.has(key)) {
|
|
61
|
+
return mapSchema(value, visit);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=walk.js.map
|
package/dist/walk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,0DAA0D;AAC1D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,YAAY;IACZ,mBAAmB;IACnB,kBAAkB;IAClB,OAAO;IACP,aAAa;CACd,CAAC,CAAA;AACF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAA;AACxE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,OAAO;IACP,iBAAiB;IACjB,sBAAsB;IACtB,kBAAkB;IAClB,uBAAuB;IACvB,eAAe;IACf,UAAU;IACV,KAAK;IACL,IAAI;IACJ,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K,CAAC;SACxB,CAAC,CACH,CAAA;IACH,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3E,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IACtD,CAAC;IACD,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAChC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-pf/openapi",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Opt-in OpenAPI 3.1 document from catalog() (POST JSON RPC)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts-pf",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"lint": "biome check src tests"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@ts-pf/docs": "0.1
|
|
52
|
+
"@ts-pf/docs": "0.5.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@ts-pf/contract": "0.
|
|
56
|
-
"@ts-pf/stream": "0.
|
|
55
|
+
"@ts-pf/contract": "0.5.1",
|
|
56
|
+
"@ts-pf/stream": "0.5.1",
|
|
57
57
|
"typebox": "^1.4.6",
|
|
58
58
|
"zod": "^4.0.0"
|
|
59
59
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ts-pf-openapi
|
|
3
|
-
description: "Use when projecting a ts-pf catalog() to OpenAPI 3.1 with openapi(). Triggers: @ts-pf/openapi, openapi(), OpenAPI 3.1, POST JSON RPC spec."
|
|
3
|
+
description: "Use when projecting a ts-pf catalog() to OpenAPI 3.1 with openapi(). Triggers: @ts-pf/openapi, openapi(), OpenAPI 3.1, POST JSON RPC spec, profile: 'codegen', openapi-generator / Kiota / orval / swagger_parser, discriminator, x-ts-pf-streams."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# @ts-pf/openapi
|
|
@@ -29,6 +29,58 @@ Every path is `POST {prefix}/{router keys}`. Serve JSON in userland (`GET /opena
|
|
|
29
29
|
|
|
30
30
|
Typed split-repo clients: `ts-pf-codegen`, not OpenAPI-TS.
|
|
31
31
|
|
|
32
|
+
## Component names and schema normalizations
|
|
33
|
+
|
|
34
|
+
Same schemas as the catalog, normalized for code generators:
|
|
35
|
+
|
|
36
|
+
- No nested `$schema` (the document's `jsonSchemaDialect` declares it).
|
|
37
|
+
- Output and error `data` schemas are open (no `additionalProperties: false`). Inputs and the `{ ok, … }` envelopes are unchanged.
|
|
38
|
+
- Root `$defs` / `definitions` are hoisted (every key except `__schemaN` is an id): `.meta({ id: 'Book' })` → `components.schemas.Book`, one component across procedures. `<path>.Input` / `<path>.Output` stay; a bare named type is a `$ref` to it.
|
|
39
|
+
- Input shape differs from output (a field with a default, or a closed object such as `z.strictObject`, since inputs stay closed) → output `Book`, input `BookInput`. One side only or the same shape → `Book`. Two shapes for one id on the same side, a taken `<id>Input`, or an id equal to another component name throws: give one schema a distinct `.meta({ id })`.
|
|
40
|
+
- Zod's unnamed recursion (any def key `__schemaN`) → `<host>.__schemaN`, shared only when side and shape are identical; give it an id for a stable name.
|
|
41
|
+
- Declared errors: one `Error.<CODE>` (+ `Error.<CODE>.Data`) when every procedure's `data` shape matches (or none), including a code only one procedure declares; else `<path>.Error.<CODE>` per procedure. Protocol errors: `TsPf.Error.<CODE>` (+ `TsPf.Error.VALIDATION.Data`).
|
|
42
|
+
|
|
43
|
+
Post-processing by component name? Use these names; older versions emitted `<path>.Error.<CODE>` and `$defs` under each procedure component.
|
|
44
|
+
|
|
45
|
+
## Codegen profile (non-TypeScript generators)
|
|
46
|
+
|
|
47
|
+
For openapi-generator, Kiota, orval, or swagger_parser, pass `profile: 'codegen'` instead of writing a post-processor. It is still POST JSON RPC (no GET, path params, or REST). Generate models only; the client writes a thin call layer that classifies by envelope, not HTTP status (guide: [Clients in other languages](https://github.com/crobinson42/ts-pf/blob/main/docs/other-languages.md)):
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { catalog } from '@ts-pf/docs'
|
|
51
|
+
import { openapi } from '@ts-pf/openapi'
|
|
52
|
+
|
|
53
|
+
const spec = openapi(catalog(contract, { prefix: '/rpc' }), {
|
|
54
|
+
info: { title: 'Planet API', version: '1.0.0' },
|
|
55
|
+
profile: 'codegen',
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
It sets these options (each settable alone; an explicit option beats the profile, e.g. `{ profile: 'codegen', naming: 'path' }` or `{ profile: 'codegen', hoist: 'none' }`):
|
|
60
|
+
|
|
61
|
+
- `envelopes: 'inline'` (default `'components'`): envelopes inline in each operation (no `<path>.Request` / `<path>.Success` components).
|
|
62
|
+
- `errors: 'shared'` (default `'per-code'`): one `RpcError`, an `ErrorCode` enum, `<Code>Data` per code with data (`NotFoundData`; protocol `ValidationErrorData`), `x-ts-pf-errors: [codes]` per operation. Nothing `$ref`s `<Code>Data`: map it by name from `error.code`. Throws when one code has two `data` shapes: declare one shape per code or rename one.
|
|
63
|
+
- `naming: 'pascal'` (default `'path'`): `AuthVerifyCodeInput` / `…Output`; a bare id input / output uses the id. Two schemas with one name throw: give one a distinct `.meta({ id })`.
|
|
64
|
+
- `closeInputs: true`: `additionalProperties: false` on input-only objects (stricter than the server, which strips unknown keys).
|
|
65
|
+
- `constAsEnum: 'exceptTags'`: `const` → one-value `enum`, except union tag properties.
|
|
66
|
+
- `dropFormatPatterns: true`: drop `pattern` next to a standard `format`.
|
|
67
|
+
- `emptyInputNull: true`: no input or a `null` input → inline `{ input: null }` body, no `Input` component.
|
|
68
|
+
- `hoist: 'objects'` (default `'none'`): nested inline objects with properties (under `properties`, `items`, record values, union variants; not tuple or `allOf` members) → a component named parent + path (`BookFindOutputAuthor`; array items `…Item`, record values `…Value`, union variants by tag value else `…Option1`; dotted under `naming: 'path'`). Identical shapes share one component (alphabetically first name). Envelopes keep their inline objects. Warns once listing the made-up names: give those objects `.meta({ id })`. One name for two shapes, or a name that is already a component, throws.
|
|
69
|
+
- `discriminators: true`: `discriminator: { propertyName, mapping }` on a `oneOf` / `anyOf` of component `$ref`s that each require a different string `const` (or one-value `enum`) on one property. Anything else is left alone.
|
|
70
|
+
- `canonical: true`: keys sorted at every depth (`canonicalize` from `@ts-pf/docs`), byte-stable output; `paths` and components become alphabetical.
|
|
71
|
+
|
|
72
|
+
Pass order (each sees the previous result): `naming` → `enumNames` → `closeInputs` → `dropFormatPatterns` → `constAsEnum` → `hoist` → `discriminators` → `canonical`.
|
|
73
|
+
|
|
74
|
+
Never set by the profile:
|
|
75
|
+
|
|
76
|
+
- `streams` (default `'operation'`): `'components'` gives stream procedures no path and lists their `<path>.Input` / `<path>.Output` components in `x-ts-pf-streams: { "<catalog key>": { input?, inputItem?, item?, output?, errors } }`; `'omit'` drops them like a catalog filter. The catalog cannot tell message-only streams from HTTP ones, so this is your call: use `'components'` when the streams are served over a message transport. Pair it with `errors: 'shared'` so every code's data has a `<Code>Data` component.
|
|
77
|
+
- `enumNames: { BookStatus: ['available', 'loaned'] }`: every inline `enum` with that value set (any order) → `$ref` to `BookStatus`. Prefer `.meta({ id })`. Unused entries warn; an invalid name, an entry with no values, two entries with one value set, or a name an existing component has with a different schema throws.
|
|
78
|
+
- `catalogHash`: written to `info['x-ts-pf-catalog-hash']`; pass `catalogHash(cat)` from `@ts-pf/codegen`.
|
|
79
|
+
|
|
80
|
+
`x-ts-pf-errors`, `x-ts-pf-streams`, and `x-ts-pf-catalog-hash` are the only `x-` extensions.
|
|
81
|
+
|
|
82
|
+
Security schemes and extra components stay userland: mutate the returned document.
|
|
83
|
+
|
|
32
84
|
## Documenting a GET bridge or REST facade
|
|
33
85
|
|
|
34
86
|
`openapi()` stays POST only. If you serve the userland GET bridge (`ts-pf-server-http`, "Cacheable reads"), add the `get` operations to the returned document yourself. Each opted-in catalog entry carries its contract meta, and the GET reuses the POST's responses:
|
|
@@ -53,8 +105,12 @@ for (const proc of cat.procedures) {
|
|
|
53
105
|
name: 'input',
|
|
54
106
|
in: 'query',
|
|
55
107
|
content: {
|
|
108
|
+
// The hoisted input component (its $refs resolve in this document).
|
|
56
109
|
'application/json': {
|
|
57
|
-
schema:
|
|
110
|
+
schema:
|
|
111
|
+
proc.input === undefined
|
|
112
|
+
? {}
|
|
113
|
+
: { $ref: `#/components/schemas/${item.post.operationId}.Input` },
|
|
58
114
|
},
|
|
59
115
|
},
|
|
60
116
|
}],
|
|
@@ -64,12 +120,14 @@ for (const proc of cat.procedures) {
|
|
|
64
120
|
}
|
|
65
121
|
```
|
|
66
122
|
|
|
67
|
-
|
|
123
|
+
The snippet assumes the default `naming: 'path'` (under `profile: 'codegen'` the input is `<Path>Input`, or absent with `emptyInputNull`).
|
|
124
|
+
|
|
125
|
+
A REST facade has its own paths and bodies, so it documents them by hand (or with your REST framework's generator). Reference the components `openapi()` already emitted (`#/components/schemas/<id>`, `<id>Input` for request bodies when the id split, `<path>.Input`, `<path>.Output`) instead of redeclaring them.
|
|
68
126
|
|
|
69
127
|
## API
|
|
70
128
|
|
|
71
129
|
- `openapi`
|
|
72
|
-
- `OpenAPIOptions` (`sse: true` / `multipart: true` advertise those content types), `OpenAPIDocument`
|
|
130
|
+
- `OpenAPIOptions` (`sse: true` / `multipart: true` advertise those content types; `profile: 'codegen'` and its options `envelopes`, `errors`, `naming`, `closeInputs`, `constAsEnum`, `dropFormatPatterns`, `emptyInputNull`, `hoist`, `discriminators`, `canonical`; also `streams`, `enumNames`, `catalogHash`), `OpenAPIDocument`
|
|
73
131
|
|
|
74
132
|
## Pair with
|
|
75
133
|
|
|
@@ -80,4 +138,4 @@ A REST facade has its own paths and bodies, so it documents them by hand (or wit
|
|
|
80
138
|
|
|
81
139
|
- GET/PUT/path params or flattened REST bodies from `openapi()` itself. Post-process the document in userland.
|
|
82
140
|
- Serve the spec from `FetchHandler`.
|
|
83
|
-
-
|
|
141
|
+
- Paths for message transports (not HTTP) in this document. Their stream schemas go in `x-ts-pf-streams` with `streams: 'components'`.
|