@aws/nx-plugin 1.0.0 → 1.0.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/LICENSE-THIRD-PARTY +11686 -23398
- package/README.md +18 -0
- package/generators.json +7 -0
- package/migrations.json +34 -1
- package/package.json +6 -6
- package/src/agentcore-gateway/schema.json +1 -0
- package/src/agentcore-harness/generator.d.ts +1 -1
- package/src/connection/scaffold-catalog.d.ts +4 -0
- package/src/connection/scaffold-catalog.js +3 -6
- package/src/connection/scaffold-catalog.js.map +1 -1
- package/src/infra/app/generator.d.ts +1 -1
- package/src/init/generator.d.ts +1 -1
- package/src/mcp-server/guide-pipeline.d.ts +2 -1
- package/src/mcp-server/guide-pipeline.js +6 -0
- package/src/mcp-server/guide-pipeline.js.map +1 -1
- package/src/mcp-server/mdx-ast.d.ts +7 -0
- package/src/mcp-server/mdx-ast.js +15 -0
- package/src/mcp-server/mdx-ast.js.map +1 -1
- package/src/mcp-server/schema-registry.d.ts +2 -2
- package/src/mcp-server/schema-registry.js +2 -2
- package/src/mcp-server/schema-registry.js.map +1 -1
- package/src/open-api/py-client/__snapshots__/generator.additional-properties.spec.ts.snap +34 -0
- package/src/open-api/py-client/__snapshots__/generator.arrays.spec.ts.snap +1750 -0
- package/src/open-api/py-client/__snapshots__/generator.complex-types.spec.ts.snap +82 -0
- package/src/open-api/py-client/__snapshots__/generator.composite-types.spec.ts.snap +447 -0
- package/src/open-api/py-client/__snapshots__/generator.duplicate-types.spec.ts.snap +404 -0
- package/src/open-api/py-client/__snapshots__/generator.errors.spec.ts.snap +430 -0
- package/src/open-api/py-client/__snapshots__/generator.fast-api.spec.ts.snap +447 -0
- package/src/open-api/py-client/__snapshots__/generator.petstore.spec.ts.snap +3488 -0
- package/src/open-api/py-client/__snapshots__/generator.primitive-types.spec.ts.snap +1444 -0
- package/src/open-api/py-client/__snapshots__/generator.request.spec.ts.snap +390 -0
- package/src/open-api/py-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +364 -0
- package/src/open-api/py-client/__snapshots__/generator.response.spec.ts.snap +739 -0
- package/src/open-api/py-client/__snapshots__/generator.streaming.spec.ts.snap +384 -0
- package/src/open-api/py-client/__snapshots__/generator.tags.spec.ts.snap +414 -0
- package/src/open-api/py-client/files/client/__clientModuleName__.py.template +1076 -0
- package/src/open-api/py-client/files/shared/__init__.py.template +28 -0
- package/src/open-api/py-client/files/shared/errors.py.template +37 -0
- package/src/open-api/py-client/files/shared/types.py.template +319 -0
- package/src/open-api/py-client/generator.d.ts +53 -0
- package/src/open-api/py-client/generator.js +119 -0
- package/src/open-api/py-client/generator.js.map +1 -0
- package/src/open-api/py-client/schema.d.js +6 -0
- package/src/open-api/py-client/schema.d.js.map +1 -0
- package/src/open-api/py-client/schema.d.ts +12 -0
- package/src/open-api/py-client/schema.json +28 -0
- package/src/open-api/py-client/vessel-registry-spec.json +2716 -0
- package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +274 -0
- package/src/open-api/ts-client/petstore-spec.d.ts +6 -0
- package/src/open-api/ts-client/petstore-spec.js +1275 -0
- package/src/open-api/ts-client/petstore-spec.js.map +1 -0
- package/src/open-api/ts-hooks/generator.spec.tsx +1 -1
- package/src/open-api/utils/codegen-data/languages.d.ts +68 -2
- package/src/open-api/utils/codegen-data/languages.js +433 -21
- package/src/open-api/utils/codegen-data/languages.js.map +1 -1
- package/src/open-api/utils/codegen-data/types.d.ts +187 -0
- package/src/open-api/utils/codegen-data/types.js +10 -1
- package/src/open-api/utils/codegen-data/types.js.map +1 -1
- package/src/open-api/utils/codegen-data.d.ts +40 -1
- package/src/open-api/utils/codegen-data.js +622 -17
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/open-api/utils/normalise.js +175 -41
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/open-api/utils/parser.js +1 -1
- package/src/open-api/utils/parser.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/preset/generator.d.ts +1 -1
- package/src/py/agent/gateway-connection/generator.js +0 -3
- package/src/py/agent/gateway-connection/generator.js.map +1 -1
- package/src/py/agent/react-connection/generator.d.ts +1 -1
- package/src/py/agent/schema.json +2 -0
- package/src/py/fast-api/react/generator.d.ts +1 -1
- package/src/py/mcp-server/schema.json +1 -0
- package/src/sdk/open-api.d.ts +2 -0
- package/src/sdk/open-api.js +1 -0
- package/src/sdk/open-api.js.map +1 -1
- package/src/smithy/project/generator.d.ts +1 -1
- package/src/smithy/react-connection/generator.d.ts +1 -1
- package/src/terraform/project/generator.d.ts +1 -1
- package/src/trpc/react/generator.d.ts +1 -1
- package/src/ts/agent/a2a-connection/generator.d.ts +1 -1
- package/src/ts/agent/gateway-connection/generator.d.ts +1 -1
- package/src/ts/agent/gateway-connection/generator.js +0 -3
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/generator.d.ts +1 -1
- package/src/ts/agent/react-connection/generator.d.ts +1 -1
- package/src/ts/agent/schema.json +1 -0
- package/src/ts/api/schema.json +2 -0
- package/src/ts/astro-docs/generator.d.ts +1 -1
- package/src/ts/dcr-proxy/generator.d.ts +1 -1
- package/src/ts/dynamodb/generator.d.ts +1 -1
- package/src/ts/lambda-function/generator.d.ts +1 -1
- package/src/ts/lib/generator.d.ts +1 -1
- package/src/ts/mcp-server/schema.json +1 -0
- package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +1 -1
- package/src/ts/nx-generator/generator.d.ts +1 -1
- package/src/ts/nx-migration/generator.d.ts +1 -1
- package/src/ts/nx-plugin/generator.d.ts +1 -1
- package/src/ts/rdb/generator.d.ts +1 -1
- package/src/ts/react-website/agui/generator.d.ts +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +10 -10
- package/src/ts/react-website/app/schema.json +1 -0
- package/src/ts/website/app/schema.json +1 -0
- package/src/utils/metrics-assertions.d.ts +18 -0
- package/src/utils/metrics-assertions.js +42 -0
- package/src/utils/metrics-assertions.js.map +1 -0
- package/src/utils/test/python-dependencies.d.ts +8 -0
- package/src/utils/test/python-dependencies.js +14 -0
- package/src/utils/test/python-dependencies.js.map +1 -0
- package/src/utils/test/python-worker/worker.py +703 -0
- package/src/utils/test/warm-python-cache.d.ts +18 -0
- package/src/utils/test/warm-python-cache.js +46 -0
- package/src/utils/test/warm-python-cache.js.map +1 -0
- package/src/utils/versions.d.ts +10 -9
- package/src/utils/versions.js +9 -8
- package/src/utils/versions.js.map +1 -1
|
@@ -52,6 +52,8 @@ export interface Discriminator {
|
|
|
52
52
|
propertyName: string;
|
|
53
53
|
/** The TypeScript property name (resolved during augmentation). */
|
|
54
54
|
typescriptPropertyName?: string;
|
|
55
|
+
/** The Python field name (resolved during augmentation). */
|
|
56
|
+
pythonPropertyName?: string;
|
|
55
57
|
/** The value → composed-model mapping. */
|
|
56
58
|
mapping: DiscriminatorMapping[];
|
|
57
59
|
/**
|
|
@@ -153,6 +155,17 @@ export interface Model {
|
|
|
153
155
|
patternPropertiesModels?: PatternPropertyModel[];
|
|
154
156
|
/** For composites: the referenced (object) models composed together. */
|
|
155
157
|
composedModels?: Model[];
|
|
158
|
+
/**
|
|
159
|
+
* For `all-of` composites: the flattened property list across all composed
|
|
160
|
+
* models (first occurrence of each property name wins).
|
|
161
|
+
*/
|
|
162
|
+
effectiveProperties?: Model[];
|
|
163
|
+
/**
|
|
164
|
+
* Set on a hoisted (normaliser-synthesised) model that an `all-of` parent
|
|
165
|
+
* flattens into itself, to the parent's name. Language templates that
|
|
166
|
+
* flatten composition can skip emitting the hoisted component separately.
|
|
167
|
+
*/
|
|
168
|
+
isInlinedByAllOf?: string;
|
|
156
169
|
/** For composites: the primitive/enum/array members composed together. */
|
|
157
170
|
composedPrimitives?: Model[];
|
|
158
171
|
/** For discriminated one-of/any-of composites: the discriminator metadata. */
|
|
@@ -165,8 +178,34 @@ export interface Model {
|
|
|
165
178
|
pythonName?: string;
|
|
166
179
|
/** The rendered Python type. */
|
|
167
180
|
pythonType?: string;
|
|
181
|
+
/**
|
|
182
|
+
* The Python type as a tree. Templates inspect this to decide how a value is
|
|
183
|
+
* validated, rather than matching on how `pythonType` is spelled.
|
|
184
|
+
*/
|
|
185
|
+
pythonTypeTree?: PythonType;
|
|
186
|
+
/**
|
|
187
|
+
* The rendered Python type with user-defined names forward-ref quoted, for
|
|
188
|
+
* use inside class bodies before the referenced class is defined.
|
|
189
|
+
*/
|
|
190
|
+
pythonAnnotation?: string;
|
|
191
|
+
/**
|
|
192
|
+
* The Python class name: the TypeScript escape plus escaping of names that
|
|
193
|
+
* would shadow imports in the generated Python modules (e.g. `Field`).
|
|
194
|
+
*/
|
|
195
|
+
pythonClassName?: string;
|
|
196
|
+
/**
|
|
197
|
+
* The Python type qualified with the `types.` namespace, for reference
|
|
198
|
+
* from the generated client modules.
|
|
199
|
+
*/
|
|
200
|
+
pythonClientType?: string;
|
|
168
201
|
/** snake_case model name (Python). */
|
|
169
202
|
nameSnakeCase?: string;
|
|
203
|
+
/**
|
|
204
|
+
* When `type` references a named model that renders as a module-level alias
|
|
205
|
+
* (collection, union or literal) rather than a class: the kind of alias.
|
|
206
|
+
* Python templates use this to pick `TypeAdapter(X)` over `X.model_validate`.
|
|
207
|
+
*/
|
|
208
|
+
referencedCollectionKind?: 'array' | 'dictionary' | 'alias';
|
|
170
209
|
/** True when the model is a renderable primitive (not composite/collection). */
|
|
171
210
|
isPrimitive?: boolean;
|
|
172
211
|
/** True when the schema declares an enum. */
|
|
@@ -188,6 +227,123 @@ export interface Model {
|
|
|
188
227
|
export type VendorExtensions = {
|
|
189
228
|
[key: string]: unknown;
|
|
190
229
|
};
|
|
230
|
+
/**
|
|
231
|
+
* A Python type as a tree rather than the rendered string, so a consumer can
|
|
232
|
+
* ask what a type *is* instead of matching on how it happens to be spelled.
|
|
233
|
+
*
|
|
234
|
+
* `builtin` — a type needing no import or qualification (`str`, `int`, `Any`,
|
|
235
|
+
* `datetime.date`). `reference` — a name defined in the generated `types`
|
|
236
|
+
* module, which may need qualifying or forward-ref quoting. `literal` — a
|
|
237
|
+
* `Literal[...]` from an enum or discriminator tag. The rest describe
|
|
238
|
+
* structure, whose members are themselves `PythonType`s.
|
|
239
|
+
*/
|
|
240
|
+
export type PythonType = {
|
|
241
|
+
kind: 'builtin';
|
|
242
|
+
name: string;
|
|
243
|
+
} | {
|
|
244
|
+
kind: 'reference';
|
|
245
|
+
name: string;
|
|
246
|
+
} | {
|
|
247
|
+
kind: 'literal';
|
|
248
|
+
values: string[];
|
|
249
|
+
} | {
|
|
250
|
+
kind: 'list';
|
|
251
|
+
element: PythonType;
|
|
252
|
+
} | {
|
|
253
|
+
kind: 'dict';
|
|
254
|
+
value: PythonType;
|
|
255
|
+
} | {
|
|
256
|
+
kind: 'tuple';
|
|
257
|
+
members: PythonType[];
|
|
258
|
+
} | {
|
|
259
|
+
kind: 'optional';
|
|
260
|
+
inner: PythonType;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Whether the type describes a container whose contents pydantic must validate
|
|
264
|
+
* element-wise — the distinction that decides `TypeAdapter(X)` over
|
|
265
|
+
* `X.model_validate(...)`, since only a class carries that method.
|
|
266
|
+
*/
|
|
267
|
+
export declare const isPythonCollection: (type: PythonType) => boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Whether the type is validated through a `TypeAdapter` rather than by calling
|
|
270
|
+
* a method on it: everything except a reference to a generated class.
|
|
271
|
+
*/
|
|
272
|
+
export declare const needsPythonTypeAdapter: (type: PythonType) => boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Where a single operation input is placed in the HTTP request. `body-field`
|
|
275
|
+
* is a field of an object request body flattened into the call signature.
|
|
276
|
+
*/
|
|
277
|
+
export interface RequestInputSource {
|
|
278
|
+
kind: 'path' | 'query' | 'header' | 'cookie' | 'body' | 'body-field';
|
|
279
|
+
/** The wire (spec) name for parameters; absent for `body-field`. */
|
|
280
|
+
wireName?: string;
|
|
281
|
+
/** The body property name, for `body-field` inputs. */
|
|
282
|
+
fieldName?: string;
|
|
283
|
+
/** Collection serialisation format for array query/header parameters. */
|
|
284
|
+
collectionFormat?: CollectionFormat;
|
|
285
|
+
}
|
|
286
|
+
/** A single input to an operation, tagged with where it goes on the wire. */
|
|
287
|
+
export interface RequestInput {
|
|
288
|
+
source: RequestInputSource;
|
|
289
|
+
/** The model describing the input's type. */
|
|
290
|
+
model: Model;
|
|
291
|
+
isRequired: boolean;
|
|
292
|
+
isNullable: boolean;
|
|
293
|
+
description: string | null;
|
|
294
|
+
/** The original spec name (parameter name or body property name). */
|
|
295
|
+
specName: string;
|
|
296
|
+
/** The Python keyword-argument name (deduplicated snake_case). */
|
|
297
|
+
pythonName?: string;
|
|
298
|
+
/** The Python annotation for the kwarg, qualified with `types.`. */
|
|
299
|
+
pythonAnnotation?: string;
|
|
300
|
+
/** The annotation as a tree, so templates can inspect it structurally. */
|
|
301
|
+
pythonTypeTree?: PythonType;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* A language-agnostic description of an operation's inputs. Each input carries
|
|
305
|
+
* its request placement plus the underlying model; language templates decide
|
|
306
|
+
* how to render the call signature (kwargs, a wrapper interface, etc).
|
|
307
|
+
*/
|
|
308
|
+
export interface RequestShape {
|
|
309
|
+
inputs: RequestInput[];
|
|
310
|
+
/** True when the body is the operation's only input (positional-arg style). */
|
|
311
|
+
isSingleBodyInput: boolean;
|
|
312
|
+
/** Set when the body's fields are flattened into the inputs. */
|
|
313
|
+
bodyFromFields?: {
|
|
314
|
+
model: Model;
|
|
315
|
+
mediaType?: string;
|
|
316
|
+
};
|
|
317
|
+
/** Set when the body is passed as a single input. */
|
|
318
|
+
bodyAsSingleInput?: {
|
|
319
|
+
model: Model;
|
|
320
|
+
mediaType?: string;
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/** One non-success response bucket in an operation's error taxonomy. */
|
|
324
|
+
export interface ErrorShapeEntry {
|
|
325
|
+
code: number | string;
|
|
326
|
+
responseModel: Model;
|
|
327
|
+
/** The generated per-code error class name (e.g. `GetPet404Error`). */
|
|
328
|
+
className?: string;
|
|
329
|
+
/** True for a literal numeric code (vs a range or `default`). */
|
|
330
|
+
isExactCode?: boolean;
|
|
331
|
+
/** The Python annotation for the error's `status` field. */
|
|
332
|
+
statusAnnotation?: string;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* A language-agnostic error taxonomy for an operation: one entry per
|
|
336
|
+
* non-success response bucket.
|
|
337
|
+
*/
|
|
338
|
+
export interface ErrorShape {
|
|
339
|
+
entries: ErrorShapeEntry[];
|
|
340
|
+
/** The generated exception class name (e.g. `GetPetApiError`). */
|
|
341
|
+
exceptionClassName?: string;
|
|
342
|
+
/** The generated error union type name (e.g. `GetPetError`). */
|
|
343
|
+
unionTypeName?: string;
|
|
344
|
+
/** False when the operation declares no error responses, so the union is `Never`. */
|
|
345
|
+
hasErrorEntries?: boolean;
|
|
346
|
+
}
|
|
191
347
|
/**
|
|
192
348
|
* An operation represents a single OpenAPI path + method. Produced by the
|
|
193
349
|
* parser and augmented by `../codegen-data.ts`.
|
|
@@ -211,12 +367,36 @@ export interface Operation {
|
|
|
211
367
|
dotNotationName?: string;
|
|
212
368
|
operationIdPascalCase?: string;
|
|
213
369
|
operationIdSnakeCase?: string;
|
|
370
|
+
/**
|
|
371
|
+
* The Python method name for this operation, kept distinct from the
|
|
372
|
+
* generated client's own members and from every other operation and tag.
|
|
373
|
+
*/
|
|
374
|
+
pythonMethodName?: string;
|
|
214
375
|
/** The generated request type name (e.g. `FooRequest`). */
|
|
215
376
|
requestTypeName?: string;
|
|
377
|
+
/**
|
|
378
|
+
* {@link requestTypeName} as a Python class name. TypeScript allows a name a
|
|
379
|
+
* digit-leading operationId produces (`42Request`) where Python does not.
|
|
380
|
+
*/
|
|
381
|
+
pythonRequestTypeName?: string;
|
|
216
382
|
/** The response model used as the operation's result. */
|
|
217
383
|
result?: Model;
|
|
384
|
+
/**
|
|
385
|
+
* Every response that can describe a success, ordered as the templates emit
|
|
386
|
+
* their checks: concrete codes, then the `2XX` range, then `default`.
|
|
387
|
+
*
|
|
388
|
+
* An operation declaring `200` and `2XX` has two: returning only for the
|
|
389
|
+
* first would make a 201 an error. `default` appears here because it covers
|
|
390
|
+
* whatever the spec did not enumerate, which includes success codes — but it
|
|
391
|
+
* describes non-2xx codes too, so it is a success only for a 2xx status.
|
|
392
|
+
*/
|
|
393
|
+
successResponses?: Model[];
|
|
218
394
|
/** The explicit body parameter when the body is not inlined. */
|
|
219
395
|
explicitRequestBodyParameter?: Model;
|
|
396
|
+
/** Language-agnostic description of the operation's inputs. */
|
|
397
|
+
requestShape?: RequestShape;
|
|
398
|
+
/** Language-agnostic error taxonomy for the operation. */
|
|
399
|
+
errorShape?: ErrorShape;
|
|
220
400
|
vendorExtensions?: VendorExtensions;
|
|
221
401
|
isMutation?: boolean;
|
|
222
402
|
isQuery?: boolean;
|
|
@@ -265,6 +445,13 @@ export interface CodeGenData extends ClientData {
|
|
|
265
445
|
};
|
|
266
446
|
untaggedOperations: Operation[];
|
|
267
447
|
vendorExtensions: VendorExtensions;
|
|
448
|
+
/**
|
|
449
|
+
* The Python attribute name for each key of `operationsByTag`, kept distinct
|
|
450
|
+
* from the generated client's own members and from every operation.
|
|
451
|
+
*/
|
|
452
|
+
pythonTagNames?: {
|
|
453
|
+
[tag: string]: string;
|
|
454
|
+
};
|
|
268
455
|
}
|
|
269
456
|
/**
|
|
270
457
|
* Create a {@link Model} with the default fields the parser always emits.
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/ /**
|
|
4
|
+
*/ /**
|
|
5
|
+
* Whether the type describes a container whose contents pydantic must validate
|
|
6
|
+
* element-wise — the distinction that decides `TypeAdapter(X)` over
|
|
7
|
+
* `X.model_validate(...)`, since only a class carries that method.
|
|
8
|
+
*/ export const isPythonCollection = (type)=>type.kind === 'list' || type.kind === 'dict' || type.kind === 'tuple';
|
|
9
|
+
/**
|
|
10
|
+
* Whether the type is validated through a `TypeAdapter` rather than by calling
|
|
11
|
+
* a method on it: everything except a reference to a generated class.
|
|
12
|
+
*/ export const needsPythonTypeAdapter = (type)=>type.kind !== 'reference';
|
|
13
|
+
/** Index a list of models by name. */ export const indexModelsByName = (models)=>Object.fromEntries(models.map((m)=>[
|
|
5
14
|
m.name,
|
|
6
15
|
m
|
|
7
16
|
]));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/open-api/utils/codegen-data/types.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * The kind of a {@link Model}, describing how it should be rendered.\n *\n * - `interface` — an object type with named properties\n * - `enum` — a set of string/number literal values\n * - `array` — a list whose element type is described by `link`\n * - `tuple` — a fixed-length array (`prefixItems`) whose element types are the\n * `properties`, in order\n * - `dictionary` — a map whose value type is described by `link`\n * - `reference` — a reference to another named model (`type` is its name)\n * - `generic` — a primitive (string/number/boolean/null/void/binary/any)\n * - `one-of` / `any-of` / `all-of` — a composite of other schemas\n */\nexport type ModelExport =\n | 'interface'\n | 'enum'\n | 'array'\n | 'tuple'\n | 'dictionary'\n | 'reference'\n | 'generic'\n | 'one-of'\n | 'any-of'\n | 'all-of';\n\n/**\n * Where a parameter-like {@link Model} appears in a request/response.\n * Empty string is used for models that are not parameters (schemas/properties).\n */\nexport type ModelIn =\n | ''\n | 'query'\n | 'path'\n | 'header'\n | 'cookie'\n | 'body'\n | 'response';\n\n/**\n * How array/object query & header parameters are serialised on the wire.\n * `deepObject` explodes an object into `key[prop]=value` query pairs.\n */\nexport type CollectionFormat = 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';\n\n/** A single enum member value. */\nexport interface EnumMember {\n value: string | number | boolean;\n}\n\n/**\n * A discriminated-composite mapping entry: a discriminator value and the name\n * of the composed model it selects.\n */\nexport interface DiscriminatorMapping {\n /** The discriminator property value (e.g. `\"cat\"`). */\n value: string;\n /** The name of the composed model this value selects (e.g. `\"Cat\"`). */\n modelName: string;\n}\n\n/**\n * The discriminator of a composite (`oneOf`/`anyOf`) or an inheritance base\n * (an `object` schema whose subtypes `allOf`-compose it), used to marshal\n * directly to the matching branch/subtype rather than merging every branch or\n * dropping subtype-only fields.\n */\nexport interface Discriminator {\n /** The wire property name carrying the discriminator value. */\n propertyName: string;\n /** The TypeScript property name (resolved during augmentation). */\n typescriptPropertyName?: string;\n /** The value → composed-model mapping. */\n mapping: DiscriminatorMapping[];\n /**\n * True when this discriminator sits on an inheritance base (an `object`\n * schema selected by `allOf`-composing subtypes) rather than a `oneOf`/\n * `anyOf` composite. The base marshals via dispatch to its subtypes, but its\n * subtypes compose the base's own (non-dispatching) body — so the base emits\n * a separate non-dispatching marshaller to break the recursion.\n */\n isBase?: boolean;\n}\n\n/** A pattern-property entry: a regex pattern and the model for its values. */\nexport interface PatternPropertyModel {\n pattern: string;\n model: Model;\n}\n\n/**\n * A model represents an OpenAPI schema, or something derived from one (a\n * property, parameter, or response). It is produced by the parser\n * (`../parser.ts`) and progressively augmented by `../codegen-data.ts` with\n * language-specific and code-generation fields before being handed to the\n * templates. Augmentation fields are optional as they are absent on raw parser\n * output.\n */\nexport interface Model {\n /** The schema, property, or parameter name. */\n name: string;\n /** How this model should be rendered. */\n export: ModelExport;\n /**\n * The model's type: a primitive name (`string`, `number`, `boolean`, `null`,\n * `void`, `binary`, `any`), `unknown`, or the name of a referenced model.\n */\n type: string;\n /** The OpenAPI `format` (e.g. `int32`, `date-time`, `binary`), if any. */\n format?: string;\n /** Description, used to render doc comments. */\n description: string | null;\n /** Whether the schema is marked deprecated. */\n deprecated: boolean;\n /** Whether the value may be null. */\n isNullable: boolean;\n /** Whether the property is read-only. */\n isReadOnly: boolean;\n /** Whether the property/parameter is required. */\n isRequired: boolean;\n /**\n * The `required` list this schema declared, kept even when it declares none of\n * the properties it names — an `allOf` member may raise a sibling branch's\n * property to mandatory, which is not the same as constraining nothing.\n */\n declaredRequired?: string[];\n /** Whether an array enforces uniqueness (rendered as a `Set`). */\n uniqueItems?: boolean;\n /** For arrays/dictionaries, the model describing the element/value type. */\n link?: Model | null;\n /** Child properties (for interfaces) or members (for composites). */\n properties: Model[];\n /** Enum members, when `export === 'enum'`. */\n enum: EnumMember[];\n /** Names of other models this model references (for import generation). */\n imports: string[];\n\n /** Where a parameter appears; `''` for non-parameter models. */\n in: ModelIn;\n /** The source property name for a parameter (body parameters use `body`). */\n prop?: string;\n /** The chosen request/response media type, for body params and responses. */\n mediaType?: string | null;\n /**\n * Per-part content types declared by the request body `encoding` object\n * (multipart bodies), keyed by property name.\n */\n partContentTypes?: { [prop: string]: string };\n /** All acceptable media types (request body / response). */\n mediaTypes?: string[];\n /** The response status code, for response models. */\n code?: number | string;\n\n /**\n * For a discriminated subtype's discriminator property: the rendered literal\n * TypeScript type (e.g. `'cat'`, or `'cat' | 'kitten'` when several values\n * map to one subtype) that makes the union a true tagged union. Absent when\n * the subtype's tag can't be pinned to a literal (e.g. it appears in\n * multiple unions with different values).\n */\n discriminatorValue?: string;\n\n /** The raw OpenAPI `type` (used to distinguish integer from number). */\n openapiType?: string | string[];\n /** Vendor extensions (`x-*`) copied from the schema. */\n vendorExtensions?: VendorExtensions;\n /** True when the schema has additionalProperties. */\n hasAdditionalProperties?: boolean;\n /** The model describing additionalProperties values. */\n additionalPropertiesModel?: Model;\n /** True when the schema has patternProperties. */\n hasPatternProperties?: boolean;\n /** The models describing each pattern's values. */\n patternPropertiesModels?: PatternPropertyModel[];\n\n /** For composites: the referenced (object) models composed together. */\n composedModels?: Model[];\n /** For composites: the primitive/enum/array members composed together. */\n composedPrimitives?: Model[];\n /** For discriminated one-of/any-of composites: the discriminator metadata. */\n discriminator?: Discriminator;\n\n /** The TypeScript identifier for this model/property. */\n typescriptName?: string;\n /** The rendered TypeScript type. */\n typescriptType?: string;\n /** The Python identifier for this model/property. */\n pythonName?: string;\n /** The rendered Python type. */\n pythonType?: string;\n /** snake_case model name (Python). */\n nameSnakeCase?: string;\n /** True when the model is a renderable primitive (not composite/collection). */\n isPrimitive?: boolean;\n /** True when the schema declares an enum. */\n isEnum?: boolean;\n\n /** True for JSON-lines streaming responses. */\n isJsonlStreaming?: boolean;\n /** The model describing each streamed item. */\n itemSchemaModel?: Model;\n\n /** Collection serialisation format for array query/header parameters. */\n collectionFormat?: CollectionFormat;\n /** Path parameter serialization style, when not the default `simple`. */\n pathStyle?: 'matrix' | 'label';\n /** Path parameter explode flag (used with `pathStyle`). */\n pathExplode?: boolean;\n /** Query parameter `allowReserved`: reserved characters are not encoded. */\n allowReserved?: boolean;\n}\n\n/** Vendor extension bag (`x-*` keys copied from a schema/operation/spec). */\nexport type VendorExtensions = { [key: string]: unknown };\n\n/**\n * An operation represents a single OpenAPI path + method. Produced by the\n * parser and augmented by `../codegen-data.ts`.\n */\nexport interface Operation {\n id: string;\n name: string;\n method: string;\n path: string;\n description: string | null;\n tags?: string[] | null;\n deprecated: boolean;\n imports: string[];\n parameters: Model[];\n /** The request body parameter (same object reference as in `parameters`). */\n parametersBody?: Model | null;\n responses: Model[];\n\n /** Deduplicated operation name used throughout generated code. */\n uniqueName?: string;\n /** Dot-notation name (tag-qualified), used for metadata keys. */\n dotNotationName?: string;\n operationIdPascalCase?: string;\n operationIdSnakeCase?: string;\n /** The generated request type name (e.g. `FooRequest`). */\n requestTypeName?: string;\n\n /** The response model used as the operation's result. */\n result?: Model;\n\n /** The explicit body parameter when the body is not inlined. */\n explicitRequestBodyParameter?: Model;\n\n vendorExtensions?: VendorExtensions;\n isMutation?: boolean;\n isQuery?: boolean;\n isStreaming?: boolean;\n isInfiniteQuery?: boolean;\n /** The cursor parameter, for infinite queries. */\n infiniteQueryCursorProperty?: Model;\n}\n\n/**\n * A service groups operations. Currently the parser produces a single\n * `Default` service; operations are re-grouped by tag downstream.\n */\nexport interface Service {\n name: string;\n operations: Operation[];\n imports: string[];\n\n /** All model names the service (API client) needs to import. */\n modelImports?: string[];\n className?: string;\n nameSnakeCase?: string;\n}\n\n/**\n * The initial data structure produced by the OpenAPI parser.\n */\nexport interface ClientData {\n models: Model[];\n services: Service[];\n}\n\n/** Models indexed by name, for reference resolution during augmentation. */\nexport type ModelsByName = { [name: string]: Model };\n\n/** Index a list of models by name. */\nexport const indexModelsByName = (models: Model[]): ModelsByName =>\n Object.fromEntries(models.map((m) => [m.name, m]));\n\n/** The single service the parser emits; operations are re-grouped by tag. */\nexport const DEFAULT_SERVICE_NAME = 'Default';\n\n/**\n * The full data structure handed to the code generation templates.\n */\nexport interface CodeGenData extends ClientData {\n className: string;\n info: OpenAPIV3.InfoObject | OpenAPIV3_1.InfoObject;\n allOperations: Operation[];\n operationsByTag: { [tag: string]: Operation[] };\n untaggedOperations: Operation[];\n vendorExtensions: VendorExtensions;\n}\n\n/**\n * Create a {@link Model} with the default fields the parser always emits.\n * Callers override the fields relevant to their specific schema.\n */\nexport const createModel = (overrides: Partial<Model> = {}): Model => ({\n name: '',\n export: 'interface',\n type: 'unknown',\n description: null,\n deprecated: false,\n isNullable: false,\n isReadOnly: false,\n isRequired: false,\n link: null,\n properties: [],\n enum: [],\n imports: [],\n in: '',\n ...overrides,\n});\n\n// Model types which indicate it is composed (ie inherits/mixin's another schema)\nexport const COMPOSED_SCHEMA_TYPES = new Set<ModelExport>([\n 'one-of',\n 'any-of',\n 'all-of',\n]);\nexport const COLLECTION_TYPES = new Set<ModelExport>(['array', 'dictionary']);\nexport const PRIMITIVE_TYPES = new Set([\n 'string',\n 'integer',\n 'number',\n 'boolean',\n 'null',\n 'any',\n 'binary',\n 'void',\n]);\n\n/**\n * Content types that indicate JSON Lines streaming (OpenAPI 3.2)\n */\nexport const STREAMING_CONTENT_TYPES = new Set([\n 'application/jsonl',\n 'application/x-ndjson',\n]);\n\n/**\n * Vendor extensions which are used to customise generated code\n */\nexport const VENDOR_EXTENSIONS = {\n /**\n * Set to 'true' to indicate this is a streaming API\n */\n STREAMING: 'x-streaming',\n /**\n * Set to true to indicate this is a mutation, regardless of its HTTP method\n */\n MUTATION: 'x-mutation',\n /**\n * Set to true to indicate this is a query, regardless of its HTTP method\n */\n QUERY: 'x-query',\n /**\n * Set to the name of the input property used as the cursor for pagination if\n * the API accepts a cursor that is not named 'cursor'.\n * This can also be set to false to override behaviour and indicate this is not\n * a paginated API.\n * Used for tanstack infinite query hooks.\n */\n CURSOR: 'x-cursor',\n} as const;\n"],"names":["indexModelsByName","models","Object","fromEntries","map","m","name","DEFAULT_SERVICE_NAME","createModel","overrides","export","type","description","deprecated","isNullable","isReadOnly","isRequired","link","properties","enum","imports","in","COMPOSED_SCHEMA_TYPES","Set","COLLECTION_TYPES","PRIMITIVE_TYPES","STREAMING_CONTENT_TYPES","VENDOR_EXTENSIONS","STREAMING","MUTATION","QUERY","CURSOR"],"mappings":"AAAA;;;CAGC,GA6RD,oCAAoC,GACpC,OAAO,MAAMA,oBAAoB,CAACC,SAChCC,OAAOC,WAAW,CAACF,OAAOG,GAAG,CAAC,CAACC,IAAM;YAACA,EAAEC,IAAI;YAAED;SAAE,GAAG;AAErD,2EAA2E,GAC3E,OAAO,MAAME,uBAAuB,UAAU;AAc9C;;;CAGC,GACD,OAAO,MAAMC,cAAc,CAACC,YAA4B,CAAC,CAAC,GAAa,CAAA;QACrEH,MAAM;QACNI,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,YAAY;QACZC,YAAY;QACZC,YAAY;QACZC,YAAY;QACZC,MAAM;QACNC,YAAY,EAAE;QACdC,MAAM,EAAE;QACRC,SAAS,EAAE;QACXC,IAAI;QACJ,GAAGZ,SAAS;IACd,CAAA,EAAG;AAEH,iFAAiF;AACjF,OAAO,MAAMa,wBAAwB,IAAIC,IAAiB;IACxD;IACA;IACA;CACD,EAAE;AACH,OAAO,MAAMC,mBAAmB,IAAID,IAAiB;IAAC;IAAS;CAAa,EAAE;AAC9E,OAAO,MAAME,kBAAkB,IAAIF,IAAI;IACrC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE;AAEH;;CAEC,GACD,OAAO,MAAMG,0BAA0B,IAAIH,IAAI;IAC7C;IACA;CACD,EAAE;AAEH;;CAEC,GACD,OAAO,MAAMI,oBAAoB;IAC/B;;GAEC,GACDC,WAAW;IACX;;GAEC,GACDC,UAAU;IACV;;GAEC,GACDC,OAAO;IACP;;;;;;GAMC,GACDC,QAAQ;AACV,EAAW"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/open-api/utils/codegen-data/types.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * The kind of a {@link Model}, describing how it should be rendered.\n *\n * - `interface` — an object type with named properties\n * - `enum` — a set of string/number literal values\n * - `array` — a list whose element type is described by `link`\n * - `tuple` — a fixed-length array (`prefixItems`) whose element types are the\n * `properties`, in order\n * - `dictionary` — a map whose value type is described by `link`\n * - `reference` — a reference to another named model (`type` is its name)\n * - `generic` — a primitive (string/number/boolean/null/void/binary/any)\n * - `one-of` / `any-of` / `all-of` — a composite of other schemas\n */\nexport type ModelExport =\n | 'interface'\n | 'enum'\n | 'array'\n | 'tuple'\n | 'dictionary'\n | 'reference'\n | 'generic'\n | 'one-of'\n | 'any-of'\n | 'all-of';\n\n/**\n * Where a parameter-like {@link Model} appears in a request/response.\n * Empty string is used for models that are not parameters (schemas/properties).\n */\nexport type ModelIn =\n | ''\n | 'query'\n | 'path'\n | 'header'\n | 'cookie'\n | 'body'\n | 'response';\n\n/**\n * How array/object query & header parameters are serialised on the wire.\n * `deepObject` explodes an object into `key[prop]=value` query pairs.\n */\nexport type CollectionFormat = 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';\n\n/** A single enum member value. */\nexport interface EnumMember {\n value: string | number | boolean;\n}\n\n/**\n * A discriminated-composite mapping entry: a discriminator value and the name\n * of the composed model it selects.\n */\nexport interface DiscriminatorMapping {\n /** The discriminator property value (e.g. `\"cat\"`). */\n value: string;\n /** The name of the composed model this value selects (e.g. `\"Cat\"`). */\n modelName: string;\n}\n\n/**\n * The discriminator of a composite (`oneOf`/`anyOf`) or an inheritance base\n * (an `object` schema whose subtypes `allOf`-compose it), used to marshal\n * directly to the matching branch/subtype rather than merging every branch or\n * dropping subtype-only fields.\n */\nexport interface Discriminator {\n /** The wire property name carrying the discriminator value. */\n propertyName: string;\n /** The TypeScript property name (resolved during augmentation). */\n typescriptPropertyName?: string;\n /** The Python field name (resolved during augmentation). */\n pythonPropertyName?: string;\n /** The value → composed-model mapping. */\n mapping: DiscriminatorMapping[];\n /**\n * True when this discriminator sits on an inheritance base (an `object`\n * schema selected by `allOf`-composing subtypes) rather than a `oneOf`/\n * `anyOf` composite. The base marshals via dispatch to its subtypes, but its\n * subtypes compose the base's own (non-dispatching) body — so the base emits\n * a separate non-dispatching marshaller to break the recursion.\n */\n isBase?: boolean;\n}\n\n/** A pattern-property entry: a regex pattern and the model for its values. */\nexport interface PatternPropertyModel {\n pattern: string;\n model: Model;\n}\n\n/**\n * A model represents an OpenAPI schema, or something derived from one (a\n * property, parameter, or response). It is produced by the parser\n * (`../parser.ts`) and progressively augmented by `../codegen-data.ts` with\n * language-specific and code-generation fields before being handed to the\n * templates. Augmentation fields are optional as they are absent on raw parser\n * output.\n */\nexport interface Model {\n /** The schema, property, or parameter name. */\n name: string;\n /** How this model should be rendered. */\n export: ModelExport;\n /**\n * The model's type: a primitive name (`string`, `number`, `boolean`, `null`,\n * `void`, `binary`, `any`), `unknown`, or the name of a referenced model.\n */\n type: string;\n /** The OpenAPI `format` (e.g. `int32`, `date-time`, `binary`), if any. */\n format?: string;\n /** Description, used to render doc comments. */\n description: string | null;\n /** Whether the schema is marked deprecated. */\n deprecated: boolean;\n /** Whether the value may be null. */\n isNullable: boolean;\n /** Whether the property is read-only. */\n isReadOnly: boolean;\n /** Whether the property/parameter is required. */\n isRequired: boolean;\n /**\n * The `required` list this schema declared, kept even when it declares none of\n * the properties it names — an `allOf` member may raise a sibling branch's\n * property to mandatory, which is not the same as constraining nothing.\n */\n declaredRequired?: string[];\n /** Whether an array enforces uniqueness (rendered as a `Set`). */\n uniqueItems?: boolean;\n /** For arrays/dictionaries, the model describing the element/value type. */\n link?: Model | null;\n /** Child properties (for interfaces) or members (for composites). */\n properties: Model[];\n /** Enum members, when `export === 'enum'`. */\n enum: EnumMember[];\n /** Names of other models this model references (for import generation). */\n imports: string[];\n\n /** Where a parameter appears; `''` for non-parameter models. */\n in: ModelIn;\n /** The source property name for a parameter (body parameters use `body`). */\n prop?: string;\n /** The chosen request/response media type, for body params and responses. */\n mediaType?: string | null;\n /**\n * Per-part content types declared by the request body `encoding` object\n * (multipart bodies), keyed by property name.\n */\n partContentTypes?: { [prop: string]: string };\n /** All acceptable media types (request body / response). */\n mediaTypes?: string[];\n /** The response status code, for response models. */\n code?: number | string;\n\n /**\n * For a discriminated subtype's discriminator property: the rendered literal\n * TypeScript type (e.g. `'cat'`, or `'cat' | 'kitten'` when several values\n * map to one subtype) that makes the union a true tagged union. Absent when\n * the subtype's tag can't be pinned to a literal (e.g. it appears in\n * multiple unions with different values).\n */\n discriminatorValue?: string;\n\n /** The raw OpenAPI `type` (used to distinguish integer from number). */\n openapiType?: string | string[];\n /** Vendor extensions (`x-*`) copied from the schema. */\n vendorExtensions?: VendorExtensions;\n /** True when the schema has additionalProperties. */\n hasAdditionalProperties?: boolean;\n /** The model describing additionalProperties values. */\n additionalPropertiesModel?: Model;\n /** True when the schema has patternProperties. */\n hasPatternProperties?: boolean;\n /** The models describing each pattern's values. */\n patternPropertiesModels?: PatternPropertyModel[];\n\n /** For composites: the referenced (object) models composed together. */\n composedModels?: Model[];\n /**\n * For `all-of` composites: the flattened property list across all composed\n * models (first occurrence of each property name wins).\n */\n effectiveProperties?: Model[];\n /**\n * Set on a hoisted (normaliser-synthesised) model that an `all-of` parent\n * flattens into itself, to the parent's name. Language templates that\n * flatten composition can skip emitting the hoisted component separately.\n */\n isInlinedByAllOf?: string;\n /** For composites: the primitive/enum/array members composed together. */\n composedPrimitives?: Model[];\n /** For discriminated one-of/any-of composites: the discriminator metadata. */\n discriminator?: Discriminator;\n\n /** The TypeScript identifier for this model/property. */\n typescriptName?: string;\n /** The rendered TypeScript type. */\n typescriptType?: string;\n /** The Python identifier for this model/property. */\n pythonName?: string;\n /** The rendered Python type. */\n pythonType?: string;\n /**\n * The Python type as a tree. Templates inspect this to decide how a value is\n * validated, rather than matching on how `pythonType` is spelled.\n */\n pythonTypeTree?: PythonType;\n /**\n * The rendered Python type with user-defined names forward-ref quoted, for\n * use inside class bodies before the referenced class is defined.\n */\n pythonAnnotation?: string;\n /**\n * The Python class name: the TypeScript escape plus escaping of names that\n * would shadow imports in the generated Python modules (e.g. `Field`).\n */\n pythonClassName?: string;\n /**\n * The Python type qualified with the `types.` namespace, for reference\n * from the generated client modules.\n */\n pythonClientType?: string;\n /** snake_case model name (Python). */\n nameSnakeCase?: string;\n /**\n * When `type` references a named model that renders as a module-level alias\n * (collection, union or literal) rather than a class: the kind of alias.\n * Python templates use this to pick `TypeAdapter(X)` over `X.model_validate`.\n */\n referencedCollectionKind?: 'array' | 'dictionary' | 'alias';\n /** True when the model is a renderable primitive (not composite/collection). */\n isPrimitive?: boolean;\n /** True when the schema declares an enum. */\n isEnum?: boolean;\n\n /** True for JSON-lines streaming responses. */\n isJsonlStreaming?: boolean;\n /** The model describing each streamed item. */\n itemSchemaModel?: Model;\n\n /** Collection serialisation format for array query/header parameters. */\n collectionFormat?: CollectionFormat;\n /** Path parameter serialization style, when not the default `simple`. */\n pathStyle?: 'matrix' | 'label';\n /** Path parameter explode flag (used with `pathStyle`). */\n pathExplode?: boolean;\n /** Query parameter `allowReserved`: reserved characters are not encoded. */\n allowReserved?: boolean;\n}\n\n/** Vendor extension bag (`x-*` keys copied from a schema/operation/spec). */\nexport type VendorExtensions = { [key: string]: unknown };\n\n/**\n * A Python type as a tree rather than the rendered string, so a consumer can\n * ask what a type *is* instead of matching on how it happens to be spelled.\n *\n * `builtin` — a type needing no import or qualification (`str`, `int`, `Any`,\n * `datetime.date`). `reference` — a name defined in the generated `types`\n * module, which may need qualifying or forward-ref quoting. `literal` — a\n * `Literal[...]` from an enum or discriminator tag. The rest describe\n * structure, whose members are themselves `PythonType`s.\n */\nexport type PythonType =\n | { kind: 'builtin'; name: string }\n | { kind: 'reference'; name: string }\n | { kind: 'literal'; values: string[] }\n | { kind: 'list'; element: PythonType }\n | { kind: 'dict'; value: PythonType }\n | { kind: 'tuple'; members: PythonType[] }\n | { kind: 'optional'; inner: PythonType };\n\n/**\n * Whether the type describes a container whose contents pydantic must validate\n * element-wise — the distinction that decides `TypeAdapter(X)` over\n * `X.model_validate(...)`, since only a class carries that method.\n */\nexport const isPythonCollection = (type: PythonType): boolean =>\n type.kind === 'list' || type.kind === 'dict' || type.kind === 'tuple';\n\n/**\n * Whether the type is validated through a `TypeAdapter` rather than by calling\n * a method on it: everything except a reference to a generated class.\n */\nexport const needsPythonTypeAdapter = (type: PythonType): boolean =>\n type.kind !== 'reference';\n\n/**\n * Where a single operation input is placed in the HTTP request. `body-field`\n * is a field of an object request body flattened into the call signature.\n */\nexport interface RequestInputSource {\n kind: 'path' | 'query' | 'header' | 'cookie' | 'body' | 'body-field';\n /** The wire (spec) name for parameters; absent for `body-field`. */\n wireName?: string;\n /** The body property name, for `body-field` inputs. */\n fieldName?: string;\n /** Collection serialisation format for array query/header parameters. */\n collectionFormat?: CollectionFormat;\n}\n\n/** A single input to an operation, tagged with where it goes on the wire. */\nexport interface RequestInput {\n source: RequestInputSource;\n /** The model describing the input's type. */\n model: Model;\n isRequired: boolean;\n isNullable: boolean;\n description: string | null;\n /** The original spec name (parameter name or body property name). */\n specName: string;\n /** The Python keyword-argument name (deduplicated snake_case). */\n pythonName?: string;\n /** The Python annotation for the kwarg, qualified with `types.`. */\n pythonAnnotation?: string;\n /** The annotation as a tree, so templates can inspect it structurally. */\n pythonTypeTree?: PythonType;\n}\n\n/**\n * A language-agnostic description of an operation's inputs. Each input carries\n * its request placement plus the underlying model; language templates decide\n * how to render the call signature (kwargs, a wrapper interface, etc).\n */\nexport interface RequestShape {\n inputs: RequestInput[];\n /** True when the body is the operation's only input (positional-arg style). */\n isSingleBodyInput: boolean;\n /** Set when the body's fields are flattened into the inputs. */\n bodyFromFields?: { model: Model; mediaType?: string };\n /** Set when the body is passed as a single input. */\n bodyAsSingleInput?: { model: Model; mediaType?: string };\n}\n\n/** One non-success response bucket in an operation's error taxonomy. */\nexport interface ErrorShapeEntry {\n code: number | string;\n responseModel: Model;\n /** The generated per-code error class name (e.g. `GetPet404Error`). */\n className?: string;\n /** True for a literal numeric code (vs a range or `default`). */\n isExactCode?: boolean;\n /** The Python annotation for the error's `status` field. */\n statusAnnotation?: string;\n}\n\n/**\n * A language-agnostic error taxonomy for an operation: one entry per\n * non-success response bucket.\n */\nexport interface ErrorShape {\n entries: ErrorShapeEntry[];\n /** The generated exception class name (e.g. `GetPetApiError`). */\n exceptionClassName?: string;\n /** The generated error union type name (e.g. `GetPetError`). */\n unionTypeName?: string;\n /** False when the operation declares no error responses, so the union is `Never`. */\n hasErrorEntries?: boolean;\n}\n\n/**\n * An operation represents a single OpenAPI path + method. Produced by the\n * parser and augmented by `../codegen-data.ts`.\n */\nexport interface Operation {\n id: string;\n name: string;\n method: string;\n path: string;\n description: string | null;\n tags?: string[] | null;\n deprecated: boolean;\n imports: string[];\n parameters: Model[];\n /** The request body parameter (same object reference as in `parameters`). */\n parametersBody?: Model | null;\n responses: Model[];\n\n /** Deduplicated operation name used throughout generated code. */\n uniqueName?: string;\n /** Dot-notation name (tag-qualified), used for metadata keys. */\n dotNotationName?: string;\n operationIdPascalCase?: string;\n operationIdSnakeCase?: string;\n /**\n * The Python method name for this operation, kept distinct from the\n * generated client's own members and from every other operation and tag.\n */\n pythonMethodName?: string;\n /** The generated request type name (e.g. `FooRequest`). */\n requestTypeName?: string;\n /**\n * {@link requestTypeName} as a Python class name. TypeScript allows a name a\n * digit-leading operationId produces (`42Request`) where Python does not.\n */\n pythonRequestTypeName?: string;\n\n /** The response model used as the operation's result. */\n result?: Model;\n /**\n * Every response that can describe a success, ordered as the templates emit\n * their checks: concrete codes, then the `2XX` range, then `default`.\n *\n * An operation declaring `200` and `2XX` has two: returning only for the\n * first would make a 201 an error. `default` appears here because it covers\n * whatever the spec did not enumerate, which includes success codes — but it\n * describes non-2xx codes too, so it is a success only for a 2xx status.\n */\n successResponses?: Model[];\n\n /** The explicit body parameter when the body is not inlined. */\n explicitRequestBodyParameter?: Model;\n\n /** Language-agnostic description of the operation's inputs. */\n requestShape?: RequestShape;\n /** Language-agnostic error taxonomy for the operation. */\n errorShape?: ErrorShape;\n\n vendorExtensions?: VendorExtensions;\n isMutation?: boolean;\n isQuery?: boolean;\n isStreaming?: boolean;\n isInfiniteQuery?: boolean;\n /** The cursor parameter, for infinite queries. */\n infiniteQueryCursorProperty?: Model;\n}\n\n/**\n * A service groups operations. Currently the parser produces a single\n * `Default` service; operations are re-grouped by tag downstream.\n */\nexport interface Service {\n name: string;\n operations: Operation[];\n imports: string[];\n\n /** All model names the service (API client) needs to import. */\n modelImports?: string[];\n className?: string;\n nameSnakeCase?: string;\n}\n\n/**\n * The initial data structure produced by the OpenAPI parser.\n */\nexport interface ClientData {\n models: Model[];\n services: Service[];\n}\n\n/** Models indexed by name, for reference resolution during augmentation. */\nexport type ModelsByName = { [name: string]: Model };\n\n/** Index a list of models by name. */\nexport const indexModelsByName = (models: Model[]): ModelsByName =>\n Object.fromEntries(models.map((m) => [m.name, m]));\n\n/** The single service the parser emits; operations are re-grouped by tag. */\nexport const DEFAULT_SERVICE_NAME = 'Default';\n\n/**\n * The full data structure handed to the code generation templates.\n */\nexport interface CodeGenData extends ClientData {\n className: string;\n info: OpenAPIV3.InfoObject | OpenAPIV3_1.InfoObject;\n allOperations: Operation[];\n operationsByTag: { [tag: string]: Operation[] };\n untaggedOperations: Operation[];\n vendorExtensions: VendorExtensions;\n /**\n * The Python attribute name for each key of `operationsByTag`, kept distinct\n * from the generated client's own members and from every operation.\n */\n pythonTagNames?: { [tag: string]: string };\n}\n\n/**\n * Create a {@link Model} with the default fields the parser always emits.\n * Callers override the fields relevant to their specific schema.\n */\nexport const createModel = (overrides: Partial<Model> = {}): Model => ({\n name: '',\n export: 'interface',\n type: 'unknown',\n description: null,\n deprecated: false,\n isNullable: false,\n isReadOnly: false,\n isRequired: false,\n link: null,\n properties: [],\n enum: [],\n imports: [],\n in: '',\n ...overrides,\n});\n\n// Model types which indicate it is composed (ie inherits/mixin's another schema)\nexport const COMPOSED_SCHEMA_TYPES = new Set<ModelExport>([\n 'one-of',\n 'any-of',\n 'all-of',\n]);\nexport const COLLECTION_TYPES = new Set<ModelExport>(['array', 'dictionary']);\nexport const PRIMITIVE_TYPES = new Set([\n 'string',\n 'integer',\n 'number',\n 'boolean',\n 'null',\n 'any',\n 'binary',\n 'void',\n]);\n\n/**\n * Content types that indicate JSON Lines streaming (OpenAPI 3.2)\n */\nexport const STREAMING_CONTENT_TYPES = new Set([\n 'application/jsonl',\n 'application/x-ndjson',\n]);\n\n/**\n * Vendor extensions which are used to customise generated code\n */\nexport const VENDOR_EXTENSIONS = {\n /**\n * Set to 'true' to indicate this is a streaming API\n */\n STREAMING: 'x-streaming',\n /**\n * Set to true to indicate this is a mutation, regardless of its HTTP method\n */\n MUTATION: 'x-mutation',\n /**\n * Set to true to indicate this is a query, regardless of its HTTP method\n */\n QUERY: 'x-query',\n /**\n * Set to the name of the input property used as the cursor for pagination if\n * the API accepts a cursor that is not named 'cursor'.\n * This can also be set to false to override behaviour and indicate this is not\n * a paginated API.\n * Used for tanstack infinite query hooks.\n */\n CURSOR: 'x-cursor',\n} as const;\n"],"names":["isPythonCollection","type","kind","needsPythonTypeAdapter","indexModelsByName","models","Object","fromEntries","map","m","name","DEFAULT_SERVICE_NAME","createModel","overrides","export","description","deprecated","isNullable","isReadOnly","isRequired","link","properties","enum","imports","in","COMPOSED_SCHEMA_TYPES","Set","COLLECTION_TYPES","PRIMITIVE_TYPES","STREAMING_CONTENT_TYPES","VENDOR_EXTENSIONS","STREAMING","MUTATION","QUERY","CURSOR"],"mappings":"AAAA;;;CAGC,GAmRD;;;;CAIC,GACD,OAAO,MAAMA,qBAAqB,CAACC,OACjCA,KAAKC,IAAI,KAAK,UAAUD,KAAKC,IAAI,KAAK,UAAUD,KAAKC,IAAI,KAAK,QAAQ;AAExE;;;CAGC,GACD,OAAO,MAAMC,yBAAyB,CAACF,OACrCA,KAAKC,IAAI,KAAK,YAAY;AAwK5B,oCAAoC,GACpC,OAAO,MAAME,oBAAoB,CAACC,SAChCC,OAAOC,WAAW,CAACF,OAAOG,GAAG,CAAC,CAACC,IAAM;YAACA,EAAEC,IAAI;YAAED;SAAE,GAAG;AAErD,2EAA2E,GAC3E,OAAO,MAAME,uBAAuB,UAAU;AAmB9C;;;CAGC,GACD,OAAO,MAAMC,cAAc,CAACC,YAA4B,CAAC,CAAC,GAAa,CAAA;QACrEH,MAAM;QACNI,QAAQ;QACRb,MAAM;QACNc,aAAa;QACbC,YAAY;QACZC,YAAY;QACZC,YAAY;QACZC,YAAY;QACZC,MAAM;QACNC,YAAY,EAAE;QACdC,MAAM,EAAE;QACRC,SAAS,EAAE;QACXC,IAAI;QACJ,GAAGX,SAAS;IACd,CAAA,EAAG;AAEH,iFAAiF;AACjF,OAAO,MAAMY,wBAAwB,IAAIC,IAAiB;IACxD;IACA;IACA;CACD,EAAE;AACH,OAAO,MAAMC,mBAAmB,IAAID,IAAiB;IAAC;IAAS;CAAa,EAAE;AAC9E,OAAO,MAAME,kBAAkB,IAAIF,IAAI;IACrC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE;AAEH;;CAEC,GACD,OAAO,MAAMG,0BAA0B,IAAIH,IAAI;IAC7C;IACA;CACD,EAAE;AAEH;;CAEC,GACD,OAAO,MAAMI,oBAAoB;IAC/B;;GAEC,GACDC,WAAW;IACX;;GAEC,GACDC,UAAU;IACV;;GAEC,GACDC,OAAO;IACP;;;;;;GAMC,GACDC,QAAQ;AACV,EAAW"}
|
|
@@ -2,9 +2,48 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { type CodeGenData } from './codegen-data/types.js';
|
|
5
|
+
import { type CodeGenData, type Model } from './codegen-data/types.js';
|
|
6
6
|
import type { Spec } from './types.js';
|
|
7
7
|
/**
|
|
8
8
|
* Build the data structure used to generate code from an OpenAPI spec.
|
|
9
9
|
*/
|
|
10
10
|
export declare const buildOpenApiCodeGenData: (inSpec: Spec) => CodeGenData;
|
|
11
|
+
/**
|
|
12
|
+
* Attributes and methods the generated Python client defines on itself. An
|
|
13
|
+
* operation or tag whose name would land on one of these is suffixed, so a
|
|
14
|
+
* spec can't silently replace the client's own plumbing — an operation called
|
|
15
|
+
* `close` would otherwise shadow the method that releases the httpx client.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PYTHON_CLIENT_MEMBERS: Set<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Final pass over all models + operation payloads to re-derive python type
|
|
20
|
+
* annotations after links/composites are resolved, and to add the
|
|
21
|
+
* python-specific annotations the py-client templates consume:
|
|
22
|
+
* - `pythonType` / `pythonAnnotation` (refreshed — necessary for collection
|
|
23
|
+
* aliases whose element type wasn't available first time through)
|
|
24
|
+
* - `pythonClassName` / `pythonClientType`
|
|
25
|
+
* - `requestShape.inputs[*].pythonName` / `.pythonAnnotation` (kwargs)
|
|
26
|
+
* - `errorShape.exceptionClassName` / `.unionTypeName` / per-entry names
|
|
27
|
+
* - `pythonMethodName` per operation and `pythonTagNames` per tag, escaped
|
|
28
|
+
* clear of the members the generated client defines
|
|
29
|
+
*
|
|
30
|
+
* Called by the py-client generator rather than from the shared pipeline, so a
|
|
31
|
+
* TypeScript consumer of the same spec never pays for fields only the Python
|
|
32
|
+
* templates read — the same split as {@link assertNoClashingPythonNames}.
|
|
33
|
+
*/
|
|
34
|
+
export declare const annotatePythonData: (data: CodeGenData) => void;
|
|
35
|
+
/**
|
|
36
|
+
* The Python counterpart of {@link assertNoClashingPropertyNames}, run over the
|
|
37
|
+
* flattened property list an `all-of` composite emits. Called by the Python
|
|
38
|
+
* generator rather than the shared pipeline, so a TypeScript consumer is never
|
|
39
|
+
* failed by a Python-specific name clash. Two members whose wire
|
|
40
|
+
* names snake_case alike (`fooBar` and `foo_bar`) would emit the same field
|
|
41
|
+
* twice, silently keeping only the last, so fail fast instead.
|
|
42
|
+
*
|
|
43
|
+
* A model's own properties are checked as well as the flattened list. The
|
|
44
|
+
* TypeScript assertion does not cover them: escaping a keyword makes `from` and
|
|
45
|
+
* `var_from` distinct in TypeScript (`from`/`varFrom`) but identical in Python,
|
|
46
|
+
* so the class emitted the same field twice and pydantic kept only the last —
|
|
47
|
+
* binding the wire value to the wrong type.
|
|
48
|
+
*/
|
|
49
|
+
export declare const assertNoClashingPythonNames: (model: Model) => void;
|