@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
|
@@ -83,15 +83,181 @@ export const toTypeScriptModelName = (name)=>{
|
|
|
83
83
|
// Prepend underscore for any reserved model names
|
|
84
84
|
return TYPESCRIPT_RESERVED_MODEL_NAMES.has(candidateName) ? `_${candidateName}` : candidateName;
|
|
85
85
|
};
|
|
86
|
+
/** Python types that are built-ins and do not need forward-ref quoting. */ const PYTHON_BUILTIN_TYPES = new Set([
|
|
87
|
+
'str',
|
|
88
|
+
'int',
|
|
89
|
+
'float',
|
|
90
|
+
'bool',
|
|
91
|
+
'bytes',
|
|
92
|
+
'None',
|
|
93
|
+
'Any',
|
|
94
|
+
'datetime.date',
|
|
95
|
+
'datetime.datetime'
|
|
96
|
+
]);
|
|
97
|
+
/**
|
|
98
|
+
* Every class-cased Python builtin, checked against `dir(builtins)` by a test.
|
|
99
|
+
*
|
|
100
|
+
* A schema of the same name is emitted as a class that shadows the builtin only
|
|
101
|
+
* from its own definition onwards, so an annotation rendered above it resolves to
|
|
102
|
+
* the builtin — a `types.py` that does not import, and whether it happens depends
|
|
103
|
+
* on where the schema sorts.
|
|
104
|
+
*/ export const PYTHON_CLASS_CASED_BUILTINS = [
|
|
105
|
+
'ArithmeticError',
|
|
106
|
+
'AssertionError',
|
|
107
|
+
'AttributeError',
|
|
108
|
+
'BaseException',
|
|
109
|
+
'BaseExceptionGroup',
|
|
110
|
+
'BlockingIOError',
|
|
111
|
+
'BrokenPipeError',
|
|
112
|
+
'BufferError',
|
|
113
|
+
'BytesWarning',
|
|
114
|
+
'ChildProcessError',
|
|
115
|
+
'ConnectionAbortedError',
|
|
116
|
+
'ConnectionError',
|
|
117
|
+
'ConnectionRefusedError',
|
|
118
|
+
'ConnectionResetError',
|
|
119
|
+
'DeprecationWarning',
|
|
120
|
+
'EOFError',
|
|
121
|
+
'Ellipsis',
|
|
122
|
+
'EncodingWarning',
|
|
123
|
+
'EnvironmentError',
|
|
124
|
+
'Exception',
|
|
125
|
+
'ExceptionGroup',
|
|
126
|
+
'False',
|
|
127
|
+
'FileExistsError',
|
|
128
|
+
'FileNotFoundError',
|
|
129
|
+
'FloatingPointError',
|
|
130
|
+
'FutureWarning',
|
|
131
|
+
'GeneratorExit',
|
|
132
|
+
'IOError',
|
|
133
|
+
'ImportError',
|
|
134
|
+
'ImportWarning',
|
|
135
|
+
'IndentationError',
|
|
136
|
+
'IndexError',
|
|
137
|
+
'InterruptedError',
|
|
138
|
+
'IsADirectoryError',
|
|
139
|
+
'KeyError',
|
|
140
|
+
'KeyboardInterrupt',
|
|
141
|
+
'LookupError',
|
|
142
|
+
'MemoryError',
|
|
143
|
+
'ModuleNotFoundError',
|
|
144
|
+
'NameError',
|
|
145
|
+
'None',
|
|
146
|
+
'NotADirectoryError',
|
|
147
|
+
'NotImplemented',
|
|
148
|
+
'NotImplementedError',
|
|
149
|
+
'OSError',
|
|
150
|
+
'OverflowError',
|
|
151
|
+
'PendingDeprecationWarning',
|
|
152
|
+
'PermissionError',
|
|
153
|
+
'ProcessLookupError',
|
|
154
|
+
'PythonFinalizationError',
|
|
155
|
+
'RecursionError',
|
|
156
|
+
'ReferenceError',
|
|
157
|
+
'ResourceWarning',
|
|
158
|
+
'RuntimeError',
|
|
159
|
+
'RuntimeWarning',
|
|
160
|
+
'StopAsyncIteration',
|
|
161
|
+
'StopIteration',
|
|
162
|
+
'SyntaxError',
|
|
163
|
+
'SyntaxWarning',
|
|
164
|
+
'SystemError',
|
|
165
|
+
'SystemExit',
|
|
166
|
+
'TabError',
|
|
167
|
+
'TimeoutError',
|
|
168
|
+
'True',
|
|
169
|
+
'TypeError',
|
|
170
|
+
'UnboundLocalError',
|
|
171
|
+
'UnicodeDecodeError',
|
|
172
|
+
'UnicodeEncodeError',
|
|
173
|
+
'UnicodeError',
|
|
174
|
+
'UnicodeTranslateError',
|
|
175
|
+
'UnicodeWarning',
|
|
176
|
+
'UserWarning',
|
|
177
|
+
'ValueError',
|
|
178
|
+
'Warning',
|
|
179
|
+
'ZeroDivisionError'
|
|
180
|
+
];
|
|
181
|
+
/**
|
|
182
|
+
* Names that the generated `types.py` and client modules import or define
|
|
183
|
+
* at module scope. A user-defined schema named `Field`, `Optional`, etc.
|
|
184
|
+
* would shadow these imports and either break forward-ref resolution
|
|
185
|
+
* (`Optional["Field"]` resolves to `pydantic.Field` without escaping) or
|
|
186
|
+
* silently produce invalid runtime types.
|
|
187
|
+
*
|
|
188
|
+
* Keep this aligned with the imports at the top of:
|
|
189
|
+
* - open-api/py-client/files/shared/types.py.template
|
|
190
|
+
* - open-api/py-client/files/client/__clientModuleName__.py.template
|
|
191
|
+
*/ const PYTHON_RESERVED_MODEL_NAMES = new Set([
|
|
192
|
+
// typing module
|
|
193
|
+
'Annotated',
|
|
194
|
+
'Any',
|
|
195
|
+
'Literal',
|
|
196
|
+
'Never',
|
|
197
|
+
'Optional',
|
|
198
|
+
'TypedDict',
|
|
199
|
+
'Union',
|
|
200
|
+
// pydantic
|
|
201
|
+
'BaseModel',
|
|
202
|
+
'ConfigDict',
|
|
203
|
+
'Field',
|
|
204
|
+
'TypeAdapter',
|
|
205
|
+
// stdlib modules referenced in templates
|
|
206
|
+
'Iterator',
|
|
207
|
+
'AsyncIterator',
|
|
208
|
+
// typing/python builtins that would also shadow primitives
|
|
209
|
+
'None',
|
|
210
|
+
'True',
|
|
211
|
+
'False',
|
|
212
|
+
'Type',
|
|
213
|
+
// namespace import in client.py — never let a user model collide
|
|
214
|
+
'types',
|
|
215
|
+
// base exception we emit
|
|
216
|
+
'ApiError',
|
|
217
|
+
// Every class-cased Python builtin, because a class of the same name shadows
|
|
218
|
+
// one only *after* its own definition. `from __future__ import annotations`
|
|
219
|
+
// defers every annotation to module scope, so a reference emitted above the
|
|
220
|
+
// class resolves to the builtin instead — and which of the two wins depends on
|
|
221
|
+
// the order the schemas happen to sort in. A published spec with a schema named
|
|
222
|
+
// `Exception` produced a `types.py` that could not be imported at all.
|
|
223
|
+
//
|
|
224
|
+
// Listed in full rather than by the names seen to break: the set is fixed and
|
|
225
|
+
// small, and a test asserts it against `dir(builtins)` so a new one is caught.
|
|
226
|
+
...PYTHON_CLASS_CASED_BUILTINS
|
|
227
|
+
]);
|
|
228
|
+
/**
|
|
229
|
+
* Return the Python class name for a model. Starts from the TypeScript
|
|
230
|
+
* escape (which already handles TS-reserved names like `Error` → `_Error`)
|
|
231
|
+
* and additionally escapes names that would shadow imports in the generated
|
|
232
|
+
* Python files.
|
|
233
|
+
*/ export const toPythonClassName = (name)=>{
|
|
234
|
+
const tsName = toTypeScriptModelName(name);
|
|
235
|
+
// A class name is an identifier too. An operationId like `42` or `1stOperation`
|
|
236
|
+
// renders a name beginning with a digit, and one written entirely in
|
|
237
|
+
// punctuation (`___`) or another script renders nothing at all — an empty
|
|
238
|
+
// prefix would name an operation's error class after the base class it derives
|
|
239
|
+
// from, silently reparenting every class emitted after it. Encoding the raw
|
|
240
|
+
// name's code points keeps it distinct rather than positional, matching how
|
|
241
|
+
// {@link toPythonName} escapes the same names.
|
|
242
|
+
const identifier = tsName ? /^\d/.test(tsName) ? `N${tsName}` : tsName : `U${encodeCodePoints(name)}`;
|
|
243
|
+
return PYTHON_RESERVED_MODEL_NAMES.has(identifier) ? `_${identifier}` : identifier;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Whether the rendered name is a Python built-in rather than a reference to a
|
|
247
|
+
* generated class. Only bare names reach here — a structured type is described
|
|
248
|
+
* by {@link PythonType} instead of being matched on its spelling.
|
|
249
|
+
*/ const isPythonBuiltinName = (name)=>!name || PYTHON_BUILTIN_TYPES.has(name);
|
|
86
250
|
const toPythonPrimitive = (property)=>{
|
|
87
251
|
if (property.type === 'string' && property.format === 'date') {
|
|
88
|
-
return 'date';
|
|
252
|
+
return 'datetime.date';
|
|
89
253
|
} else if (property.type === 'string' && property.format === 'date-time') {
|
|
90
|
-
return 'datetime';
|
|
91
|
-
} else if (property.type === 'any') {
|
|
92
|
-
return '
|
|
254
|
+
return 'datetime.datetime';
|
|
255
|
+
} else if (property.type === 'any' || property.type === 'unknown') {
|
|
256
|
+
return 'Any';
|
|
93
257
|
} else if (property.type === 'binary') {
|
|
94
|
-
return '
|
|
258
|
+
return 'bytes';
|
|
259
|
+
} else if (property.type === 'null' || property.type === 'void') {
|
|
260
|
+
return 'None';
|
|
95
261
|
} else if (property.type === 'number') {
|
|
96
262
|
if (property.openapiType === 'integer') {
|
|
97
263
|
return 'int';
|
|
@@ -105,38 +271,197 @@ const toPythonPrimitive = (property)=>{
|
|
|
105
271
|
default:
|
|
106
272
|
return 'float';
|
|
107
273
|
}
|
|
274
|
+
} else if (property.type === 'integer') {
|
|
275
|
+
return 'int';
|
|
108
276
|
} else if (property.type === 'boolean') {
|
|
109
277
|
return 'bool';
|
|
110
278
|
} else if (property.type === 'string') {
|
|
111
279
|
return 'str';
|
|
112
280
|
}
|
|
113
|
-
|
|
281
|
+
// Fall-through is a user-defined model reference. The py-client emits
|
|
282
|
+
// classes using `pythonClassName`, so references use the same escaped form.
|
|
283
|
+
return toPythonClassName(property.type);
|
|
114
284
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Render a value as a Python literal expression: a quoted string with anything
|
|
287
|
+
* that would break out of the quotes escaped, `None` for null, and the bare
|
|
288
|
+
* value for numbers.
|
|
289
|
+
*/ export const toPythonLiteral = (value)=>{
|
|
290
|
+
if (typeof value === 'string') {
|
|
291
|
+
// Backslash first, so the escapes added below aren't escaped again.
|
|
292
|
+
const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t');
|
|
293
|
+
return `"${escaped}"`;
|
|
294
|
+
}
|
|
295
|
+
if (value === null || value === undefined) return 'None';
|
|
296
|
+
if (typeof value === 'boolean') return value ? 'True' : 'False';
|
|
297
|
+
return String(value);
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* A discriminated subtype's tag values. `discriminatorValue` is stored as
|
|
301
|
+
* rendered TypeScript literals (e.g. `"cat" | "kitten"`), which are already in
|
|
302
|
+
* Python's literal spelling.
|
|
303
|
+
*/ const pythonDiscriminatorValues = (discriminatorValue)=>discriminatorValue.split(' | ');
|
|
304
|
+
/** An enum's members as Python literal expressions. */ const pythonEnumValues = (property)=>(property.enum ?? []).map((member)=>toPythonLiteral(member.value));
|
|
305
|
+
/**
|
|
306
|
+
* The Python type of a collection's element. An enum element (anonymous or
|
|
307
|
+
* referenced) becomes a `Literal[...]` so callers can't pass a value outside
|
|
308
|
+
* the set.
|
|
309
|
+
*/ const pythonCollectionElementType = (property, link)=>{
|
|
310
|
+
if (link?.export === 'enum') {
|
|
311
|
+
return {
|
|
312
|
+
kind: 'literal',
|
|
313
|
+
values: pythonEnumValues(link)
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (link) {
|
|
317
|
+
return nullableMemberType(link, toPythonTypeTree(link));
|
|
318
|
+
}
|
|
319
|
+
// No link, but the collection itself carries the enum members (an inline
|
|
320
|
+
// enum array or dictionary).
|
|
321
|
+
if (property.isEnum && property.enum.length > 0) {
|
|
322
|
+
return {
|
|
323
|
+
kind: 'literal',
|
|
324
|
+
values: pythonEnumValues(property)
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
return pythonPrimitiveType(property);
|
|
328
|
+
};
|
|
329
|
+
/** A primitive or model reference as a structured type. */ const pythonPrimitiveType = (property)=>{
|
|
330
|
+
const name = toPythonPrimitive(property);
|
|
331
|
+
return isPythonBuiltinName(name) ? {
|
|
332
|
+
kind: 'builtin',
|
|
333
|
+
name
|
|
334
|
+
} : {
|
|
335
|
+
kind: 'reference',
|
|
336
|
+
name
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* A collection member's type, admitting `None` when the member is nullable.
|
|
341
|
+
*
|
|
342
|
+
* The member's own nullability is not the collection's: `list[str | None]` is a
|
|
343
|
+
* list that is always present whose items may be null. Dropping it made a valid
|
|
344
|
+
* response containing `null` fail to parse. TypeScript applies the same rule via
|
|
345
|
+
* its own member renderer.
|
|
346
|
+
*/ const nullableMemberType = (member, rendered)=>member.isNullable && member.type !== 'null' ? {
|
|
347
|
+
kind: 'optional',
|
|
348
|
+
inner: rendered
|
|
349
|
+
} : rendered;
|
|
350
|
+
/**
|
|
351
|
+
* The Python type of a property, as a tree.
|
|
352
|
+
*
|
|
353
|
+
* This is the single place a model's Python type is derived. Consumers that
|
|
354
|
+
* need to know what a type is — a collection, a class reference, a literal —
|
|
355
|
+
* inspect the tree rather than the rendered string, and render it with
|
|
356
|
+
* {@link renderPythonType} when they need source text.
|
|
357
|
+
*/ export const toPythonTypeTree = (property)=>{
|
|
358
|
+
if (property.discriminatorValue) {
|
|
359
|
+
return {
|
|
360
|
+
kind: 'literal',
|
|
361
|
+
values: pythonDiscriminatorValues(property.discriminatorValue)
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
const link = property.link ?? undefined;
|
|
118
365
|
switch(property.export){
|
|
366
|
+
case 'enum':
|
|
367
|
+
return property.enum?.length ? {
|
|
368
|
+
kind: 'literal',
|
|
369
|
+
values: pythonEnumValues(property)
|
|
370
|
+
} : pythonPrimitiveType(property);
|
|
119
371
|
case 'generic':
|
|
120
372
|
case 'reference':
|
|
121
|
-
return
|
|
373
|
+
return pythonPrimitiveType(property);
|
|
122
374
|
case 'array':
|
|
123
|
-
return
|
|
375
|
+
return {
|
|
376
|
+
kind: 'list',
|
|
377
|
+
element: pythonCollectionElementType(property, link)
|
|
378
|
+
};
|
|
124
379
|
case 'tuple':
|
|
125
|
-
return
|
|
380
|
+
return {
|
|
381
|
+
kind: 'tuple',
|
|
382
|
+
members: property.properties.map((member)=>nullableMemberType(member, toPythonTypeTree(member)))
|
|
383
|
+
};
|
|
126
384
|
case 'dictionary':
|
|
127
|
-
return
|
|
385
|
+
return {
|
|
386
|
+
kind: 'dict',
|
|
387
|
+
value: pythonCollectionElementType(property, link)
|
|
388
|
+
};
|
|
128
389
|
case 'one-of':
|
|
129
390
|
case 'any-of':
|
|
130
391
|
case 'all-of':
|
|
131
|
-
return
|
|
392
|
+
return {
|
|
393
|
+
kind: 'reference',
|
|
394
|
+
name: toPythonClassName(property.name)
|
|
395
|
+
};
|
|
132
396
|
default:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
397
|
+
{
|
|
398
|
+
// "any"/"unknown" has export = interface — route to the primitive path so
|
|
399
|
+
// they become `Any` rather than being treated as a model reference.
|
|
400
|
+
if (PRIMITIVE_TYPES.has(property.type) || property.type === 'unknown') {
|
|
401
|
+
return pythonPrimitiveType(property);
|
|
402
|
+
}
|
|
403
|
+
const name = toPythonClassName(property.type);
|
|
404
|
+
return isPythonBuiltinName(name) ? {
|
|
405
|
+
kind: 'builtin',
|
|
406
|
+
name
|
|
407
|
+
} : {
|
|
408
|
+
kind: 'reference',
|
|
409
|
+
name
|
|
410
|
+
};
|
|
136
411
|
}
|
|
137
|
-
return property.type;
|
|
138
412
|
}
|
|
139
413
|
};
|
|
414
|
+
/** Render a structured Python type as source text. */ export const renderPythonType = (type, options = {})=>{
|
|
415
|
+
const render = (t)=>{
|
|
416
|
+
switch(t.kind){
|
|
417
|
+
case 'builtin':
|
|
418
|
+
return t.name;
|
|
419
|
+
case 'reference':
|
|
420
|
+
{
|
|
421
|
+
const qualified = `${options.prefix ?? ''}${t.name}`;
|
|
422
|
+
return options.forwardRef ? `"${qualified}"` : qualified;
|
|
423
|
+
}
|
|
424
|
+
case 'literal':
|
|
425
|
+
return `Literal[${t.values.join(', ')}]`;
|
|
426
|
+
case 'list':
|
|
427
|
+
return `list[${render(t.element)}]`;
|
|
428
|
+
case 'dict':
|
|
429
|
+
return `dict[str, ${render(t.value)}]`;
|
|
430
|
+
case 'tuple':
|
|
431
|
+
return `tuple[${t.members.map(render).join(', ')}]`;
|
|
432
|
+
case 'optional':
|
|
433
|
+
{
|
|
434
|
+
// PEP 604, which is what the ruff rules generated Python projects vend
|
|
435
|
+
// (`UP045`) require, and what every other Python template here emits.
|
|
436
|
+
const inner = render(t.inner);
|
|
437
|
+
return inner === 'None' ? inner : `${inner} | None`;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
return render(type);
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Return the idiomatic Python type for a given property.
|
|
445
|
+
*
|
|
446
|
+
* Uses PEP-585 lower-case generics (`list[...]`, `dict[str, ...]`), fully-
|
|
447
|
+
* qualified stdlib types (`datetime.date`, `datetime.datetime`), `bytes` for
|
|
448
|
+
* binary payloads, and `Literal[...]` for enums. Model references are
|
|
449
|
+
* returned as bare class names — callers that emit the type inside a class
|
|
450
|
+
* body (where the class isn't yet defined) should use `toPythonAnnotation`
|
|
451
|
+
* instead to get forward-ref quoting.
|
|
452
|
+
*/ export const toPythonType = (property)=>renderPythonType(toPythonTypeTree(property));
|
|
453
|
+
/**
|
|
454
|
+
* Render a type with every class reference prefixed with the given namespace,
|
|
455
|
+
* so a client module can reach the types module through a single import.
|
|
456
|
+
*/ export const qualifyPythonType = (type, prefix)=>type ? renderPythonType(type, {
|
|
457
|
+
prefix
|
|
458
|
+
}) : 'Any';
|
|
459
|
+
/**
|
|
460
|
+
* Same as `toPythonType`, but wraps class references in forward-ref quotes so
|
|
461
|
+
* they can be used inside a class body before the class is defined.
|
|
462
|
+
*/ export const toPythonAnnotation = (property)=>renderPythonType(toPythonTypeTree(property), {
|
|
463
|
+
forwardRef: true
|
|
464
|
+
});
|
|
140
465
|
// @see https://github.com/OpenAPITools/openapi-generator/blob/e2a62ace74de361bef6338b7fa37da8577242aef/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L106
|
|
141
466
|
const PYTHON_KEYWORDS = new Set([
|
|
142
467
|
// @property
|
|
@@ -187,17 +512,104 @@ const PYTHON_KEYWORDS = new Set([
|
|
|
187
512
|
'async',
|
|
188
513
|
'await'
|
|
189
514
|
]);
|
|
515
|
+
/**
|
|
516
|
+
* Names the emitted annotations refer to, so binding one shadows the type it
|
|
517
|
+
* names within the scope the annotation is evaluated in.
|
|
518
|
+
*
|
|
519
|
+
* For a keyword argument the local wins before a `TypeAdapter(list[...])`
|
|
520
|
+
* annotation is evaluated, and the call fails with a `TypeError`. For a pydantic
|
|
521
|
+
* field it is worse: the class body binds the name to the field default, and
|
|
522
|
+
* because `types.py` carries `from __future__ import annotations` every
|
|
523
|
+
* annotation on the class is evaluated in that namespace — so one field named
|
|
524
|
+
* `str` makes a sibling's `str | None` unresolvable and the module cannot be
|
|
525
|
+
* imported at all. `datetime` is the module the date annotations qualify.
|
|
526
|
+
*/ const PYTHON_TYPE_SCOPE_NAMES = new Set([
|
|
527
|
+
// The module every generated annotation qualifies a model through. A kwarg of
|
|
528
|
+
// this name shadowed it in the method's own return annotation, so the call
|
|
529
|
+
// raised `AttributeError` on the caller's value — after the module imported and
|
|
530
|
+
// with the request itself going out correctly.
|
|
531
|
+
'types',
|
|
532
|
+
'bool',
|
|
533
|
+
'bytes',
|
|
534
|
+
'datetime',
|
|
535
|
+
'dict',
|
|
536
|
+
'float',
|
|
537
|
+
'int',
|
|
538
|
+
'list',
|
|
539
|
+
'set',
|
|
540
|
+
'str',
|
|
541
|
+
'tuple',
|
|
542
|
+
'type'
|
|
543
|
+
]);
|
|
544
|
+
/**
|
|
545
|
+
* Names the generated client's method bodies bind, in the same scope as an
|
|
546
|
+
* operation's keyword arguments.
|
|
547
|
+
*
|
|
548
|
+
* A kwarg sharing one of these is not merely shadowed — the method assigns its
|
|
549
|
+
* own local over the caller's value, so internal state is serialised onto the
|
|
550
|
+
* wire (a body field named `header_params` was sent as `{}`). Escaped like a
|
|
551
|
+
* keyword, since the wire name is preserved by the field alias either way.
|
|
552
|
+
*
|
|
553
|
+
* Locals of the private helpers are excluded — those take their own parameters
|
|
554
|
+
* and never share a scope with an operation's arguments — as are `body` and
|
|
555
|
+
* `response`, the generator's own names for the whole body and the response,
|
|
556
|
+
* which are assigned after the request is built.
|
|
557
|
+
*/ const PYTHON_METHOD_SCOPE_NAMES = new Set([
|
|
558
|
+
'cookie_params',
|
|
559
|
+
'header_formats',
|
|
560
|
+
'header_params',
|
|
561
|
+
'path_params',
|
|
562
|
+
'path_styles',
|
|
563
|
+
'query_formats',
|
|
564
|
+
'query_params',
|
|
565
|
+
'request_kwargs'
|
|
566
|
+
]);
|
|
567
|
+
/**
|
|
568
|
+
* Names pydantic reserves on a `BaseModel`. A field called `model_dump` or
|
|
569
|
+
* `model_config` would either shadow the method callers rely on or replace the
|
|
570
|
+
* `ConfigDict` the generated class sets, so they are escaped like a keyword.
|
|
571
|
+
*
|
|
572
|
+
* `model_` is pydantic's protected namespace, so anything in it is escaped
|
|
573
|
+
* rather than only the members that exist today.
|
|
574
|
+
*/ const isPydanticReservedName = (name)=>name.startsWith('model_') || name === 'model_fields' || name === 'schema';
|
|
575
|
+
/**
|
|
576
|
+
* A name's non-alphanumeric characters replaced by their code points, so a name
|
|
577
|
+
* that would otherwise escape to nothing keeps a distinct, stable spelling: two
|
|
578
|
+
* such names never collide and the same spec always renders the same way.
|
|
579
|
+
*/ const encodeCodePoints = (name)=>Array.from(name).map((ch)=>/[a-zA-Z0-9]/.test(ch) ? ch : ch.codePointAt(0).toString(16)).join('').toLowerCase();
|
|
580
|
+
/**
|
|
581
|
+
* A snake_case name that is a usable Python identifier.
|
|
582
|
+
*
|
|
583
|
+
* `snakeCase` keeps only alphanumerics, so a name written in another script
|
|
584
|
+
* yields the empty string and one beginning with a digit is not an identifier at
|
|
585
|
+
* all. Either would emit code that does not parse, so the name falls back to
|
|
586
|
+
* {@link encodeCodePoints} rather than to a positional name.
|
|
587
|
+
*/ const toPythonIdentifier = (name)=>{
|
|
588
|
+
const snake = snakeCase(name);
|
|
589
|
+
if (snake && !/^\d/.test(snake)) {
|
|
590
|
+
return snake;
|
|
591
|
+
}
|
|
592
|
+
return snake ? `n_${snake}` : `u_${encodeCodePoints(name)}`;
|
|
593
|
+
};
|
|
190
594
|
export const toPythonName = (namedEntity, name)=>{
|
|
191
|
-
const nameSnakeCase =
|
|
595
|
+
const nameSnakeCase = toPythonIdentifier(name);
|
|
192
596
|
// Names overlapping a TypeScript reserved word carry a leading `_`; strip it
|
|
193
|
-
// before testing against the Python keyword set.
|
|
194
|
-
|
|
597
|
+
// before testing against the Python keyword set. Also test the snake-cased
|
|
598
|
+
// form — snakeCase strips trailing underscores, so `from_` becomes `from`
|
|
599
|
+
// and would otherwise slip through.
|
|
600
|
+
const rawStripped = name.startsWith('_') ? name.slice(1) : name;
|
|
601
|
+
const isPydanticReserved = namedEntity === 'property' && (isPydanticReservedName(rawStripped) || isPydanticReservedName(nameSnakeCase));
|
|
602
|
+
if (isPydanticReserved || PYTHON_KEYWORDS.has(rawStripped) || PYTHON_KEYWORDS.has(nameSnakeCase) || // A method argument and a model field both share a scope with the names the
|
|
603
|
+
// emitted annotations refer to; only an argument also shares one with the
|
|
604
|
+
// client's own locals.
|
|
605
|
+
(namedEntity === 'argument' || namedEntity === 'property') && PYTHON_TYPE_SCOPE_NAMES.has(nameSnakeCase) || namedEntity === 'argument' && PYTHON_METHOD_SCOPE_NAMES.has(nameSnakeCase)) {
|
|
195
606
|
const nameSuffix = `_${nameSnakeCase}`;
|
|
196
607
|
switch(namedEntity){
|
|
197
608
|
case 'model':
|
|
198
609
|
return `model${nameSuffix}`;
|
|
199
610
|
case 'operation':
|
|
200
611
|
return `call${nameSuffix}`;
|
|
612
|
+
case 'argument':
|
|
201
613
|
case 'property':
|
|
202
614
|
return `var${nameSuffix}`;
|
|
203
615
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/open-api/utils/codegen-data/languages.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { camelCase, snakeCase, toClassName } from '../../../utils/names.js';\nimport { type Model, PRIMITIVE_TYPES } from './types.js';\n\nconst toTypescriptPrimitive = (property: Model): string => {\n if (\n property.type === 'string' &&\n ['date', 'date-time'].includes(property.format ?? '')\n ) {\n return 'Date';\n } else if (property.type === 'binary') {\n return 'Blob';\n }\n return property.type;\n};\n\n// A nullable tuple member renders as a union with null.\nconst memberType = (rendered: string, member: Model): string =>\n member.isNullable && member.type !== 'null' ? `${rendered} | null` : rendered;\n\nexport const toTypeScriptType = (property: Model): string => {\n // A discriminated subtype's discriminator property renders as its literal\n // tag, making the union a true (narrowable) tagged union.\n if (property.discriminatorValue) {\n return property.discriminatorValue;\n }\n const link = property.link;\n // Enum links serialise as their primitive; use the model's own type instead.\n const valueType = () =>\n link && link.export !== 'enum' ? toTypeScriptType(link) : property.type;\n switch (property.export) {\n case 'enum':\n case 'generic':\n return toTypescriptPrimitive(property);\n case 'array':\n return `Array<${valueType()}>`;\n case 'tuple':\n return `[${property.properties\n .map((member) => memberType(toTypeScriptType(member), member))\n .join(', ')}]`;\n case 'dictionary':\n return `{ [key: string]: ${valueType()}; }`;\n case 'one-of':\n case 'any-of':\n case 'all-of':\n return toTypeScriptModelName(property.name);\n case 'reference':\n default:\n if (property.type === 'unknown') {\n return 'unknown';\n }\n if (PRIMITIVE_TYPES.has(property.type)) {\n return toTypescriptPrimitive(property);\n }\n return toTypeScriptModelName(property.type);\n }\n};\n\nexport const toTypeScriptName = (name: string): string => {\n // A name of only non-identifier characters (e.g. \"_\") camelCases to an empty\n // string; fall back to an underscore so the emitted property stays valid.\n return camelCase(name) || (name ?? '').replace(/[^a-zA-Z0-9]/g, '_') || '_';\n};\n\nconst TYPESCRIPT_RESERVED_MODEL_NAMES = new Set([\n 'Date',\n 'Blob',\n 'Object',\n 'String',\n 'Boolean',\n 'Integer',\n 'Long',\n 'Float',\n 'Array',\n 'ReadonlyArray',\n 'File',\n 'Error',\n 'Map',\n 'Set',\n 'Number',\n 'Symbol',\n 'BigInt',\n 'Function',\n 'Promise',\n 'RegExp',\n 'JSON',\n]);\n\nexport const toTypeScriptModelName = (name: string): string => {\n const candidateName = toClassName(name);\n\n // Prepend underscore for any reserved model names\n return TYPESCRIPT_RESERVED_MODEL_NAMES.has(candidateName)\n ? `_${candidateName}`\n : candidateName;\n};\n\nconst toPythonPrimitive = (property: Model): string => {\n if (property.type === 'string' && property.format === 'date') {\n return 'date';\n } else if (property.type === 'string' && property.format === 'date-time') {\n return 'datetime';\n } else if (property.type === 'any') {\n return 'object';\n } else if (property.type === 'binary') {\n return 'bytearray';\n } else if (property.type === 'number') {\n if (property.openapiType === 'integer') {\n return 'int';\n }\n\n switch (property.format) {\n case 'int32':\n case 'int64':\n return 'int';\n case 'float':\n case 'double':\n default:\n return 'float';\n }\n } else if (property.type === 'boolean') {\n return 'bool';\n } else if (property.type === 'string') {\n return 'str';\n }\n return property.type;\n};\n\nexport const toPythonType = (property: Model): string => {\n const link = property.link;\n const valueType = () =>\n link && link.export !== 'enum' ? toPythonType(link) : property.type;\n switch (property.export) {\n case 'generic':\n case 'reference':\n return toPythonPrimitive(property);\n case 'array':\n return `List[${valueType()}]`;\n case 'tuple':\n return `Tuple[${property.properties\n .map((member) => toPythonType(member))\n .join(', ')}]`;\n case 'dictionary':\n return `Dict[str, ${valueType()}]`;\n case 'one-of':\n case 'any-of':\n case 'all-of':\n return property.name;\n default:\n // \"any\" has export = interface\n if (PRIMITIVE_TYPES.has(property.type)) {\n return toPythonPrimitive(property);\n }\n return property.type;\n }\n};\n\n// @see https://github.com/OpenAPITools/openapi-generator/blob/e2a62ace74de361bef6338b7fa37da8577242aef/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L106\nconst PYTHON_KEYWORDS = new Set([\n // @property\n 'property',\n // typing keywords\n 'schema',\n 'base64',\n 'json',\n 'date',\n 'float',\n // python reserved words\n 'and',\n 'del',\n 'from',\n 'not',\n 'while',\n 'as',\n 'elif',\n 'global',\n 'or',\n 'with',\n 'assert',\n 'else',\n 'if',\n 'pass',\n 'yield',\n 'break',\n 'except',\n 'import',\n 'print',\n 'class',\n 'exec',\n 'in',\n 'raise',\n 'continue',\n 'finally',\n 'is',\n 'return',\n 'def',\n 'for',\n 'lambda',\n 'try',\n 'self',\n 'nonlocal',\n 'None',\n 'True',\n 'False',\n 'async',\n 'await',\n]);\n\nexport const toPythonName = (\n namedEntity: 'model' | 'property' | 'operation',\n name: string,\n) => {\n const nameSnakeCase = snakeCase(name);\n\n // Names overlapping a TypeScript reserved word carry a leading `_`; strip it\n // before testing against the Python keyword set.\n if (PYTHON_KEYWORDS.has(name.startsWith('_') ? name.slice(1) : name)) {\n const nameSuffix = `_${nameSnakeCase}`;\n switch (namedEntity) {\n case 'model':\n return `model${nameSuffix}`;\n case 'operation':\n return `call${nameSuffix}`;\n case 'property':\n return `var${nameSuffix}`;\n default:\n break;\n }\n }\n return nameSnakeCase;\n};\n"],"names":["camelCase","snakeCase","toClassName","PRIMITIVE_TYPES","toTypescriptPrimitive","property","type","includes","format","memberType","rendered","member","isNullable","toTypeScriptType","discriminatorValue","link","valueType","export","properties","map","join","toTypeScriptModelName","name","has","toTypeScriptName","replace","TYPESCRIPT_RESERVED_MODEL_NAMES","Set","candidateName","toPythonPrimitive","openapiType","toPythonType","PYTHON_KEYWORDS","toPythonName","namedEntity","nameSnakeCase","startsWith","slice","nameSuffix"],"mappings":"AAAA;;;CAGC,GAED,SAASA,SAAS,EAAEC,SAAS,EAAEC,WAAW,QAAQ,0BA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,CAAC,KAAK,EAAEI,YAAY;YAC7B,KAAK;gBACH,OAAO,CAAC,IAAI,EAAEA,YAAY;YAC5B,KAAK;gBACH,OAAO,CAAC,GAAG,EAAEA,YAAY;YAC3B;gBACE;QACJ;IACF;IACA,OAAOH;AACT,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/open-api/utils/codegen-data/languages.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { camelCase, snakeCase, toClassName } from '../../../utils/names.js';\nimport { type Model, PRIMITIVE_TYPES, type PythonType } from './types.js';\n\nconst toTypescriptPrimitive = (property: Model): string => {\n if (\n property.type === 'string' &&\n ['date', 'date-time'].includes(property.format ?? '')\n ) {\n return 'Date';\n } else if (property.type === 'binary') {\n return 'Blob';\n }\n return property.type;\n};\n\n// A nullable tuple member renders as a union with null.\nconst memberType = (rendered: string, member: Model): string =>\n member.isNullable && member.type !== 'null' ? `${rendered} | null` : rendered;\n\nexport const toTypeScriptType = (property: Model): string => {\n // A discriminated subtype's discriminator property renders as its literal\n // tag, making the union a true (narrowable) tagged union.\n if (property.discriminatorValue) {\n return property.discriminatorValue;\n }\n const link = property.link;\n // Enum links serialise as their primitive; use the model's own type instead.\n const valueType = () =>\n link && link.export !== 'enum' ? toTypeScriptType(link) : property.type;\n switch (property.export) {\n case 'enum':\n case 'generic':\n return toTypescriptPrimitive(property);\n case 'array':\n return `Array<${valueType()}>`;\n case 'tuple':\n return `[${property.properties\n .map((member) => memberType(toTypeScriptType(member), member))\n .join(', ')}]`;\n case 'dictionary':\n return `{ [key: string]: ${valueType()}; }`;\n case 'one-of':\n case 'any-of':\n case 'all-of':\n return toTypeScriptModelName(property.name);\n case 'reference':\n default:\n if (property.type === 'unknown') {\n return 'unknown';\n }\n if (PRIMITIVE_TYPES.has(property.type)) {\n return toTypescriptPrimitive(property);\n }\n return toTypeScriptModelName(property.type);\n }\n};\n\nexport const toTypeScriptName = (name: string): string => {\n // A name of only non-identifier characters (e.g. \"_\") camelCases to an empty\n // string; fall back to an underscore so the emitted property stays valid.\n return camelCase(name) || (name ?? '').replace(/[^a-zA-Z0-9]/g, '_') || '_';\n};\n\nconst TYPESCRIPT_RESERVED_MODEL_NAMES = new Set([\n 'Date',\n 'Blob',\n 'Object',\n 'String',\n 'Boolean',\n 'Integer',\n 'Long',\n 'Float',\n 'Array',\n 'ReadonlyArray',\n 'File',\n 'Error',\n 'Map',\n 'Set',\n 'Number',\n 'Symbol',\n 'BigInt',\n 'Function',\n 'Promise',\n 'RegExp',\n 'JSON',\n]);\n\nexport const toTypeScriptModelName = (name: string): string => {\n const candidateName = toClassName(name);\n\n // Prepend underscore for any reserved model names\n return TYPESCRIPT_RESERVED_MODEL_NAMES.has(candidateName)\n ? `_${candidateName}`\n : candidateName;\n};\n\n/** Python types that are built-ins and do not need forward-ref quoting. */\nconst PYTHON_BUILTIN_TYPES = new Set([\n 'str',\n 'int',\n 'float',\n 'bool',\n 'bytes',\n 'None',\n 'Any',\n 'datetime.date',\n 'datetime.datetime',\n]);\n\n/**\n * Every class-cased Python builtin, checked against `dir(builtins)` by a test.\n *\n * A schema of the same name is emitted as a class that shadows the builtin only\n * from its own definition onwards, so an annotation rendered above it resolves to\n * the builtin — a `types.py` that does not import, and whether it happens depends\n * on where the schema sorts.\n */\nexport const PYTHON_CLASS_CASED_BUILTINS = [\n 'ArithmeticError',\n 'AssertionError',\n 'AttributeError',\n 'BaseException',\n 'BaseExceptionGroup',\n 'BlockingIOError',\n 'BrokenPipeError',\n 'BufferError',\n 'BytesWarning',\n 'ChildProcessError',\n 'ConnectionAbortedError',\n 'ConnectionError',\n 'ConnectionRefusedError',\n 'ConnectionResetError',\n 'DeprecationWarning',\n 'EOFError',\n 'Ellipsis',\n 'EncodingWarning',\n 'EnvironmentError',\n 'Exception',\n 'ExceptionGroup',\n 'False',\n 'FileExistsError',\n 'FileNotFoundError',\n 'FloatingPointError',\n 'FutureWarning',\n 'GeneratorExit',\n 'IOError',\n 'ImportError',\n 'ImportWarning',\n 'IndentationError',\n 'IndexError',\n 'InterruptedError',\n 'IsADirectoryError',\n 'KeyError',\n 'KeyboardInterrupt',\n 'LookupError',\n 'MemoryError',\n 'ModuleNotFoundError',\n 'NameError',\n 'None',\n 'NotADirectoryError',\n 'NotImplemented',\n 'NotImplementedError',\n 'OSError',\n 'OverflowError',\n 'PendingDeprecationWarning',\n 'PermissionError',\n 'ProcessLookupError',\n 'PythonFinalizationError',\n 'RecursionError',\n 'ReferenceError',\n 'ResourceWarning',\n 'RuntimeError',\n 'RuntimeWarning',\n 'StopAsyncIteration',\n 'StopIteration',\n 'SyntaxError',\n 'SyntaxWarning',\n 'SystemError',\n 'SystemExit',\n 'TabError',\n 'TimeoutError',\n 'True',\n 'TypeError',\n 'UnboundLocalError',\n 'UnicodeDecodeError',\n 'UnicodeEncodeError',\n 'UnicodeError',\n 'UnicodeTranslateError',\n 'UnicodeWarning',\n 'UserWarning',\n 'ValueError',\n 'Warning',\n 'ZeroDivisionError',\n];\n\n/**\n * Names that the generated `types.py` and client modules import or define\n * at module scope. A user-defined schema named `Field`, `Optional`, etc.\n * would shadow these imports and either break forward-ref resolution\n * (`Optional[\"Field\"]` resolves to `pydantic.Field` without escaping) or\n * silently produce invalid runtime types.\n *\n * Keep this aligned with the imports at the top of:\n * - open-api/py-client/files/shared/types.py.template\n * - open-api/py-client/files/client/__clientModuleName__.py.template\n */\nconst PYTHON_RESERVED_MODEL_NAMES = new Set([\n // typing module\n 'Annotated',\n 'Any',\n 'Literal',\n 'Never',\n 'Optional',\n 'TypedDict',\n 'Union',\n // pydantic\n 'BaseModel',\n 'ConfigDict',\n 'Field',\n 'TypeAdapter',\n // stdlib modules referenced in templates\n 'Iterator',\n 'AsyncIterator',\n // typing/python builtins that would also shadow primitives\n 'None',\n 'True',\n 'False',\n 'Type',\n // namespace import in client.py — never let a user model collide\n 'types',\n // base exception we emit\n 'ApiError',\n // Every class-cased Python builtin, because a class of the same name shadows\n // one only *after* its own definition. `from __future__ import annotations`\n // defers every annotation to module scope, so a reference emitted above the\n // class resolves to the builtin instead — and which of the two wins depends on\n // the order the schemas happen to sort in. A published spec with a schema named\n // `Exception` produced a `types.py` that could not be imported at all.\n //\n // Listed in full rather than by the names seen to break: the set is fixed and\n // small, and a test asserts it against `dir(builtins)` so a new one is caught.\n ...PYTHON_CLASS_CASED_BUILTINS,\n]);\n\n/**\n * Return the Python class name for a model. Starts from the TypeScript\n * escape (which already handles TS-reserved names like `Error` → `_Error`)\n * and additionally escapes names that would shadow imports in the generated\n * Python files.\n */\nexport const toPythonClassName = (name: string): string => {\n const tsName = toTypeScriptModelName(name);\n // A class name is an identifier too. An operationId like `42` or `1stOperation`\n // renders a name beginning with a digit, and one written entirely in\n // punctuation (`___`) or another script renders nothing at all — an empty\n // prefix would name an operation's error class after the base class it derives\n // from, silently reparenting every class emitted after it. Encoding the raw\n // name's code points keeps it distinct rather than positional, matching how\n // {@link toPythonName} escapes the same names.\n const identifier = tsName\n ? /^\\d/.test(tsName)\n ? `N${tsName}`\n : tsName\n : `U${encodeCodePoints(name)}`;\n return PYTHON_RESERVED_MODEL_NAMES.has(identifier)\n ? `_${identifier}`\n : identifier;\n};\n\n/**\n * Whether the rendered name is a Python built-in rather than a reference to a\n * generated class. Only bare names reach here — a structured type is described\n * by {@link PythonType} instead of being matched on its spelling.\n */\nconst isPythonBuiltinName = (name: string): boolean =>\n !name || PYTHON_BUILTIN_TYPES.has(name);\n\nconst toPythonPrimitive = (property: Model): string => {\n if (property.type === 'string' && property.format === 'date') {\n return 'datetime.date';\n } else if (property.type === 'string' && property.format === 'date-time') {\n return 'datetime.datetime';\n } else if (property.type === 'any' || property.type === 'unknown') {\n return 'Any';\n } else if (property.type === 'binary') {\n return 'bytes';\n } else if (property.type === 'null' || property.type === 'void') {\n return 'None';\n } else if (property.type === 'number') {\n if (property.openapiType === 'integer') {\n return 'int';\n }\n\n switch (property.format) {\n case 'int32':\n case 'int64':\n return 'int';\n case 'float':\n case 'double':\n default:\n return 'float';\n }\n } else if (property.type === 'integer') {\n return 'int';\n } else if (property.type === 'boolean') {\n return 'bool';\n } else if (property.type === 'string') {\n return 'str';\n }\n // Fall-through is a user-defined model reference. The py-client emits\n // classes using `pythonClassName`, so references use the same escaped form.\n return toPythonClassName(property.type);\n};\n\n/**\n * Render a value as a Python literal expression: a quoted string with anything\n * that would break out of the quotes escaped, `None` for null, and the bare\n * value for numbers.\n */\nexport const toPythonLiteral = (value: unknown): string => {\n if (typeof value === 'string') {\n // Backslash first, so the escapes added below aren't escaped again.\n const escaped = value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\t/g, '\\\\t');\n return `\"${escaped}\"`;\n }\n if (value === null || value === undefined) return 'None';\n if (typeof value === 'boolean') return value ? 'True' : 'False';\n return String(value);\n};\n\n/**\n * A discriminated subtype's tag values. `discriminatorValue` is stored as\n * rendered TypeScript literals (e.g. `\"cat\" | \"kitten\"`), which are already in\n * Python's literal spelling.\n */\nconst pythonDiscriminatorValues = (discriminatorValue: string): string[] =>\n discriminatorValue.split(' | ');\n\n/** An enum's members as Python literal expressions. */\nconst pythonEnumValues = (property: Model): string[] =>\n (property.enum ?? []).map((member) => toPythonLiteral(member.value));\n\n/**\n * The Python type of a collection's element. An enum element (anonymous or\n * referenced) becomes a `Literal[...]` so callers can't pass a value outside\n * the set.\n */\nconst pythonCollectionElementType = (\n property: Model,\n link: Model | undefined,\n): PythonType => {\n if (link?.export === 'enum') {\n return { kind: 'literal', values: pythonEnumValues(link) };\n }\n if (link) {\n return nullableMemberType(link, toPythonTypeTree(link));\n }\n // No link, but the collection itself carries the enum members (an inline\n // enum array or dictionary).\n if (property.isEnum && property.enum.length > 0) {\n return { kind: 'literal', values: pythonEnumValues(property) };\n }\n return pythonPrimitiveType(property);\n};\n\n/** A primitive or model reference as a structured type. */\nconst pythonPrimitiveType = (property: Model): PythonType => {\n const name = toPythonPrimitive(property);\n return isPythonBuiltinName(name)\n ? { kind: 'builtin', name }\n : { kind: 'reference', name };\n};\n\n/**\n * A collection member's type, admitting `None` when the member is nullable.\n *\n * The member's own nullability is not the collection's: `list[str | None]` is a\n * list that is always present whose items may be null. Dropping it made a valid\n * response containing `null` fail to parse. TypeScript applies the same rule via\n * its own member renderer.\n */\nconst nullableMemberType = (member: Model, rendered: PythonType): PythonType =>\n member.isNullable && member.type !== 'null'\n ? { kind: 'optional', inner: rendered }\n : rendered;\n\n/**\n * The Python type of a property, as a tree.\n *\n * This is the single place a model's Python type is derived. Consumers that\n * need to know what a type is — a collection, a class reference, a literal —\n * inspect the tree rather than the rendered string, and render it with\n * {@link renderPythonType} when they need source text.\n */\nexport const toPythonTypeTree = (property: Model): PythonType => {\n if (property.discriminatorValue) {\n return {\n kind: 'literal',\n values: pythonDiscriminatorValues(property.discriminatorValue),\n };\n }\n const link = property.link ?? undefined;\n switch (property.export) {\n case 'enum':\n return property.enum?.length\n ? { kind: 'literal', values: pythonEnumValues(property) }\n : pythonPrimitiveType(property);\n case 'generic':\n case 'reference':\n return pythonPrimitiveType(property);\n case 'array':\n return {\n kind: 'list',\n element: pythonCollectionElementType(property, link),\n };\n case 'tuple':\n return {\n kind: 'tuple',\n members: property.properties.map((member) =>\n nullableMemberType(member, toPythonTypeTree(member)),\n ),\n };\n case 'dictionary':\n return {\n kind: 'dict',\n value: pythonCollectionElementType(property, link),\n };\n case 'one-of':\n case 'any-of':\n case 'all-of':\n return { kind: 'reference', name: toPythonClassName(property.name) };\n default: {\n // \"any\"/\"unknown\" has export = interface — route to the primitive path so\n // they become `Any` rather than being treated as a model reference.\n if (PRIMITIVE_TYPES.has(property.type) || property.type === 'unknown') {\n return pythonPrimitiveType(property);\n }\n const name = toPythonClassName(property.type);\n return isPythonBuiltinName(name)\n ? { kind: 'builtin', name }\n : { kind: 'reference', name };\n }\n }\n};\n\n/** How a reference to a generated class is spelled where it is rendered. */\nexport interface RenderPythonTypeOptions {\n /**\n * Namespace prefix for a class reference, e.g. `\"types.\"` from a client\n * module that imports the types module wholesale.\n */\n readonly prefix?: string;\n /**\n * Wrap a class reference in quotes, for use inside a class body before the\n * referenced class is defined. pydantic resolves these lazily.\n */\n readonly forwardRef?: boolean;\n}\n\n/** Render a structured Python type as source text. */\nexport const renderPythonType = (\n type: PythonType,\n options: RenderPythonTypeOptions = {},\n): string => {\n const render = (t: PythonType): string => {\n switch (t.kind) {\n case 'builtin':\n return t.name;\n case 'reference': {\n const qualified = `${options.prefix ?? ''}${t.name}`;\n return options.forwardRef ? `\"${qualified}\"` : qualified;\n }\n case 'literal':\n return `Literal[${t.values.join(', ')}]`;\n case 'list':\n return `list[${render(t.element)}]`;\n case 'dict':\n return `dict[str, ${render(t.value)}]`;\n case 'tuple':\n return `tuple[${t.members.map(render).join(', ')}]`;\n case 'optional': {\n // PEP 604, which is what the ruff rules generated Python projects vend\n // (`UP045`) require, and what every other Python template here emits.\n const inner = render(t.inner);\n return inner === 'None' ? inner : `${inner} | None`;\n }\n }\n };\n return render(type);\n};\n\n/**\n * Return the idiomatic Python type for a given property.\n *\n * Uses PEP-585 lower-case generics (`list[...]`, `dict[str, ...]`), fully-\n * qualified stdlib types (`datetime.date`, `datetime.datetime`), `bytes` for\n * binary payloads, and `Literal[...]` for enums. Model references are\n * returned as bare class names — callers that emit the type inside a class\n * body (where the class isn't yet defined) should use `toPythonAnnotation`\n * instead to get forward-ref quoting.\n */\nexport const toPythonType = (property: Model): string =>\n renderPythonType(toPythonTypeTree(property));\n\n/**\n * Render a type with every class reference prefixed with the given namespace,\n * so a client module can reach the types module through a single import.\n */\nexport const qualifyPythonType = (\n type: PythonType | undefined,\n prefix: string,\n): string => (type ? renderPythonType(type, { prefix }) : 'Any');\n\n/**\n * Same as `toPythonType`, but wraps class references in forward-ref quotes so\n * they can be used inside a class body before the class is defined.\n */\nexport const toPythonAnnotation = (property: Model): string =>\n renderPythonType(toPythonTypeTree(property), { forwardRef: true });\n\n// @see https://github.com/OpenAPITools/openapi-generator/blob/e2a62ace74de361bef6338b7fa37da8577242aef/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L106\nconst PYTHON_KEYWORDS = new Set([\n // @property\n 'property',\n // typing keywords\n 'schema',\n 'base64',\n 'json',\n 'date',\n 'float',\n // python reserved words\n 'and',\n 'del',\n 'from',\n 'not',\n 'while',\n 'as',\n 'elif',\n 'global',\n 'or',\n 'with',\n 'assert',\n 'else',\n 'if',\n 'pass',\n 'yield',\n 'break',\n 'except',\n 'import',\n 'print',\n 'class',\n 'exec',\n 'in',\n 'raise',\n 'continue',\n 'finally',\n 'is',\n 'return',\n 'def',\n 'for',\n 'lambda',\n 'try',\n 'self',\n 'nonlocal',\n 'None',\n 'True',\n 'False',\n 'async',\n 'await',\n]);\n\n/**\n * Names the emitted annotations refer to, so binding one shadows the type it\n * names within the scope the annotation is evaluated in.\n *\n * For a keyword argument the local wins before a `TypeAdapter(list[...])`\n * annotation is evaluated, and the call fails with a `TypeError`. For a pydantic\n * field it is worse: the class body binds the name to the field default, and\n * because `types.py` carries `from __future__ import annotations` every\n * annotation on the class is evaluated in that namespace — so one field named\n * `str` makes a sibling's `str | None` unresolvable and the module cannot be\n * imported at all. `datetime` is the module the date annotations qualify.\n */\nconst PYTHON_TYPE_SCOPE_NAMES = new Set([\n // The module every generated annotation qualifies a model through. A kwarg of\n // this name shadowed it in the method's own return annotation, so the call\n // raised `AttributeError` on the caller's value — after the module imported and\n // with the request itself going out correctly.\n 'types',\n 'bool',\n 'bytes',\n 'datetime',\n 'dict',\n 'float',\n 'int',\n 'list',\n 'set',\n 'str',\n 'tuple',\n 'type',\n]);\n\n/**\n * Names the generated client's method bodies bind, in the same scope as an\n * operation's keyword arguments.\n *\n * A kwarg sharing one of these is not merely shadowed — the method assigns its\n * own local over the caller's value, so internal state is serialised onto the\n * wire (a body field named `header_params` was sent as `{}`). Escaped like a\n * keyword, since the wire name is preserved by the field alias either way.\n *\n * Locals of the private helpers are excluded — those take their own parameters\n * and never share a scope with an operation's arguments — as are `body` and\n * `response`, the generator's own names for the whole body and the response,\n * which are assigned after the request is built.\n */\nconst PYTHON_METHOD_SCOPE_NAMES = new Set([\n 'cookie_params',\n 'header_formats',\n 'header_params',\n 'path_params',\n 'path_styles',\n 'query_formats',\n 'query_params',\n 'request_kwargs',\n]);\n\n/**\n * Names pydantic reserves on a `BaseModel`. A field called `model_dump` or\n * `model_config` would either shadow the method callers rely on or replace the\n * `ConfigDict` the generated class sets, so they are escaped like a keyword.\n *\n * `model_` is pydantic's protected namespace, so anything in it is escaped\n * rather than only the members that exist today.\n */\nconst isPydanticReservedName = (name: string): boolean =>\n name.startsWith('model_') || name === 'model_fields' || name === 'schema';\n\n/**\n * A name's non-alphanumeric characters replaced by their code points, so a name\n * that would otherwise escape to nothing keeps a distinct, stable spelling: two\n * such names never collide and the same spec always renders the same way.\n */\nconst encodeCodePoints = (name: string): string =>\n Array.from(name)\n .map((ch) =>\n /[a-zA-Z0-9]/.test(ch) ? ch : ch.codePointAt(0)!.toString(16),\n )\n .join('')\n .toLowerCase();\n\n/**\n * A snake_case name that is a usable Python identifier.\n *\n * `snakeCase` keeps only alphanumerics, so a name written in another script\n * yields the empty string and one beginning with a digit is not an identifier at\n * all. Either would emit code that does not parse, so the name falls back to\n * {@link encodeCodePoints} rather than to a positional name.\n */\nconst toPythonIdentifier = (name: string): string => {\n const snake = snakeCase(name);\n if (snake && !/^\\d/.test(snake)) {\n return snake;\n }\n return snake ? `n_${snake}` : `u_${encodeCodePoints(name)}`;\n};\n\nexport const toPythonName = (\n namedEntity: 'model' | 'property' | 'operation' | 'argument',\n name: string,\n) => {\n const nameSnakeCase = toPythonIdentifier(name);\n\n // Names overlapping a TypeScript reserved word carry a leading `_`; strip it\n // before testing against the Python keyword set. Also test the snake-cased\n // form — snakeCase strips trailing underscores, so `from_` becomes `from`\n // and would otherwise slip through.\n const rawStripped = name.startsWith('_') ? name.slice(1) : name;\n const isPydanticReserved =\n namedEntity === 'property' &&\n (isPydanticReservedName(rawStripped) ||\n isPydanticReservedName(nameSnakeCase));\n if (\n isPydanticReserved ||\n PYTHON_KEYWORDS.has(rawStripped) ||\n PYTHON_KEYWORDS.has(nameSnakeCase) ||\n // A method argument and a model field both share a scope with the names the\n // emitted annotations refer to; only an argument also shares one with the\n // client's own locals.\n ((namedEntity === 'argument' || namedEntity === 'property') &&\n PYTHON_TYPE_SCOPE_NAMES.has(nameSnakeCase)) ||\n (namedEntity === 'argument' && PYTHON_METHOD_SCOPE_NAMES.has(nameSnakeCase))\n ) {\n const nameSuffix = `_${nameSnakeCase}`;\n switch (namedEntity) {\n case 'model':\n return `model${nameSuffix}`;\n case 'operation':\n return `call${nameSuffix}`;\n case 'argument':\n case 'property':\n return `var${nameSuffix}`;\n default:\n break;\n }\n }\n return nameSnakeCase;\n};\n"],"names":["camelCase","snakeCase","toClassName","PRIMITIVE_TYPES","toTypescriptPrimitive","property","type","includes","format","memberType","rendered","member","isNullable","toTypeScriptType","discriminatorValue","link","valueType","export","properties","map","join","toTypeScriptModelName","name","has","toTypeScriptName","replace","TYPESCRIPT_RESERVED_MODEL_NAMES","Set","candidateName","PYTHON_BUILTIN_TYPES","PYTHON_CLASS_CASED_BUILTINS","PYTHON_RESERVED_MODEL_NAMES","toPythonClassName","tsName","identifier","test","encodeCodePoints","isPythonBuiltinName","toPythonPrimitive","openapiType","toPythonLiteral","value","escaped","undefined","String","pythonDiscriminatorValues","split","pythonEnumValues","enum","pythonCollectionElementType","kind","values","nullableMemberType","toPythonTypeTree","isEnum","length","pythonPrimitiveType","inner","element","members","renderPythonType","options","render","t","qualified","prefix","forwardRef","toPythonType","qualifyPythonType","toPythonAnnotation","PYTHON_KEYWORDS","PYTHON_TYPE_SCOPE_NAMES","PYTHON_METHOD_SCOPE_NAMES","isPydanticReservedName","startsWith","Array","from","ch","codePointAt","toString","toLowerCase","toPythonIdentifier","snake","toPythonName","namedEntity","nameSnakeCase","rawStripped","slice","isPydanticReserved","nameSuffix"],"mappings":"AAAA;;;CAGC,GAED,SAASA,SAAS,EAAEC,SAAS,EAAEC,WAAW,QAAQ,0BAA0B;AAC5E,SAAqBC,eAAe,QAAyB,aAAa;AAE1E,MAAMC,wBAAwB,CAACC;IAC7B,IACEA,SAASC,IAAI,KAAK,YAClB;QAAC;QAAQ;KAAY,CAACC,QAAQ,CAACF,SAASG,MAAM,IAAI,KAClD;QACA,OAAO;IACT,OAAO,IAAIH,SAASC,IAAI,KAAK,UAAU;QACrC,OAAO;IACT;IACA,OAAOD,SAASC,IAAI;AACtB;AAEA,wDAAwD;AACxD,MAAMG,aAAa,CAACC,UAAkBC,SACpCA,OAAOC,UAAU,IAAID,OAAOL,IAAI,KAAK,SAAS,GAAGI,SAAS,OAAO,CAAC,GAAGA;AAEvE,OAAO,MAAMG,mBAAmB,CAACR;IAC/B,0EAA0E;IAC1E,0DAA0D;IAC1D,IAAIA,SAASS,kBAAkB,EAAE;QAC/B,OAAOT,SAASS,kBAAkB;IACpC;IACA,MAAMC,OAAOV,SAASU,IAAI;IAC1B,6EAA6E;IAC7E,MAAMC,YAAY,IAChBD,QAAQA,KAAKE,MAAM,KAAK,SAASJ,iBAAiBE,QAAQV,SAASC,IAAI;IACzE,OAAQD,SAASY,MAAM;QACrB,KAAK;QACL,KAAK;YACH,OAAOb,sBAAsBC;QAC/B,KAAK;YACH,OAAO,CAAC,MAAM,EAAEW,YAAY,CAAC,CAAC;QAChC,KAAK;YACH,OAAO,CAAC,CAAC,EAAEX,SAASa,UAAU,CAC3BC,GAAG,CAAC,CAACR,SAAWF,WAAWI,iBAAiBF,SAASA,SACrDS,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,KAAK;YACH,OAAO,CAAC,iBAAiB,EAAEJ,YAAY,GAAG,CAAC;QAC7C,KAAK;QACL,KAAK;QACL,KAAK;YACH,OAAOK,sBAAsBhB,SAASiB,IAAI;QAC5C,KAAK;QACL;YACE,IAAIjB,SAASC,IAAI,KAAK,WAAW;gBAC/B,OAAO;YACT;YACA,IAAIH,gBAAgBoB,GAAG,CAAClB,SAASC,IAAI,GAAG;gBACtC,OAAOF,sBAAsBC;YAC/B;YACA,OAAOgB,sBAAsBhB,SAASC,IAAI;IAC9C;AACF,EAAE;AAEF,OAAO,MAAMkB,mBAAmB,CAACF;IAC/B,6EAA6E;IAC7E,0EAA0E;IAC1E,OAAOtB,UAAUsB,SAAS,AAACA,CAAAA,QAAQ,EAAC,EAAGG,OAAO,CAAC,iBAAiB,QAAQ;AAC1E,EAAE;AAEF,MAAMC,kCAAkC,IAAIC,IAAI;IAC9C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,MAAMN,wBAAwB,CAACC;IACpC,MAAMM,gBAAgB1B,YAAYoB;IAElC,kDAAkD;IAClD,OAAOI,gCAAgCH,GAAG,CAACK,iBACvC,CAAC,CAAC,EAAEA,eAAe,GACnBA;AACN,EAAE;AAEF,yEAAyE,GACzE,MAAMC,uBAAuB,IAAIF,IAAI;IACnC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;CAOC,GACD,OAAO,MAAMG,8BAA8B;IACzC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC;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