@aws/nx-plugin 1.0.0-rc.30 → 1.0.0-rc.32

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.
Files changed (59) hide show
  1. package/LICENSE-THIRD-PARTY +235 -1336
  2. package/README.md +1 -1
  3. package/package.json +1 -2
  4. package/src/mcp-server/tools/create-workspace-command.js +2 -2
  5. package/src/mcp-server/tools/create-workspace-command.js.map +1 -1
  6. package/src/open-api/ts-client/__snapshots__/generator.additional-properties.spec.ts.snap +147 -33
  7. package/src/open-api/ts-client/__snapshots__/generator.arrays.spec.ts.snap +308 -75
  8. package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +286 -62
  9. package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +674 -93
  10. package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +211 -36
  11. package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +196 -44
  12. package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +5507 -0
  13. package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +219 -60
  14. package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +280 -0
  15. package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +351 -80
  16. package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +170 -49
  17. package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +98 -22
  18. package/src/open-api/ts-client/__snapshots__/generator.response.spec.ts.snap +147 -33
  19. package/src/open-api/ts-client/__snapshots__/generator.streaming.spec.ts.snap +392 -88
  20. package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +196 -44
  21. package/src/open-api/ts-client/files/client.gen.ts.template +166 -19
  22. package/src/open-api/ts-client/files/types.gen.ts.template +4 -4
  23. package/src/open-api/ts-client/generator.js +1 -1
  24. package/src/open-api/ts-client/generator.js.map +1 -1
  25. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +5 -0
  26. package/src/open-api/ts-hooks/generator.spec.tsx +70 -0
  27. package/src/open-api/utils/codegen-data/languages.d.ts +0 -6
  28. package/src/open-api/utils/codegen-data/languages.js +23 -18
  29. package/src/open-api/utils/codegen-data/languages.js.map +1 -1
  30. package/src/open-api/utils/codegen-data/types.d.ts +240 -10
  31. package/src/open-api/utils/codegen-data/types.js +24 -1
  32. package/src/open-api/utils/codegen-data/types.js.map +1 -1
  33. package/src/open-api/utils/codegen-data.d.ts +2 -2
  34. package/src/open-api/utils/codegen-data.js +357 -617
  35. package/src/open-api/utils/codegen-data.js.map +1 -1
  36. package/src/open-api/utils/normalise.js +167 -22
  37. package/src/open-api/utils/normalise.js.map +1 -1
  38. package/src/open-api/utils/parser.d.ts +55 -0
  39. package/src/open-api/utils/parser.js +754 -0
  40. package/src/open-api/utils/parser.js.map +1 -0
  41. package/src/open-api/utils/types.d.ts +18 -0
  42. package/src/open-api/utils/types.js.map +1 -1
  43. package/src/preset/__snapshots__/generator.spec.ts.snap +6 -6
  44. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +414 -6
  45. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +276 -4
  46. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +414 -6
  47. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +0 -23
  48. package/src/ts/mcp-server/generator.js +10 -22
  49. package/src/ts/mcp-server/generator.js.map +1 -1
  50. package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
  51. package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
  52. package/src/utils/mcp.js +1 -1
  53. package/src/utils/mcp.js.map +1 -1
  54. package/src/utils/names.d.ts +6 -0
  55. package/src/utils/names.js +6 -1
  56. package/src/utils/names.js.map +1 -1
  57. package/src/utils/versions.d.ts +5 -5
  58. package/src/utils/versions.js +4 -4
  59. package/src/utils/versions.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/utils/codegen-data.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Plugin } from '@hey-api/openapi-ts';\nimport * as gen from '@hey-api/openapi-ts';\nimport camelCase from 'lodash.camelcase';\nimport orderBy from 'lodash.orderby';\nimport trim from 'lodash.trim';\nimport uniqBy from 'lodash.uniqby';\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport {\n kebabCase,\n pascalCase,\n snakeCase,\n toClassName,\n upperFirst,\n} from '../../utils/names';\nimport {\n toPythonName,\n toPythonType,\n toTypeScriptModelName,\n toTypeScriptName,\n toTypeScriptType,\n} from './codegen-data/languages';\nimport {\n type ClientData,\n COLLECTION_TYPES,\n COMPOSED_SCHEMA_TYPES,\n type CodeGenData,\n flattenModelLink,\n type Model,\n type Operation,\n PRIMITIVE_TYPES,\n STREAMING_CONTENT_TYPES,\n VENDOR_EXTENSIONS,\n} from './codegen-data/types';\nimport { normaliseOpenApiSpecForCodeGen } from './normalise';\nimport { isRef, resolveIfRef, splitRef } from './refs';\nimport type { Spec } from './types';\n\n/**\n * Builds a data structure from an OpenAPI spec which can be used to generate code\n */\nexport const buildOpenApiCodeGenData = async (\n inSpec: Spec,\n): Promise<CodeGenData> => {\n // Ensure spec is ready for codegen\n const spec = normaliseOpenApiSpecForCodeGen(inSpec);\n\n // Build the initial data, which we will augment with additional information\n const data = await buildInitialCodeGenData(spec);\n\n // Ensure the models have their links set when they are arrays/dictionaries\n ensureModelLinks(spec, data);\n\n // Mutate the models with enough data to render composite models in the templates\n ensureCompositeModels(data);\n\n const modelsByName = Object.fromEntries(data.models.map((m) => [m.name, m]));\n\n // Augment operations with additional data\n for (const service of data.services) {\n // Keep track of the request and response models we need the service (ie api client) to import\n const requestModelImports: string[] = [];\n const responseModelImports: string[] = [];\n\n for (const op of service.operations) {\n // Extract the operation back from the openapi spec\n const specOp = (spec as any)?.paths?.[op.path]?.[\n op.method.toLowerCase()\n ] as OpenAPIV3.OperationObject | undefined;\n\n op.name = op.id ?? op.name;\n (op as any).uniqueName = op.name;\n if (specOp['x-aws-nx-deduplicated-op-id']) {\n (op as any).uniqueName = specOp['x-aws-nx-deduplicated-op-id'];\n }\n if (specOp['x-aws-nx-deduplicated-dot-op-id']) {\n (op as any).dotNotationName = specOp['x-aws-nx-deduplicated-dot-op-id'];\n }\n\n // Add vendor extensions\n (op as any).vendorExtensions = (op as any).vendorExtensions ?? {};\n copyVendorExtensions(specOp ?? {}, (op as any).vendorExtensions);\n\n if (specOp) {\n // Add all response models to the response model imports\n responseModelImports.push(\n ...op.responses\n .filter((r) => r.export === 'reference')\n .map((r) => r.type),\n );\n\n for (const response of op.responses) {\n // Validate that the response is not a composite schema of primitives since we cannot determine what\n // the type of the response is (it all comes back as text!)\n if (\n response.export === 'reference' &&\n COMPOSED_SCHEMA_TYPES.has(modelsByName[response.type]?.export)\n ) {\n const composedPrimitives = (\n modelsByName[response.type] as any\n ).composedPrimitives.filter(\n (p) => !['array', 'dictionary'].includes(p.export),\n );\n if (composedPrimitives.length > 0) {\n throw new Error(\n `Operation \"${op.method} ${op.path}\" returns a composite schema of primitives with ${camelCase(modelsByName[response.type].export)}, which cannot be distinguished at runtime`,\n );\n }\n }\n\n const matchingSpecResponse = specOp.responses[`${response.code}`];\n\n // @hey-api/openapi-ts does not distinguish between returning an \"any\" or returning \"void\"\n // We distinguish this by looking back at each response in the spec, and checking whether it\n // has content\n if (matchingSpecResponse) {\n // Resolve the ref if necessary\n const specResponse = resolveIfRef(spec, matchingSpecResponse);\n\n // When there's no content, we set the type to 'void'\n if (!specResponse.content) {\n response.type = 'void';\n } else {\n // Add the response media types\n const mediaTypes = Object.keys(specResponse.content);\n (response as any).mediaTypes = mediaTypes;\n\n for (const mediaType of mediaTypes) {\n const responseContent =\n specResponse.content?.[mediaType] ??\n Object.values(specResponse.content)[0];\n const responseSchema = resolveIfRef(\n spec,\n responseContent.schema,\n );\n if (responseSchema) {\n await mutateWithOpenapiSchemaProperties(\n spec,\n response,\n responseSchema,\n modelsByName,\n );\n }\n if (\n STREAMING_CONTENT_TYPES.has(mediaType) &&\n 'itemSchema' in responseContent\n ) {\n (response as any).isJsonlStreaming = true;\n (response as any).itemSchemaModel =\n await buildOrReferenceModel(\n spec,\n modelsByName,\n responseContent.itemSchema,\n );\n }\n }\n }\n }\n }\n }\n\n const specParametersByName = Object.fromEntries(\n (specOp?.parameters ?? []).map((p) => {\n const param = resolveIfRef(spec, p);\n return [param.name, param];\n }),\n );\n\n // Loop through the parameters\n for (const parameter of op.parameters) {\n // Add the request model import\n if (parameter.export === 'reference') {\n requestModelImports.push(parameter.type);\n }\n\n const specParameter = specParametersByName[parameter.prop];\n const specParameterSchema = resolveIfRef(spec, specParameter?.schema);\n\n if (specParameterSchema) {\n await mutateWithOpenapiSchemaProperties(\n spec,\n parameter,\n specParameterSchema,\n modelsByName,\n );\n }\n\n if (parameter.in === 'body' || parameter.in === 'formData') {\n // Parameter name for the body is 'body'. `formData` bodies arrive\n // under a synthetic `formData` param (hey-api convention) that's\n // logically the body — normalise both shapes to `in === 'body'`\n // so every downstream consumer (including ts-client's request-\n // type composition) sees a single body kind.\n parameter.name = 'body';\n parameter.prop = 'body';\n parameter.in = 'body';\n\n // The request body is not in the \"parameters\" section of the openapi spec so we won't have added the schema\n // properties above. Find it here.\n const specBody = resolveIfRef(spec, specOp?.requestBody);\n if (specBody) {\n if (parameter.mediaType) {\n const bodySchema = resolveIfRef(\n spec,\n specBody.content?.[parameter.mediaType]?.schema,\n );\n if (bodySchema) {\n await mutateWithOpenapiSchemaProperties(\n spec,\n parameter,\n bodySchema,\n modelsByName,\n );\n }\n }\n // Track all the media types that can be accepted in the request body\n (parameter as any).mediaTypes = Object.keys(specBody.content);\n }\n } else if (\n ['query', 'header'].includes(parameter.in) &&\n specParameter\n ) {\n // Translate style/explode to OpenAPI v2 style collectionFormat\n // https://spec.openapis.org/oas/v3.0.3.html#style-values\n const style =\n specParameter.style ??\n (parameter.in === 'query' ? 'form' : 'simple');\n const explode = specParameter.explode ?? style === 'form';\n\n if (parameter.in === 'query') {\n (parameter as any).collectionFormat = explode\n ? 'multi'\n : ({\n spaceDelimited: 'ssv',\n pipeDelimited: 'tsv',\n simple: 'csv',\n form: 'csv',\n }[style] ?? 'multi');\n } else {\n // parameter.in === \"header\"\n (parameter as any).collectionFormat = explode ? 'multi' : 'csv';\n }\n }\n\n mutateModelWithAdditionalTypes(parameter);\n }\n\n // Add language types to response models\n (op.responses ?? []).forEach(mutateModelWithAdditionalTypes);\n\n // Sort responses by code\n op.responses = orderBy(op.responses, (r) => r.code);\n // Result is the lowest successful response, otherwise is the 2XX or default response\n const result = op.responses.find(\n (r) => typeof r.code === 'number' && r.code >= 200 && r.code < 300,\n );\n (op as any).result =\n result ??\n op.responses.find((r) => r.code === '2XX' || r.code === 'default');\n\n // Add variants of operation name\n (op as any).operationIdPascalCase = pascalCase((op as any).uniqueName);\n (op as any).operationIdKebabCase = kebabCase((op as any).uniqueName);\n (op as any).operationIdSnakeCase = toPythonName(\n 'operation',\n (op as any).uniqueName,\n );\n\n // Add request type name (after operationIdPascalCase is set)\n if (op.parameters && op.parameters.length > 0) {\n const baseRequestTypeName = `${(op as any).operationIdPascalCase}Request`;\n const hasConflict = !!spec.components?.schemas?.[baseRequestTypeName];\n if (hasConflict) {\n // Use OperationRequest suffix when there's a conflict\n (op as any).requestTypeName =\n `${(op as any).operationIdPascalCase}OperationRequest`;\n } else {\n // Use standard Request suffix when no conflict\n (op as any).requestTypeName = baseRequestTypeName;\n }\n }\n\n mutateOperationWithAdditionalData(op);\n }\n\n // Lexicographical ordering of operations\n service.operations = orderBy(\n service.operations,\n (op) => (op as any).uniqueName,\n );\n\n // Add the models to import\n (service as any).modelImports = orderBy(\n uniqBy(\n [...service.imports, ...requestModelImports, ...responseModelImports],\n (x) => x,\n ),\n );\n\n // Add the service class name\n (service as any).className = `${service.name}Api`;\n (service as any).classNameSnakeCase = snakeCase((service as any).className);\n (service as any).nameSnakeCase = snakeCase(service.name);\n }\n\n // All operations across all services\n const allOperations = uniqBy(\n data.services.flatMap((s) => s.operations),\n (o) => (o as any).uniqueName,\n );\n\n // Add additional models for operation parameters\n data.models = [\n ...data.models,\n ...allOperations.flatMap((op: Operation): Model[] => {\n if (op.parameters && op.parameters.length > 0) {\n // Build a collection of request parameter models to create based on their position (ie 'in' in the openapi spec, eg body, query, path, header, etc)\n const parametersByPosition: { [position: string]: Model[] } = {};\n\n op.parameters\n .filter(\n // We filter out (return false for) request bodies which we \"inline\" - ie we don't create a property which points to the body, the request will only be the body itself\n (p) => {\n // Always create models for non-body parameters\n if (p.in !== 'body') {\n return true;\n }\n\n // If the body is the only parameter, we can inline it no matter the type\n if (op.parameters.length === 1) {\n return false;\n }\n\n // We inline object bodies, so long as they aren't dictionaries (as dictionary keys could clash with other parameters),\n // and so long as they don't have a property name that clashes with another parameter\n const hasClashingPropertyName = (\n modelsByName?.[p.type]?.properties ?? []\n ).some((prop) =>\n op.parameters.some((param) => param.name === prop.name),\n );\n if (\n p.export === 'reference' &&\n modelsByName?.[p.type]?.export !== 'dictionary' &&\n !hasClashingPropertyName\n ) {\n return false;\n }\n\n // Don't inline anything else\n return true;\n },\n )\n .forEach((parameter) => {\n parametersByPosition[parameter.in] = [\n ...(parametersByPosition[parameter.in] ?? []),\n parameter,\n ];\n });\n\n // Ensure that if we have an explicit body parameter, it's called \"body\"\n const requestBodyParameter = parametersByPosition['body']?.[0];\n if (requestBodyParameter) {\n requestBodyParameter.name = 'body';\n (requestBodyParameter as any).prop = 'body';\n }\n\n (op as any).explicitRequestBodyParameter = requestBodyParameter;\n\n return Object.entries(parametersByPosition).map(\n ([position, parameters]) => {\n const name = `${(op as any).operationIdPascalCase}Request${upperFirst(position)}Parameters`;\n return {\n $refs: [],\n base: name,\n description: op.description,\n enum: null,\n enums: null,\n export: 'interface',\n imports: [],\n in: '',\n link: undefined,\n name,\n properties: parameters,\n template: '',\n type: name,\n isDefinition: false,\n isNullable: false,\n isReadOnly: false,\n isRequired: true,\n };\n },\n );\n }\n return [] as Model[];\n }),\n ];\n\n // Augment models with additional data\n for (const model of data.models) {\n // Add a snake_case name\n (model as any).nameSnakeCase = toPythonName('model', model.name);\n\n const matchingSpecModel = spec?.components?.schemas?.[model.name];\n\n if (matchingSpecModel) {\n const specModel = resolveIfRef(spec, matchingSpecModel);\n\n await mutateWithOpenapiSchemaProperties(\n spec,\n model,\n specModel,\n modelsByName,\n );\n\n // Add unique imports\n (model as any).uniqueImports = orderBy(\n uniqBy(\n [\n ...model.imports,\n // Include property imports, if any\n ...model.properties\n .filter((p) => p.export === 'reference')\n .map((p) => p.type),\n ],\n (x) => x,\n ),\n ).filter((modelImport) => modelImport !== model.name); // Filter out self for recursive model references\n\n // Add deprecated flag if present\n (model as any).deprecated = specModel.deprecated || false;\n\n // Augment properties with additional data\n for (const property of model.properties) {\n const matchingSpecProperty = specModel.properties?.[property.name];\n\n if (matchingSpecProperty) {\n const specProperty = resolveIfRef(spec, matchingSpecProperty);\n await mutateWithOpenapiSchemaProperties(\n spec,\n property,\n specProperty,\n modelsByName,\n );\n }\n }\n }\n\n // Augment properties with additional data\n model.properties.forEach((property) => {\n // Add language-specific names/types\n mutateModelWithAdditionalTypes(property);\n });\n }\n\n for (const model of data.models) {\n // Set the model's typescript name and type\n (model as any).typescriptName = toTypeScriptModelName(model.name);\n (model as any).typescriptType = (model as any).typescriptName;\n }\n\n // Order models lexicographically by name\n data.models = orderBy(data.models, (d) => d.name);\n\n // Order services so default appears first, then otherwise by name\n data.services = orderBy(data.services, (s) =>\n s.name === 'Default' ? '' : s.name,\n );\n\n // All operations by tags\n const operationsByTag: { [tag: string]: Operation[] } = {};\n const untaggedOperations: Operation[] = [];\n allOperations.forEach((op) => {\n const tags = (op as any).tags;\n if (tags && tags.length > 0) {\n tags.map(camelCase).forEach((tag: string) => {\n operationsByTag[tag] = [...(operationsByTag[tag] ?? []), op];\n });\n } else {\n untaggedOperations.push(op);\n }\n });\n\n // Add top level vendor extensions\n const vendorExtensions: { [key: string]: any } = {};\n copyVendorExtensions(spec ?? {}, vendorExtensions);\n\n return {\n ...data,\n operationsByTag,\n untaggedOperations,\n info: spec.info,\n allOperations,\n vendorExtensions,\n className: toClassName(spec.info.title),\n };\n};\n\nconst buildInitialCodeGenData = async (spec: Spec): Promise<ClientData> => {\n let data: ClientData;\n\n // We create a plugin which will capture the client data\n const plugin: Plugin.DefineConfig<{ name: string }> = () => ({\n name: 'plugin',\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n _handler: () => {},\n _handlerLegacy: ({ client }) => {\n data = client;\n },\n });\n\n // Use @hey-api/openapi-ts to build the initial data structure that we'll generate clients from\n await gen.createClient({\n experimentalParser: false,\n input: {\n path: spec,\n },\n output: 'unused',\n plugins: [plugin()],\n dryRun: true,\n logs: { level: 'silent' },\n });\n\n if (!data) {\n // If this happens it indicates an update to @hey-api/openapi-ts which has removed the legacy parser\n throw new Error('Failed to build code generation data');\n }\n\n return data;\n};\n\n/**\n * Build a model for a particular primitive schema.\n * Only primitives are supported since we only return one model.\n * For non-primitives, it assumes all referenced subschemas are already models\n */\nconst buildModelForPrimitive = async (\n originalSpec: Spec,\n schema: OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject,\n): Promise<Model> => {\n const targetSchemaName = '___aws_nx_plugin_openapi_tmp_schema___';\n\n const spec: Spec = {\n openapi: '3.1.0',\n info: { title: 'tmp', version: '1.0.0' },\n paths: {},\n components: {\n schemas: {\n ...originalSpec.components?.schemas,\n [targetSchemaName]: schema,\n },\n },\n };\n const data = await buildInitialCodeGenData(spec);\n\n const model = data.models.find((m) => m.name === targetSchemaName);\n if (!model) {\n throw new Error(\n `Failed to construct model for schema ${JSON.stringify(schema)}`,\n );\n }\n\n ensureModelLinks(spec, data);\n await mutateWithOpenapiSchemaProperties(\n spec,\n model,\n schema,\n Object.fromEntries(data.models.map((m) => [m.name, m])),\n );\n\n return model;\n};\n\nconst buildOrReferenceModel = async (\n spec: Spec,\n modelsByName: { [name: string]: Model },\n schema:\n | OpenAPIV3.SchemaObject\n | OpenAPIV3_1.SchemaObject\n | OpenAPIV3.ReferenceObject,\n): Promise<Model> => {\n if (isRef(schema)) {\n const name = splitRef(schema.$ref)[2];\n return modelsByName[name];\n }\n // Non referenced schemas won't have a model created as they are primitives and aren't covered by @heyapi\n // So we build the model here\n return await buildModelForPrimitive(spec, schema);\n};\n\n/**\n * Copy vendor extensions from the first parameter to the second\n */\nconst copyVendorExtensions = (\n object: object,\n vendorExtensions: { [key: string]: any },\n) => {\n Object.entries(object ?? {}).forEach(([key, value]) => {\n if (key.startsWith('x-')) {\n vendorExtensions[key] = value;\n }\n });\n};\n\nconst mutateWithOpenapiSchemaProperties = async (\n spec: Spec,\n model: Model,\n schema: OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject,\n modelsByName: { [name: string]: Model },\n visited: Set<Model> = new Set(),\n) => {\n (model as any).format = schema.format;\n (model as any).isInteger = schema.type === 'integer';\n (model as any).isShort = schema.format === 'int32';\n (model as any).isLong = schema.format === 'int64';\n (model as any).deprecated = !!schema.deprecated;\n (model as any).openapiType = schema.type;\n (model as any).isNotSchema = !!schema.not;\n (model as any).isEnum = !!schema.enum && schema.enum.length > 0;\n\n // Copy any schema vendor extensions\n (model as any).vendorExtensions = {};\n copyVendorExtensions(schema, (model as any).vendorExtensions);\n\n // Use our added vendor extension\n (model as any).isHoisted = !!(model as any).vendorExtensions?.[\n 'x-aws-nx-hoisted'\n ];\n\n // Ensure models with additional properties are handled correctly\n if (schema.additionalProperties) {\n const additionalPropertiesModel = await buildOrReferenceModel(\n spec,\n modelsByName,\n schema.additionalProperties === true ? {} : schema.additionalProperties,\n );\n\n // The original models treat _some_ objects with additional properties as a \"dictionary\", and others as an \"interface\"\n // For the purposes of our code generation, we define a \"dictionary\" to be a model with no explicit properties, only\n // additional properties. Interfaces can have a mixture of explicit properties and additional properties.\n if (model.export === 'dictionary') {\n // Dictionaries contain a special property which is the model itself. Other properties are explicit properties.\n const explicitProperties = model.properties.filter(\n (p) => !(p.export === 'dictionary' && p.name === model.name),\n );\n\n if (explicitProperties.length > 0 || (schema as any).patternProperties) {\n // Treat this model as an interface instead of a dictionary, since this has\n // explicit properties\n model.export = 'interface';\n (model as any).hasAdditionalProperties = true;\n (model as any).additionalPropertiesModel = additionalPropertiesModel;\n model.properties = explicitProperties;\n }\n } else {\n (model as any).hasAdditionalProperties = true;\n (model as any).additionalPropertiesModel = additionalPropertiesModel;\n // There's a special property named [key: string] which is the definition of the additional properties\n // We remove this so we don't render it as a regular property.\n model.properties = (model.properties ?? []).filter(\n (p) => p.name !== '[key: string]',\n );\n }\n }\n\n // Ensure models with pattern properties are handled correctly\n if ((schema as any).patternProperties) {\n const patternProperties = resolveIfRef(\n spec,\n (schema as any).patternProperties as\n | OpenAPIV3.ReferenceObject\n | {\n [pattern: string]:\n | OpenAPIV3.ReferenceObject\n | OpenAPIV3.SchemaObject\n | OpenAPIV3_1.SchemaObject;\n },\n );\n\n const patternPropertiesModels: { pattern: string; model: Model }[] = [];\n\n // When there are pattern properties, we don't want to treat models as dictionaries since there can be more than one type of \"value\"\n // depending on what pattern the key matches\n if (model.export === 'dictionary') {\n model.export = 'interface';\n }\n\n for (const [pattern, patternProperty] of Object.entries(\n patternProperties,\n )) {\n const patternPropertyModel = await buildOrReferenceModel(\n spec,\n modelsByName,\n patternProperty,\n );\n if (patternPropertyModel) {\n patternPropertiesModels.push({\n pattern,\n model: patternPropertyModel,\n });\n }\n }\n\n (model as any).hasPatternProperties = true;\n (model as any).patternPropertiesModels = patternPropertiesModels;\n }\n\n mutateModelWithAdditionalTypes(model);\n\n visited.add(model);\n\n const modelLink = flattenModelLink(model.link);\n\n // Also apply to array items recursively\n if (\n model.export === 'array' &&\n modelLink &&\n 'items' in schema &&\n schema.items &&\n !visited.has(modelLink)\n ) {\n const subSchema = resolveIfRef(spec, schema.items);\n await mutateWithOpenapiSchemaProperties(\n spec,\n modelLink,\n subSchema,\n modelsByName,\n visited,\n );\n }\n\n // Also apply to object properties recursively\n if (\n model.export === 'dictionary' &&\n model.link &&\n 'additionalProperties' in schema &&\n schema.additionalProperties &&\n !visited.has(modelLink)\n ) {\n const subSchema = resolveIfRef(spec, schema.additionalProperties);\n // Additional properties can be \"true\" rather than a type\n if (subSchema !== true) {\n await mutateWithOpenapiSchemaProperties(\n spec,\n modelLink,\n subSchema,\n modelsByName,\n visited,\n );\n }\n }\n\n for (const property of model.properties.filter(\n (p) => !visited.has(p) && schema.properties?.[trim(p.name, `\"'`)],\n )) {\n const subSchema = resolveIfRef(\n spec,\n schema.properties![trim(property.name, `\"'`)],\n );\n await mutateWithOpenapiSchemaProperties(\n spec,\n property,\n subSchema,\n modelsByName,\n visited,\n );\n }\n\n if (COMPOSED_SCHEMA_TYPES.has(model.export)) {\n for (let i = 0; i < model.properties.length; i++) {\n const subSchema = resolveIfRef(\n spec,\n (schema as any)[camelCase(model.export)]?.[i],\n );\n if (subSchema) {\n await mutateWithOpenapiSchemaProperties(\n spec,\n model.properties[i],\n subSchema,\n modelsByName,\n visited,\n );\n }\n }\n }\n};\n\n/**\n * Ensure that the \"link\" property of all dictionary/array models and properties are set recursively\n */\nconst ensureModelLinks = (spec: Spec, data: ClientData) => {\n const modelsByName = Object.fromEntries(data.models.map((m) => [m.name, m]));\n const visited = new Set<Model>();\n\n // Ensure set for all models\n data.models.forEach((model) => {\n const schema = resolveIfRef(spec, spec?.components?.schemas?.[model.name]);\n if (schema) {\n // Object schemas should be typed as the model we will create\n if (\n schema.type === 'object' &&\n (schema.properties || (schema as any).patternProperties)\n ) {\n model.type = model.name;\n }\n _ensureModelLinks(spec, modelsByName, model, schema, visited);\n }\n });\n\n // Ensure set for all parameters and responses\n data.services.forEach((service) => {\n service.operations.forEach((op) => {\n const specOp = (spec as any)?.paths?.[op.path]?.[\n op.method.toLowerCase()\n ] as OpenAPIV3.OperationObject | undefined;\n\n const specParametersByName = Object.fromEntries(\n (specOp?.parameters ?? []).map((p) => {\n const param = resolveIfRef(spec, p);\n return [param.name, param];\n }),\n );\n\n op.parameters.forEach((parameter) => {\n const specParameter = specParametersByName[parameter.prop];\n const specParameterSchema = resolveIfRef(spec, specParameter?.schema);\n\n if (specParameterSchema) {\n _ensureModelLinks(\n spec,\n modelsByName,\n parameter,\n specParameterSchema,\n visited,\n );\n } else if (parameter.in === 'body') {\n // Body is not in the \"parameters\" section of the OpenAPI spec so we handle it in an explicit case here\n const specBody = resolveIfRef(spec, specOp?.requestBody);\n const specBodySchema = resolveIfRef(\n spec,\n specBody?.content?.[parameter.mediaType]?.schema,\n );\n\n if (specBodySchema) {\n _ensureModelLinks(\n spec,\n modelsByName,\n parameter,\n specBodySchema,\n visited,\n );\n }\n }\n });\n\n op.responses.forEach((response) => {\n const specResponse = resolveIfRef(\n spec,\n specOp?.responses?.[response.code],\n );\n const mediaTypes = Object.keys(specResponse?.content ?? {});\n mediaTypes.forEach((mediaType) => {\n const responseSchema = resolveIfRef(\n spec,\n specResponse?.content?.[mediaType]?.schema,\n );\n if (responseSchema) {\n _ensureModelLinks(\n spec,\n modelsByName,\n response,\n responseSchema,\n visited,\n );\n }\n });\n });\n });\n });\n};\n\nconst _ensureModelLinks = (\n spec: Spec,\n modelsByName: { [name: string]: Model },\n model: Model,\n schema: OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject,\n visited: Set<Model>,\n) => {\n if (visited.has(model)) {\n return;\n }\n\n visited.add(model);\n\n if (\n model.export === 'dictionary' &&\n 'additionalProperties' in schema &&\n schema.additionalProperties\n ) {\n if (isRef(schema.additionalProperties)) {\n const name = splitRef(schema.additionalProperties.$ref)[2];\n if (modelsByName[name] && !model.link) {\n model.link = modelsByName[name];\n }\n } else if (model.link && typeof schema.additionalProperties !== 'boolean') {\n _ensureModelLinks(\n spec,\n modelsByName,\n flattenModelLink(model.link),\n schema.additionalProperties,\n visited,\n );\n }\n } else if (model.export === 'array' && 'items' in schema && schema.items) {\n if (isRef(schema.items)) {\n const name = splitRef(schema.items.$ref)[2];\n if (modelsByName[name] && !model.link) {\n model.link = modelsByName[name];\n }\n } else if (model.link) {\n _ensureModelLinks(\n spec,\n modelsByName,\n flattenModelLink(model.link),\n schema.items,\n visited,\n );\n }\n }\n\n model.properties\n .filter((p) => !visited.has(p) && schema.properties?.[trim(p.name, `\"'`)])\n .forEach((property) => {\n const subSchema = resolveIfRef(\n spec,\n schema.properties![trim(property.name, `\"'`)],\n );\n _ensureModelLinks(spec, modelsByName, property, subSchema, visited);\n });\n\n if (COMPOSED_SCHEMA_TYPES.has(model.export)) {\n model.properties.forEach((property, i) => {\n const subSchema = resolveIfRef(\n spec,\n (schema as any)[camelCase(model.export)]?.[i],\n );\n if (subSchema) {\n _ensureModelLinks(spec, modelsByName, property, subSchema, visited);\n }\n });\n }\n};\n\n/**\n * Mutates the given data to ensure composite models (ie allOf, oneOf, anyOf) have the necessary\n * properties for representing them in generated code. Adds `composedModels` and `composedPrimitives`\n * which contain the models and primitive types that each model is composed of.\n */\nconst ensureCompositeModels = (data: ClientData) => {\n const visited = new Set<Model>();\n data.models.forEach((model) =>\n mutateModelWithCompositeProperties(data, model, visited),\n );\n};\n\nconst mutateModelWithCompositeProperties = (\n data: ClientData,\n model: Model,\n visited: Set<Model>,\n) => {\n if (COMPOSED_SCHEMA_TYPES.has(model.export) && !visited.has(model)) {\n visited.add(model);\n\n // Find the models/primitives which this is composed from\n const composedModelReferences = model.properties.filter(\n (p) => !p.name && p.export === 'reference',\n );\n const composedPrimitives = model.properties.filter(\n (p) => !p.name && p.export !== 'reference',\n );\n\n const modelsByName = Object.fromEntries(\n data.models.map((m) => [m.name, m]),\n );\n let composedModels = composedModelReferences.flatMap((r) =>\n modelsByName[r.type] ? [modelsByName[r.type]] : [],\n );\n // Recursively resolve composed properties of properties, to ensure mixins for all-of include all recursive all-of properties\n composedModels.forEach((m) =>\n mutateModelWithCompositeProperties(data, m, visited),\n );\n\n // Enums are models, however they are serialised as primitives and so should be moved to the primitives list\n composedPrimitives.push(\n ...composedModels.filter((m) => m.export === 'enum'),\n );\n composedModels = composedModels.filter((m) => m.export !== 'enum');\n\n // When multiple arrays of non-primitives are composed using allOf/oneOf/anyOf, it's not possible to distinguish at runtime which\n // type it is, and so we validate this away.\n // TODO: consider honouring more advanced OpenAPI spec features like \"discriminators\" which can help for this case, but in practice\n // users are unlikely to model their API this way\n const isPrimitiveArray = (m: Model) => {\n if (m.link && ['array', 'dictionary'].includes(m.export)) {\n return isPrimitiveArray(flattenModelLink(m.link));\n }\n return (\n PRIMITIVE_TYPES.has(m.type) && !['date', 'date-time'].includes(m.format)\n );\n };\n const arrayComposedModels = composedPrimitives.filter(\n (m) => m.export === 'array' && !isPrimitiveArray(m),\n );\n if (arrayComposedModels.length > 1) {\n throw new Error(\n `Schema \"${model.name}\" defines ${camelCase(model.export)} with multiple array types which cannot be distinguished at runtime.`,\n );\n }\n\n // For all-of models, we include all composed model properties.\n if (model.export === 'all-of') {\n if (composedPrimitives.length > 0) {\n throw new Error(\n `Schema \"${model.name}\" defines allOf with non-object types. allOf may only compose object types in the OpenAPI specification.`,\n );\n }\n }\n\n (model as any).composedModels = composedModels;\n (model as any).composedPrimitives = composedPrimitives;\n }\n};\n\n/**\n * Mutates the given model to add language specific types and names\n */\nconst mutateModelWithAdditionalTypes = (model: Model) => {\n // Trim any surrounding quotes from name\n model.name = trim(model.name, `\"'`);\n\n (model as any).typescriptName = toTypeScriptName(model.name);\n (model as any).typescriptType = toTypeScriptType(model);\n (model as any).pythonName = toPythonName('property', model.name);\n (model as any).pythonType = toPythonType(model);\n (model as any).isPrimitive =\n PRIMITIVE_TYPES.has(model.type) &&\n !COMPOSED_SCHEMA_TYPES.has(model.export) &&\n !COLLECTION_TYPES.has(model.export);\n};\n\n/**\n * Determine whether or not an operation is a mutation\n */\nconst isOperationMutation = (op: Operation): boolean => {\n // Let the user override whether an operation is a query or mutation using x-mutation/x-query\n const { vendorExtensions } = op as any;\n if (vendorExtensions?.[VENDOR_EXTENSIONS.MUTATION]) {\n return true;\n } else if (vendorExtensions?.[VENDOR_EXTENSIONS.QUERY]) {\n return false;\n }\n // Assume a restful API and treat mutative HTTP methods as mutations\n return ['PATCH', 'POST', 'PUT', 'DELETE'].includes(op.method);\n};\n\n/**\n * Add infinite query details to the operation\n */\nconst mutateOperationWithInfiniteQueryDetails = (op: Operation) => {\n const { paginationDisabled, cursorPropertyName } = getCursorOptions(op);\n\n // Allow users to customise the \"cursor\" property used for paginated requests\n const cursorProperty = op.parameters.find(\n (p) => p.name === cursorPropertyName,\n );\n\n // The operation is an infinite query if:\n // - x-cursor is not set to 'false' (this allows users to disable infinite queries for operations that accept a 'cursor')\n // - the operation accepts a parameter named 'cursor', or a parameter named as the user specified with x-cursor\n (op as any).isInfiniteQuery = !paginationDisabled && !!cursorProperty;\n if ((op as any).isInfiniteQuery) {\n (op as any).infiniteQueryCursorProperty = cursorProperty;\n }\n};\n\n/**\n * Extracts the cursor options for this operation based on the vendor extensions\n *\n * Valid usage of x-cursor:\n *\n * x-cursor: 'property' - customises the input property used for pagination\n * x-cursor: false - disables pagination for the operation (ie the operation would have pagination by default as an input 'cursor' property exists)\n *\n * We also support object equivalents of the above, since Smithy vendor extensions can only be objects\n *\n * x-cursor: { inputToken: 'property' }\n * x-cursor: { enabled: false }\n */\nconst getCursorOptions = (op: Operation) => {\n const { vendorExtensions } = op as any;\n\n const cursorExtension = vendorExtensions?.[VENDOR_EXTENSIONS.CURSOR];\n\n // By default pagination isn't explicitly disabled and the cursor property to look for is 'cursor'\n let paginationDisabled = false;\n let cursorPropertyName = 'cursor';\n\n if (typeof cursorExtension === 'boolean' && cursorExtension === false) {\n paginationDisabled = true;\n } else if (typeof cursorExtension === 'string') {\n cursorPropertyName = cursorExtension;\n } else if (typeof cursorExtension === 'object') {\n if (cursorExtension?.enabled === false) {\n paginationDisabled = true;\n }\n if (\n cursorExtension?.inputToken &&\n typeof cursorExtension.inputToken === 'string'\n ) {\n cursorPropertyName = cursorExtension.inputToken;\n }\n }\n\n // x-cursor can be: a string (indicating pagination is enabled and the property name to use)\n\n return {\n paginationDisabled,\n cursorPropertyName,\n };\n};\n\n/**\n * Add additional data to an operation for code generation decisions\n */\nconst mutateOperationWithAdditionalData = (op: Operation) => {\n // Add mutation/query details\n const isMutation = isOperationMutation(op);\n (op as any).isMutation = isMutation;\n (op as any).isQuery = !isMutation;\n\n // Streaming responses\n (op as any).isStreaming =\n !!(op as any).vendorExtensions?.[VENDOR_EXTENSIONS.STREAMING] ||\n op.responses.some((res) => (res as any).isJsonlStreaming);\n\n // Set the result type for the client method to the item schema so that\n // it will resolve to AsyncIterableIterator<{itemSchemaModel.name}>\n const jsonlResponse = op.responses.find(\n (res) => (res as any).isJsonlStreaming,\n );\n if (jsonlResponse) {\n const itemSchemaModel = (jsonlResponse as any).itemSchemaModel;\n const result = (op as any).result;\n if (result && itemSchemaModel) {\n result.type = itemSchemaModel.name;\n result.typescriptType = itemSchemaModel.name;\n result.export = 'reference';\n }\n }\n\n // Add infinite query details if applicable\n if (!isMutation) {\n mutateOperationWithInfiniteQueryDetails(op);\n }\n};\n"],"names":["gen","camelCase","orderBy","trim","uniqBy","kebabCase","pascalCase","snakeCase","toClassName","upperFirst","toPythonName","toPythonType","toTypeScriptModelName","toTypeScriptName","toTypeScriptType","COLLECTION_TYPES","COMPOSED_SCHEMA_TYPES","flattenModelLink","PRIMITIVE_TYPES","STREAMING_CONTENT_TYPES","VENDOR_EXTENSIONS","normaliseOpenApiSpecForCodeGen","isRef","resolveIfRef","splitRef","buildOpenApiCodeGenData","inSpec","spec","data","buildInitialCodeGenData","ensureModelLinks","ensureCompositeModels","modelsByName","Object","fromEntries","models","map","m","name","service","services","requestModelImports","responseModelImports","op","operations","specOp","paths","path","method","toLowerCase","id","uniqueName","dotNotationName","vendorExtensions","copyVendorExtensions","push","responses","filter","r","export","type","response","has","composedPrimitives","p","includes","length","Error","matchingSpecResponse","code","specResponse","content","mediaTypes","keys","mediaType","responseContent","values","responseSchema","schema","mutateWithOpenapiSchemaProperties","isJsonlStreaming","itemSchemaModel","buildOrReferenceModel","itemSchema","specParametersByName","parameters","param","parameter","specParameter","prop","specParameterSchema","in","specBody","requestBody","bodySchema","style","explode","collectionFormat","spaceDelimited","pipeDelimited","simple","form","mutateModelWithAdditionalTypes","forEach","result","find","operationIdPascalCase","operationIdKebabCase","operationIdSnakeCase","baseRequestTypeName","hasConflict","components","schemas","requestTypeName","mutateOperationWithAdditionalData","modelImports","imports","x","className","classNameSnakeCase","nameSnakeCase","allOperations","flatMap","s","o","parametersByPosition","hasClashingPropertyName","properties","some","requestBodyParameter","explicitRequestBodyParameter","entries","position","$refs","base","description","enum","enums","link","undefined","template","isDefinition","isNullable","isReadOnly","isRequired","model","matchingSpecModel","specModel","uniqueImports","modelImport","deprecated","property","matchingSpecProperty","specProperty","typescriptName","typescriptType","d","operationsByTag","untaggedOperations","tags","tag","info","title","plugin","_handler","_handlerLegacy","client","createClient","experimentalParser","input","output","plugins","dryRun","logs","level","buildModelForPrimitive","originalSpec","targetSchemaName","openapi","version","JSON","stringify","$ref","object","key","value","startsWith","visited","Set","format","isInteger","isShort","isLong","openapiType","isNotSchema","not","isEnum","isHoisted","additionalProperties","additionalPropertiesModel","explicitProperties","patternProperties","hasAdditionalProperties","patternPropertiesModels","pattern","patternProperty","patternPropertyModel","hasPatternProperties","add","modelLink","items","subSchema","i","_ensureModelLinks","specBodySchema","mutateModelWithCompositeProperties","composedModelReferences","composedModels","isPrimitiveArray","arrayComposedModels","pythonName","pythonType","isPrimitive","isOperationMutation","MUTATION","QUERY","mutateOperationWithInfiniteQueryDetails","paginationDisabled","cursorPropertyName","getCursorOptions","cursorProperty","isInfiniteQuery","infiniteQueryCursorProperty","cursorExtension","CURSOR","enabled","in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L,qBAAqBK;IACvB,OAAO,IAAI,OAAOA,oBAAoB,UAAU;QAC9C,IAAIA,iBAAiBE,YAAY,OAAO;YACtCR,qBAAqB;QACvB;QACA,IACEM,iBAAiBG,cACjB,OAAOH,gBAAgBG,UAAU,KAAK,UACtC;YACAR,qBAAqBK,gBAAgBG,UAAU;QACjD;IACF;IAEA,4FAA4F;IAE5F,OAAO;QACLT;QACAC;IACF;AACF;AAEA;;CAEC,GACD,MAAMlH,oCAAoC,CAACvE;IACzC,6BAA6B;IAC7B,MAAMkM,aAAad,oBAAoBpL;IACtCA,GAAWkM,UAAU,GAAGA;IACxBlM,GAAWmM,OAAO,GAAG,CAACD;IAEvB,sBAAsB;IACrBlM,GAAWoM,WAAW,GACrB,CAAC,CAAC,AAACpM,GAAWU,gBAAgB,EAAE,CAACjC,kBAAkB4N,SAAS,CAAC,IAC7DrM,GAAGa,SAAS,CAACwE,IAAI,CAAC,CAACiH,MAAQ,AAACA,IAAYjK,gBAAgB;IAE1D,uEAAuE;IACvE,mEAAmE;IACnE,MAAMkK,gBAAgBvM,GAAGa,SAAS,CAACiD,IAAI,CACrC,CAACwI,MAAQ,AAACA,IAAYjK,gBAAgB;IAExC,IAAIkK,eAAe;QACjB,MAAMjK,kBAAkB,AAACiK,cAAsBjK,eAAe;QAC9D,MAAMuB,SAAS,AAAC7D,GAAW6D,MAAM;QACjC,IAAIA,UAAUvB,iBAAiB;YAC7BuB,OAAO5C,IAAI,GAAGqB,gBAAgB3C,IAAI;YAClCkE,OAAOmD,cAAc,GAAG1E,gBAAgB3C,IAAI;YAC5CkE,OAAO7C,MAAM,GAAG;QAClB;IACF;IAEA,2CAA2C;IAC3C,IAAI,CAACkL,YAAY;QACfX,wCAAwCvL;IAC1C;AACF"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/utils/codegen-data.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport orderBy from 'lodash.orderby';\nimport trim from 'lodash.trim';\nimport uniqBy from 'lodash.uniqby';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport {\n camelCase,\n pascalCase,\n snakeCase,\n toClassName,\n upperFirst,\n} from '../../utils/names';\nimport {\n toPythonName,\n toPythonType,\n toTypeScriptModelName,\n toTypeScriptName,\n toTypeScriptType,\n} from './codegen-data/languages';\nimport {\n COLLECTION_TYPES,\n COMPOSED_SCHEMA_TYPES,\n type CodeGenData,\n type CollectionFormat,\n createModel,\n DEFAULT_SERVICE_NAME,\n indexModelsByName,\n type Model,\n type ModelsByName,\n type Operation,\n type PatternPropertyModel,\n PRIMITIVE_TYPES,\n type Service,\n STREAMING_CONTENT_TYPES,\n VENDOR_EXTENSIONS,\n type VendorExtensions,\n} from './codegen-data/types';\nimport { normaliseOpenApiSpecForCodeGen } from './normalise';\nimport {\n buildClientData,\n buildInlineModel,\n compositeMemberSchemas,\n getSpecOperation,\n getSpecParametersByKey,\n getSpecPathParameters,\n linkModel,\n specParameterKey,\n} from './parser';\nimport { isRef, resolveIfRef, splitRef } from './refs';\nimport type { OpenApiSchema, OpenApiSchemaOrRef, Spec } from './types';\n\n/**\n * Build the data structure used to generate code from an OpenAPI spec.\n */\nexport const buildOpenApiCodeGenData = (inSpec: Spec): CodeGenData => {\n const spec = normaliseOpenApiSpecForCodeGen(inSpec);\n const data = buildClientData(spec);\n\n const modelsByName = indexModelsByName(data.models);\n\n for (const service of data.services) {\n augmentService(spec, service, modelsByName);\n }\n\n const allOperations = uniqBy(\n data.services.flatMap((s) => s.operations),\n (o) => o.uniqueName,\n );\n\n // A model per operation request parameter position (query/path/body/...).\n data.models = [\n ...data.models,\n ...allOperations.flatMap((op) =>\n buildRequestParameterModels(op, modelsByName),\n ),\n ];\n\n for (const model of data.models) {\n augmentModel(spec, model, modelsByName);\n }\n for (const model of data.models) {\n model.typescriptName = toTypeScriptModelName(model.name);\n model.typescriptType = model.typescriptName;\n }\n\n for (const model of data.models) {\n assertNoClashingPropertyNames(model);\n }\n\n data.models = orderBy(data.models, (d) => d.name);\n // Default service first, then by name.\n data.services = orderBy(data.services, (s) =>\n s.name === DEFAULT_SERVICE_NAME ? '' : s.name,\n );\n\n const { operationsByTag, untaggedOperations } =\n groupOperationsByTag(allOperations);\n\n return {\n ...data,\n operationsByTag,\n untaggedOperations,\n info: spec.info,\n allOperations,\n vendorExtensions: vendorExtensionsOf(spec),\n className: toClassName(spec.info.title),\n };\n};\n\n/**\n * Augment a service and each of its operations with the data needed for code\n * generation (names, imports, result/request types, behavioural flags), and\n * compute the set of models the service (ie API client) needs to import.\n */\nconst augmentService = (\n spec: Spec,\n service: Service,\n modelsByName: ModelsByName,\n): void => {\n const modelImports = service.operations.flatMap((op) =>\n augmentOperation(spec, op, modelsByName),\n );\n\n service.operations = orderBy(service.operations, (op) => op.uniqueName);\n service.modelImports = orderBy(\n uniqBy([...service.imports, ...modelImports], (x) => x),\n );\n service.className = `${service.name}Api`;\n service.nameSnakeCase = snakeCase(service.name);\n};\n\n/**\n * Augment a single operation with all the data the templates need, returning\n * the names of the models it references (for the service's import list).\n */\nconst augmentOperation = (\n spec: Spec,\n op: Operation,\n modelsByName: ModelsByName,\n): string[] => {\n const specOp = getSpecOperation(spec, op);\n\n assignOperationNames(op, specOp);\n\n op.vendorExtensions = vendorExtensionsOf(specOp);\n\n const modelImports = [\n ...(specOp ? augmentResponses(spec, op, specOp, modelsByName) : []),\n ...augmentParameters(spec, op, specOp, modelsByName),\n ];\n\n op.responses.forEach(addLanguageTypes);\n op.responses = orderBy(op.responses, (r) => r.code);\n\n // Result is the lowest successful response, otherwise the 2XX or default.\n op.result =\n op.responses.find(\n (r) => typeof r.code === 'number' && r.code >= 200 && r.code < 300,\n ) ?? op.responses.find((r) => r.code === '2XX' || r.code === 'default');\n\n op.operationIdPascalCase = pascalCase(op.uniqueName);\n op.operationIdSnakeCase = toPythonName('operation', op.uniqueName);\n\n if (op.parameters.length > 0) {\n const baseRequestTypeName = `${op.operationIdPascalCase}Request`;\n // Use the OperationRequest suffix when the standard Request name clashes\n // with an existing schema.\n op.requestTypeName = spec.components?.schemas?.[baseRequestTypeName]\n ? `${op.operationIdPascalCase}OperationRequest`\n : baseRequestTypeName;\n }\n\n augmentOperationBehaviour(op);\n\n return modelImports;\n};\n\n/**\n * Set an operation's name and its deduplicated variants from the vendor\n * extensions the normaliser added.\n */\nconst assignOperationNames = (\n op: Operation,\n specOp: OpenAPIV3.OperationObject | undefined,\n): void => {\n const deduplicatedOpId = specOp?.['x-aws-nx-deduplicated-op-id'] as\n | string\n | undefined;\n const dotNotationOpId = specOp?.['x-aws-nx-deduplicated-dot-op-id'] as\n | string\n | undefined;\n\n op.name = op.id ?? op.name;\n op.uniqueName = deduplicatedOpId ?? op.name;\n if (dotNotationOpId) {\n op.dotNotationName = dotNotationOpId;\n }\n};\n\n/**\n * Augment an operation's response models with schema-derived data, resolving\n * void responses and streaming item schemas. Returns the response model names\n * to import.\n */\nconst augmentResponses = (\n spec: Spec,\n op: Operation,\n specOp: OpenAPIV3.OperationObject,\n modelsByName: ModelsByName,\n): string[] => {\n const modelImports = op.responses\n .filter((r) => r.export === 'reference')\n .map((r) => r.type);\n\n for (const response of op.responses) {\n // We cannot distinguish a composite of primitives at runtime (it all comes\n // back as text), so validate this away.\n if (\n response.export === 'reference' &&\n COMPOSED_SCHEMA_TYPES.has(modelsByName[response.type]?.export)\n ) {\n const composedPrimitives = (\n modelsByName[response.type].composedPrimitives ?? []\n ).filter((p) => !COLLECTION_TYPES.has(p.export));\n if (composedPrimitives.length > 0) {\n throw new Error(\n `Operation \"${op.method} ${op.path}\" returns a composite schema of primitives with ${camelCase(modelsByName[response.type].export)}, which cannot be distinguished at runtime`,\n );\n }\n }\n\n const matchingSpecResponse = specOp.responses[`${response.code}`];\n if (!matchingSpecResponse) continue;\n\n const specResponse = resolveIfRef(spec, matchingSpecResponse);\n\n // When there's no content, the response type is 'void'\n if (!specResponse.content) {\n response.type = 'void';\n continue;\n }\n\n const mediaTypes = Object.keys(specResponse.content);\n response.mediaTypes = mediaTypes;\n\n for (const mediaType of mediaTypes) {\n const responseContent = specResponse.content[mediaType];\n const responseSchema = resolveIfRef(spec, responseContent.schema);\n if (responseSchema) {\n augmentModelFromSchema(spec, response, responseSchema, modelsByName);\n }\n if (\n STREAMING_CONTENT_TYPES.has(mediaType) &&\n 'itemSchema' in responseContent\n ) {\n response.isJsonlStreaming = true;\n response.itemSchemaModel = buildOrReferenceModel(\n spec,\n modelsByName,\n responseContent.itemSchema as OpenApiSchemaOrRef,\n );\n }\n }\n }\n\n return modelImports;\n};\n\n/**\n * Augment an operation's parameter models with schema-derived data, resolving\n * request bodies and query/header collection formats. Returns the parameter\n * model names to import.\n */\nconst augmentParameters = (\n spec: Spec,\n op: Operation,\n specOp: OpenAPIV3.OperationObject | undefined,\n modelsByName: ModelsByName,\n): string[] => {\n const specParametersByKey = getSpecParametersByKey(\n spec,\n specOp,\n getSpecPathParameters(spec, op),\n );\n\n const modelImports: string[] = [];\n\n for (const parameter of op.parameters) {\n if (parameter.export === 'reference') {\n modelImports.push(parameter.type);\n }\n\n const specParameter =\n specParametersByKey[\n specParameterKey({ in: parameter.in, name: parameter.prop })\n ];\n const specParameterSchema = resolveIfRef(spec, specParameter?.schema);\n if (specParameterSchema) {\n augmentModelFromSchema(\n spec,\n parameter,\n specParameterSchema,\n modelsByName,\n );\n }\n\n if (parameter.in === 'body') {\n augmentBodyParameter(spec, parameter, specOp, modelsByName);\n } else if (\n (parameter.in === 'query' || parameter.in === 'header') &&\n specParameter\n ) {\n parameter.collectionFormat = getCollectionFormat(\n parameter.in,\n specParameter,\n );\n }\n\n addLanguageTypes(parameter);\n }\n\n return modelImports;\n};\n\n/**\n * Augment a request body parameter with its schema (the body is not in the\n * spec's `parameters`, so it is resolved from `requestBody` here) and record\n * its acceptable media types.\n */\nconst augmentBodyParameter = (\n spec: Spec,\n parameter: Model,\n specOp: OpenAPIV3.OperationObject | undefined,\n modelsByName: ModelsByName,\n): void => {\n // The request body parameter is named 'body' downstream.\n parameter.name = 'body';\n parameter.prop = 'body';\n\n const specBody = resolveIfRef(spec, specOp?.requestBody);\n if (!specBody) return;\n\n if (parameter.mediaType) {\n const bodySchema = resolveIfRef(\n spec,\n specBody.content?.[parameter.mediaType]?.schema,\n );\n if (bodySchema) {\n augmentModelFromSchema(spec, parameter, bodySchema, modelsByName);\n }\n }\n // Track all the media types that can be accepted in the request body\n parameter.mediaTypes = Object.keys(specBody.content);\n};\n\n/**\n * Translate an OpenAPI v3 parameter's style/explode into a v2-style\n * collectionFormat used when serialising array parameters.\n * @see https://spec.openapis.org/oas/v3.0.3.html#style-values\n */\nconst getCollectionFormat = (\n position: 'query' | 'header',\n specParameter: OpenAPIV3.ParameterObject,\n): CollectionFormat => {\n const style =\n specParameter.style ?? (position === 'query' ? 'form' : 'simple');\n const explode = specParameter.explode ?? style === 'form';\n\n if (position === 'header') {\n return explode ? 'multi' : 'csv';\n }\n // `deepObject` serialises an object as `key[prop]=value` pairs regardless of\n // explode; the object shape (not array collection) drives its serialisation.\n if (style === 'deepObject') {\n return 'deepObject';\n }\n return explode\n ? 'multi'\n : ((\n {\n spaceDelimited: 'ssv',\n pipeDelimited: 'pipes',\n simple: 'csv',\n form: 'csv',\n } as const\n )[style] ?? 'multi');\n};\n\n/**\n * Build the request parameter models for an operation — one model per parameter\n * position (query/path/header/cookie/body), named e.g.\n * `FooRequestQueryParameters`. Request bodies that can be represented directly\n * (the sole parameter, or a non-clashing object reference) are inlined rather\n * than given a wrapper model, and recorded on `op.explicitRequestBodyParameter`.\n */\nconst buildRequestParameterModels = (\n op: Operation,\n modelsByName: ModelsByName,\n): Model[] => {\n if (!op.parameters || op.parameters.length === 0) {\n return [];\n }\n\n // Whether the request body can be represented directly, without a wrapper\n // model (ie the request will be the body itself).\n const canInlineBody = (body: Model): boolean => {\n // If the body is the only parameter, we can inline it no matter the type\n if (op.parameters.length === 1) {\n return true;\n }\n // We inline object bodies, so long as they aren't dictionaries (as\n // dictionary keys could clash with other parameters), and so long as they\n // don't have a property name that clashes with another parameter\n const hasClashingPropertyName = (\n modelsByName?.[body.type]?.properties ?? []\n ).some((prop) => op.parameters.some((param) => param.name === prop.name));\n return (\n body.export === 'reference' &&\n modelsByName?.[body.type]?.export !== 'dictionary' &&\n !hasClashingPropertyName\n );\n };\n\n // Group parameters by their position (`in`: query/path/header/cookie/body),\n // dropping any body that can be inlined.\n const parametersByPosition = op.parameters\n .filter((p) => !(p.in === 'body' && canInlineBody(p)))\n .reduce<{ [position: string]: Model[] }>(\n (acc, p) => ({ ...acc, [p.in]: [...(acc[p.in] ?? []), p] }),\n {},\n );\n\n // The body parameter was already renamed to \"body\" by augmentBodyParameter.\n op.explicitRequestBodyParameter = parametersByPosition['body']?.[0];\n\n return Object.entries(parametersByPosition).map(([position, parameters]) => {\n const name = `${op.operationIdPascalCase}Request${upperFirst(position)}Parameters`;\n return createModel({\n description: op.description,\n export: 'interface',\n name,\n properties: parameters,\n type: name,\n isRequired: true,\n });\n });\n};\n\n/**\n * Augment a single model with schema-derived data (from its matching spec\n * schema, if any) and language-specific names and types.\n */\nconst augmentModel = (\n spec: Spec,\n model: Model,\n modelsByName: ModelsByName,\n): void => {\n model.nameSnakeCase = toPythonName('model', model.name);\n\n const matchingSpecModel = spec?.components?.schemas?.[model.name];\n if (matchingSpecModel) {\n const specModel = resolveIfRef(spec, matchingSpecModel);\n\n augmentModelFromSchema(spec, model, specModel, modelsByName);\n\n for (const property of model.properties) {\n const matchingSpecProperty = specModel.properties?.[property.name];\n if (matchingSpecProperty) {\n const specProperty = resolveIfRef(spec, matchingSpecProperty);\n augmentModelFromSchema(spec, property, specProperty, modelsByName);\n }\n }\n }\n\n model.properties.forEach(addLanguageTypes);\n\n // Resolve the discriminator's TypeScript property name for marshalling.\n if (model.discriminator) {\n model.discriminator.typescriptPropertyName = toTypeScriptName(\n model.discriminator.propertyName,\n );\n }\n};\n\n/**\n * Ensure no two properties/parameters of an object model collapse onto the same\n * TypeScript identifier (e.g. `foo-bar` and `foo_bar` both camelCase to\n * `fooBar`, or a query and header parameter sharing a name within one request\n * position). Such a clash would emit a type with duplicate members that does\n * not compile, so fail fast with an actionable error instead.\n */\nconst assertNoClashingPropertyNames = (model: Model): void => {\n const seen = new Map<string, string>();\n for (const property of model.properties) {\n // Composite members are unnamed (their names are empty); skip them.\n if (!property.name) continue;\n const existing = seen.get(property.typescriptName!);\n if (existing !== undefined && existing !== property.name) {\n throw new Error(\n `Property name conflict in \"${model.name}\": \"${existing}\" and \"${property.name}\" both map to the TypeScript name \"${property.typescriptName}\". Please rename one of these in your OpenAPI specification.`,\n );\n }\n seen.set(property.typescriptName!, property.name);\n }\n};\n\n/**\n * Group operations by their (camelCased) tags, collecting any untagged\n * operations separately.\n */\nconst groupOperationsByTag = (\n allOperations: Operation[],\n): {\n operationsByTag: { [tag: string]: Operation[] };\n untaggedOperations: Operation[];\n} => {\n const isTagged = (op: Operation): boolean => !!op.tags && op.tags.length > 0;\n\n const operationsByTag = allOperations\n .filter(isTagged)\n .flatMap((op) => op.tags!.map((tag) => [camelCase(tag), op] as const))\n .reduce<{ [tag: string]: Operation[] }>(\n (acc, [tag, op]) => ({ ...acc, [tag]: [...(acc[tag] ?? []), op] }),\n {},\n );\n\n return {\n operationsByTag,\n untaggedOperations: allOperations.filter((op) => !isTagged(op)),\n };\n};\n\n/**\n * Resolve a schema to its model: an existing named model for a `$ref`, or a\n * freshly built-and-augmented model for an inline (nested value) schema.\n */\nconst buildOrReferenceModel = (\n spec: Spec,\n modelsByName: ModelsByName,\n schema: OpenApiSchemaOrRef,\n): Model => {\n if (isRef(schema)) {\n const name = splitRef(schema.$ref)[2];\n return modelsByName[name];\n }\n const model = buildInlineModel(spec, schema);\n linkModel(spec, modelsByName, model, schema);\n augmentModelFromSchema(spec, model, schema, modelsByName);\n return model;\n};\n\n/**\n * The `x-*` vendor extensions declared on an object.\n */\nconst vendorExtensionsOf = (object: object | undefined): VendorExtensions =>\n Object.fromEntries(\n Object.entries(object ?? {}).filter(([key]) => key.startsWith('x-')),\n );\n\nconst augmentModelFromSchema = (\n spec: Spec,\n model: Model,\n schema: OpenApiSchema,\n modelsByName: ModelsByName,\n visited: Set<Model> = new Set(),\n) => {\n model.format = schema.format;\n model.deprecated = !!schema.deprecated;\n model.openapiType = schema.type;\n model.isEnum = !!schema.enum && schema.enum.length > 0;\n model.vendorExtensions = vendorExtensionsOf(schema);\n\n // A \"dictionary\" has only additional properties; an \"interface\" may mix\n // explicit and additional properties.\n if (schema.additionalProperties) {\n const additionalPropertiesModel = buildOrReferenceModel(\n spec,\n modelsByName,\n schema.additionalProperties === true ? {} : schema.additionalProperties,\n );\n\n if (model.export === 'dictionary') {\n // A dictionary carries a self-referential property; the rest are explicit\n const explicitProperties = model.properties.filter(\n (p) => !(p.export === 'dictionary' && p.name === model.name),\n );\n\n // Explicit properties make this an interface rather than a dictionary\n if (explicitProperties.length > 0 || schema.patternProperties) {\n model.export = 'interface';\n model.hasAdditionalProperties = true;\n model.additionalPropertiesModel = additionalPropertiesModel;\n model.properties = explicitProperties;\n }\n } else {\n model.hasAdditionalProperties = true;\n model.additionalPropertiesModel = additionalPropertiesModel;\n }\n }\n\n // Pattern properties can have different value types per pattern, so the model\n // is an interface rather than a dictionary.\n if (schema.patternProperties) {\n const patternProperties = resolveIfRef(spec, schema.patternProperties);\n\n if (model.export === 'dictionary') {\n model.export = 'interface';\n }\n\n model.hasPatternProperties = true;\n model.patternPropertiesModels = Object.entries(patternProperties)\n .map(([pattern, patternProperty]) => ({\n pattern,\n model: buildOrReferenceModel(spec, modelsByName, patternProperty),\n }))\n .filter((entry): entry is PatternPropertyModel => !!entry.model);\n }\n\n addLanguageTypes(model);\n\n visited.add(model);\n\n const recurse = (target: Model, subSchema: OpenApiSchema): void =>\n augmentModelFromSchema(spec, target, subSchema, modelsByName, visited);\n\n // Array element type.\n if (\n model.export === 'array' &&\n model.link &&\n 'items' in schema &&\n schema.items &&\n !visited.has(model.link)\n ) {\n recurse(model.link, resolveIfRef(spec, schema.items));\n }\n\n // Dictionary value type (additionalProperties may be `true` rather than a\n // schema).\n if (\n model.export === 'dictionary' &&\n model.link &&\n 'additionalProperties' in schema &&\n schema.additionalProperties &&\n !visited.has(model.link)\n ) {\n const subSchema = resolveIfRef(spec, schema.additionalProperties);\n if (subSchema !== true) {\n recurse(model.link, subSchema);\n }\n }\n\n model.properties\n .filter((p) => !visited.has(p) && schema.properties?.[trim(p.name, `\"'`)])\n .forEach((property) =>\n recurse(\n property,\n resolveIfRef(spec, schema.properties![trim(property.name, `\"'`)]),\n ),\n );\n\n if (COMPOSED_SCHEMA_TYPES.has(model.export)) {\n const memberSchemas = compositeMemberSchemas(schema, model.export);\n model.properties.forEach((property, i) => {\n const subSchema = resolveIfRef(spec, memberSchemas[i]);\n if (subSchema) {\n recurse(property, subSchema);\n }\n });\n }\n};\n\nconst addLanguageTypes = (model: Model) => {\n model.name = trim(model.name, `\"'`);\n model.typescriptName = toTypeScriptName(model.name);\n model.typescriptType = toTypeScriptType(model);\n model.pythonName = toPythonName('property', model.name);\n model.pythonType = toPythonType(model);\n model.isPrimitive =\n PRIMITIVE_TYPES.has(model.type) &&\n !COMPOSED_SCHEMA_TYPES.has(model.export) &&\n !COLLECTION_TYPES.has(model.export);\n};\n\nconst isOperationMutation = (op: Operation): boolean => {\n // x-mutation/x-query override the HTTP-method default.\n const { vendorExtensions } = op;\n if (vendorExtensions?.[VENDOR_EXTENSIONS.MUTATION]) {\n return true;\n } else if (vendorExtensions?.[VENDOR_EXTENSIONS.QUERY]) {\n return false;\n }\n return ['PATCH', 'POST', 'PUT', 'DELETE'].includes(op.method);\n};\n\nconst augmentInfiniteQuery = (op: Operation) => {\n const { paginationDisabled, cursorPropertyName } = getCursorOptions(op);\n\n const cursorProperty = op.parameters.find(\n (p) => p.name === cursorPropertyName,\n );\n\n // An infinite query is a paginated operation that accepts the cursor parameter\n op.isInfiniteQuery = !paginationDisabled && !!cursorProperty;\n if (op.isInfiniteQuery) {\n op.infiniteQueryCursorProperty = cursorProperty;\n }\n};\n\n/**\n * Resolve the pagination cursor options from an operation's `x-cursor` vendor\n * extension. Accepted forms (object variants exist because Smithy vendor\n * extensions must be objects):\n *\n * - `'property'` / `{ inputToken: 'property' }` — the input property to page on\n * - `false` / `{ enabled: false }` — disable pagination\n */\nconst getCursorOptions = (\n op: Operation,\n): { paginationDisabled: boolean; cursorPropertyName: string } => {\n const cursor = op.vendorExtensions?.[VENDOR_EXTENSIONS.CURSOR];\n\n // Defaults: pagination enabled, paging on a property named 'cursor'.\n if (cursor === false) {\n return { paginationDisabled: true, cursorPropertyName: 'cursor' };\n }\n if (typeof cursor === 'string') {\n return { paginationDisabled: false, cursorPropertyName: cursor };\n }\n const options = (cursor ?? {}) as { enabled?: boolean; inputToken?: unknown };\n return {\n paginationDisabled: options.enabled === false,\n cursorPropertyName:\n typeof options.inputToken === 'string' ? options.inputToken : 'cursor',\n };\n};\n\n/**\n * Add query/mutation, streaming and infinite-query flags to an operation.\n */\nconst augmentOperationBehaviour = (op: Operation) => {\n const isMutation = isOperationMutation(op);\n op.isMutation = isMutation;\n op.isQuery = !isMutation;\n\n op.isStreaming =\n !!op.vendorExtensions?.[VENDOR_EXTENSIONS.STREAMING] ||\n op.responses.some((res) => res.isJsonlStreaming);\n\n // For JSON-lines streaming, the result is each streamed item, so the client\n // method returns AsyncIterableIterator<itemSchemaModel>. Named (hoisted)\n // item schemas become references; inline primitives keep their own type.\n const jsonlResponse = op.responses.find((res) => res.isJsonlStreaming);\n if (jsonlResponse) {\n const itemSchemaModel = jsonlResponse.itemSchemaModel;\n const result = op.result;\n if (result && itemSchemaModel) {\n if (itemSchemaModel.name) {\n result.type = itemSchemaModel.name;\n result.typescriptType = itemSchemaModel.name;\n result.export = 'reference';\n } else {\n result.type = itemSchemaModel.type;\n result.typescriptType = itemSchemaModel.typescriptType;\n result.export = itemSchemaModel.export;\n result.format = itemSchemaModel.format;\n result.link = itemSchemaModel.link;\n result.isPrimitive = itemSchemaModel.isPrimitive;\n }\n }\n }\n\n // Add infinite query details if applicable\n if (!isMutation) {\n augmentInfiniteQuery(op);\n }\n};\n"],"names":["orderBy","trim","uniqBy","camelCase","pascalCase","snakeCase","toClassName","upperFirst","toPythonName","toPythonType","toTypeScriptModelName","toTypeScriptName","toTypeScriptType","COLLECTION_TYPES","COMPOSED_SCHEMA_TYPES","createModel","DEFAULT_SERVICE_NAME","indexModelsByName","PRIMITIVE_TYPES","STREAMING_CONTENT_TYPES","VENDOR_EXTENSIONS","normaliseOpenApiSpecForCodeGen","buildClientData","buildInlineModel","compositeMemberSchemas","getSpecOperation","getSpecParametersByKey","getSpecPathParameters","linkModel","specParameterKey","isRef","resolveIfRef","splitRef","buildOpenApiCodeGenData","inSpec","spec","data","modelsByName","models","service","services","augmentService","allOperations","flatMap","s","operations","o","uniqueName","op","buildRequestParameterModels","model","augmentModel","typescriptName","name","typescriptType","assertNoClashingPropertyNames","d","operationsByTag","untaggedOperations","groupOperationsByTag","info","vendorExtensions","vendorExtensionsOf","className","title","modelImports","augmentOperation","imports","x","nameSnakeCase","specOp","assignOperationNames","augmentResponses","augmentParameters","responses","forEach","addLanguageTypes","r","code","result","find","operationIdPascalCase","operationIdSnakeCase","parameters","length","baseRequestTypeName","requestTypeName","components","schemas","augmentOperationBehaviour","deduplicatedOpId","dotNotationOpId","id","dotNotationName","filter","export","map","type","response","has","composedPrimitives","p","Error","method","path","matchingSpecResponse","specResponse","content","mediaTypes","Object","keys","mediaType","responseContent","responseSchema","schema","augmentModelFromSchema","isJsonlStreaming","itemSchemaModel","buildOrReferenceModel","itemSchema","specParametersByKey","parameter","push","specParameter","in","prop","specParameterSchema","augmentBodyParameter","collectionFormat","getCollectionFormat","specBody","requestBody","bodySchema","position","style","explode","spaceDelimited","pipeDelimited","simple","form","canInlineBody","body","hasClashingPropertyName","properties","some","param","parametersByPosition","reduce","acc","explicitRequestBodyParameter","entries","description","isRequired","matchingSpecModel","specModel","property","matchingSpecProperty","specProperty","discriminator","typescriptPropertyName","propertyName","seen","Map","existing","get","undefined","set","isTagged","tags","tag","$ref","object","fromEntries","key","startsWith","visited","Set","format","deprecated","openapiType","isEnum","enum","additionalProperties","additionalPropertiesModel","explicitProperties","patternProperties","hasAdditionalProperties","hasPatternProperties","patternPropertiesModels","pattern","patternProperty","entry","add","recurse","target","subSchema","link","items","memberSchemas","i","pythonName","pythonType","isPrimitive","isOperationMutation","MUTATION","QUERY","includes","augmentInfiniteQuery","paginationDisabled","cursorPropertyName","getCursorOptions","cursorProperty","isInfiniteQuery","infiniteQueryCursorProperty","cursor","CURSOR","options","enabled","inputToken","isMutation","isQuery","isStreaming","STREAMING","res","jsonlResponse"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,aAAa,iBAAiB;AACrC,OAAOC,UAAU,cAAc;AAC/B,OAAOC,YAAY,gBAAgB;AAEnC,SACEC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,WAAW,EACXC,UAAU,QACL,uBAAoB;AAC3B,SACEC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,gBAAgB,EAChBC,gBAAgB,QACX,8BAA2B;AAClC,SACEC,gBAAgB,EAChBC,qBAAqB,EAGrBC,WAAW,EACXC,oBAAoB,EACpBC,iBAAiB,EAKjBC,eAAe,EAEfC,uBAAuB,EACvBC,iBAAiB,QAEZ,0BAAuB;AAC9B,SAASC,8BAA8B,QAAQ,iBAAc;AAC7D,SACEC,eAAe,EACfC,gBAAgB,EAChBC,sBAAsB,EACtBC,gBAAgB,EAChBC,sBAAsB,EACtBC,qBAAqB,EACrBC,SAAS,EACTC,gBAAgB,QACX,cAAW;AAClB,SAASC,KAAK,EAAEC,YAAY,EAAEC,QAAQ,QAAQ,YAAS;AAGvD;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC;IACtC,MAAMC,OAAOd,+BAA+Ba;IAC5C,MAAME,OAAOd,gBAAgBa;IAE7B,MAAME,eAAepB,kBA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AAC,IACpD9K,GAAG0B,SAAS,CAACsE,IAAI,CAAC,CAAC+E,MAAQA,IAAI3G,gBAAgB;IAEjD,4EAA4E;IAC5E,yEAAyE;IACzE,yEAAyE;IACzE,MAAM4G,gBAAgBhL,GAAG0B,SAAS,CAACM,IAAI,CAAC,CAAC+I,MAAQA,IAAI3G,gBAAgB;IACrE,IAAI4G,eAAe;QACjB,MAAM3G,kBAAkB2G,cAAc3G,eAAe;QACrD,MAAMtC,SAAS/B,GAAG+B,MAAM;QACxB,IAAIA,UAAUsC,iBAAiB;YAC7B,IAAIA,gBAAgBhE,IAAI,EAAE;gBACxB0B,OAAOkB,IAAI,GAAGoB,gBAAgBhE,IAAI;gBAClC0B,OAAOzB,cAAc,GAAG+D,gBAAgBhE,IAAI;gBAC5C0B,OAAOgB,MAAM,GAAG;YAClB,OAAO;gBACLhB,OAAOkB,IAAI,GAAGoB,gBAAgBpB,IAAI;gBAClClB,OAAOzB,cAAc,GAAG+D,gBAAgB/D,cAAc;gBACtDyB,OAAOgB,MAAM,GAAGsB,gBAAgBtB,MAAM;gBACtChB,OAAOkG,MAAM,GAAG5D,gBAAgB4D,MAAM;gBACtClG,OAAOqH,IAAI,GAAG/E,gBAAgB+E,IAAI;gBAClCrH,OAAO2H,WAAW,GAAGrF,gBAAgBqF,WAAW;YAClD;QACF;IACF;IAEA,2CAA2C;IAC3C,IAAI,CAACiB,YAAY;QACfZ,qBAAqB/J;IACvB;AACF"}
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
- */ import camelCase from "lodash.camelcase";
5
- import cloneDeepWith from "lodash.clonedeepwith";
6
- import { pascalCase, toClassName, upperFirst } from "../../utils/names.js";
4
+ */ import cloneDeepWith from "lodash.clonedeepwith";
5
+ import { camelCase, pascalCase, toClassName, upperFirst } from "../../utils/names.js";
6
+ import { STREAMING_CONTENT_TYPES } from "./codegen-data/types.js";
7
7
  import { isRef, resolveIfRef, resolveRef, splitRef } from "./refs.js";
8
8
  /**
9
9
  * Normalise schema names to valid TypeScript identifiers.
@@ -11,9 +11,14 @@ import { isRef, resolveIfRef, resolveRef, splitRef } from "./refs.js";
11
11
  * Throws an error if normalisation would create a name clash.
12
12
  */ const normaliseSchemaNames = (spec)=>{
13
13
  const schemaNameMapping = {};
14
- const existingSchemaNames = new Set(Object.keys(spec.components?.schemas ?? {}));
14
+ const originalNames = Object.keys(spec.components?.schemas ?? {});
15
+ const existingSchemaNames = new Set(originalNames);
16
+ // The name each schema resolves to (its normalised form, or itself when it
17
+ // needs no normalisation). Used to detect two distinct schemas that would
18
+ // collapse onto the same identifier.
19
+ const resolvedNameOwners = {};
15
20
  // Build mapping of old names to new names
16
- Object.keys(spec.components?.schemas ?? {}).forEach((name)=>{
21
+ originalNames.forEach((name)=>{
17
22
  const normalizedName = toClassName(name);
18
23
  if (normalizedName !== name) {
19
24
  // Check if the normalized name would clash with an existing schema
@@ -22,6 +27,14 @@ import { isRef, resolveIfRef, resolveRef, splitRef } from "./refs.js";
22
27
  }
23
28
  schemaNameMapping[name] = normalizedName;
24
29
  }
30
+ // Detect two distinct schemas resolving to the same name (e.g. "Foo-Bar"
31
+ // and "Foo.Bar" both normalise to "FooBar"), which would otherwise
32
+ // silently overwrite one another.
33
+ const owner = resolvedNameOwners[normalizedName];
34
+ if (owner !== undefined) {
35
+ throw new Error(`Schema name normalization conflict: "${name}" and "${owner}" both normalize to "${normalizedName}". Please rename one of these schemas in your OpenAPI specification.`);
36
+ }
37
+ resolvedNameOwners[normalizedName] = name;
25
38
  });
26
39
  // If no normalization needed, return spec as-is
27
40
  if (Object.keys(schemaNameMapping).length === 0) {
@@ -42,14 +55,25 @@ import { isRef, resolveIfRef, resolveRef, splitRef } from "./refs.js";
42
55
  }
43
56
  }
44
57
  });
45
- // Rename schema keys
58
+ // Rename schema keys, recording the original name so downstream code can
59
+ // recover the on-the-wire value (e.g. an implicit discriminator matches on
60
+ // the original schema name, not its normalised identifier).
46
61
  Object.entries(schemaNameMapping).forEach(([oldName, newName])=>{
47
- spec.components.schemas[newName] = spec.components.schemas[oldName];
62
+ const schema = spec.components.schemas[oldName];
63
+ if (schema && !isRef(schema)) {
64
+ schema['x-aws-nx-original-name'] = oldName;
65
+ }
66
+ spec.components.schemas[newName] = schema;
48
67
  delete spec.components.schemas[oldName];
49
68
  });
50
69
  return spec;
51
70
  };
52
71
  const isCompositeSchema = (schema)=>!!schema.allOf || !!schema.anyOf || !!schema.oneOf;
72
+ /**
73
+ * The media type whose schema is hoisted for a request/response: prefer
74
+ * `application/json`, falling back to any `+json` vendored type (e.g.
75
+ * `application/problem+json`).
76
+ */ const preferredJsonMediaType = (mediaTypes)=>mediaTypes.find((mediaType)=>mediaType === 'application/json') ?? mediaTypes.find((mediaType)=>mediaType.split(';')[0].endsWith('+json'));
53
77
  const hasSubSchemasToVisit = (schema)=>!!schema && !isRef(schema) && ([
54
78
  'object',
55
79
  'array'
@@ -82,7 +106,11 @@ const filterInlineCompositeSchemas = (schemas, nameParts, namePartPrefix, propPa
82
106
  /**
83
107
  * Returns a unique model/schema name for any models which we hoist
84
108
  */ const createUniqueModelName = (nameParts, seenModelNameCounts)=>{
85
- const candidateName = nameParts.map(upperFirst).join('');
109
+ // Normalise each part to a class-name form (stripping `_`, hyphens, etc) so
110
+ // the hoisted schema name matches what `toTypeScriptModelName`/`toClassName`
111
+ // later derive — otherwise a part like `store_photos` yields a `Store_photos`
112
+ // schema whose reference (`StorePhotos`) no longer resolves.
113
+ const candidateName = nameParts.map(toClassName).join('');
86
114
  const seenModelNameCount = seenModelNameCounts[candidateName];
87
115
  // We have not seen this name so we're free to use it
88
116
  if (seenModelNameCount === undefined) {
@@ -205,27 +233,117 @@ const hoistInlineObjectSubSchemas = (nameParts, schema, seenModelNameCounts)=>{
205
233
  };
206
234
  /**
207
235
  * Rewrites OpenAPI 3.1 `const` schemas to the semantically equivalent `enum`
208
- * form. FastAPI emits `{type: 'string', const: 'X'}` for `Literal['X']`;
209
- * downstream hey-api/openapi-ts handles the enum shape but synthesises
210
- * phantom named references for the const shape.
211
- */ const rewriteConstToEnum = (spec)=>cloneDeepWith(spec, (v)=>{
236
+ * form. FastAPI emits `{type: 'string', const: 'X'}` for `Literal['X']`; the
237
+ * parser understands the enum shape, whereas the const shape would synthesise
238
+ * phantom named references.
239
+ */ const rewriteConstToEnum = (spec)=>{
240
+ const rewrite = (v)=>{
212
241
  if (v && typeof v === 'object' && !Array.isArray(v) && 'const' in v && !('enum' in v)) {
213
242
  const { const: constValue, ...rest } = v;
243
+ // Recurse with the same rewrite so consts nested within a rewritten
244
+ // schema are also rewritten.
214
245
  return cloneDeepWith({
215
246
  ...rest,
216
247
  enum: [
217
248
  constValue
218
249
  ]
219
- });
250
+ }, rewrite);
251
+ }
252
+ };
253
+ return cloneDeepWith(spec, rewrite);
254
+ };
255
+ /**
256
+ * Rewrites a composite schema with sibling `properties`/`required` (a valid
257
+ * JSON Schema conjunction, common in FastAPI/Pydantic output) into an
258
+ * equivalent extra `allOf` member, so the parser sees a pure composite and the
259
+ * sibling fields are neither dropped from the type nor stripped when
260
+ * marshalling.
261
+ */ const rewriteCompositeSiblingProperties = (spec)=>{
262
+ const rewrite = (v)=>{
263
+ if (v && typeof v === 'object' && !Array.isArray(v) && Array.isArray(v.allOf) && v.properties) {
264
+ const { properties, required, type: _type, ...rest } = v;
265
+ return cloneDeepWith({
266
+ ...rest,
267
+ allOf: [
268
+ ...v.allOf,
269
+ {
270
+ type: 'object',
271
+ properties,
272
+ ...required ? {
273
+ required
274
+ } : {}
275
+ }
276
+ ]
277
+ }, rewrite);
278
+ }
279
+ };
280
+ return cloneDeepWith(spec, rewrite);
281
+ };
282
+ /**
283
+ * Rewrites an OpenAPI 3.1 multi-type schema (`type: ['integer', 'string']`)
284
+ * into the equivalent `anyOf` of single-type schemas, dropping `null` from the
285
+ * list and marking the schema nullable instead. This lets the parser render a
286
+ * proper union rather than collapsing to the first declared type.
287
+ */ const rewriteMultiTypeToAnyOf = (spec)=>{
288
+ const rewrite = (v)=>{
289
+ if (v && typeof v === 'object' && !Array.isArray(v) && Array.isArray(v.type) && !('anyOf' in v) && !('oneOf' in v) && !('allOf' in v) && !('enum' in v)) {
290
+ const { type, nullable, ...rest } = v;
291
+ const nonNull = type.filter((t)=>t !== 'null');
292
+ const isNullable = nullable === true || nonNull.length !== type.length;
293
+ // Recurse with the same rewrite so multi-type schemas nested within a
294
+ // rewritten schema (e.g. the items of a nullable array) are also
295
+ // rewritten.
296
+ // A single non-null type is not a union; keep it as a plain typed schema.
297
+ if (nonNull.length <= 1) {
298
+ return cloneDeepWith({
299
+ ...rest,
300
+ ...nonNull.length === 1 ? {
301
+ type: nonNull[0]
302
+ } : {},
303
+ ...isNullable ? {
304
+ nullable: true
305
+ } : {}
306
+ }, rewrite);
307
+ }
308
+ return cloneDeepWith({
309
+ ...rest,
310
+ anyOf: nonNull.map((t)=>({
311
+ type: t
312
+ })),
313
+ ...isNullable ? {
314
+ nullable: true
315
+ } : {}
316
+ }, rewrite);
317
+ }
318
+ };
319
+ return cloneDeepWith(spec, rewrite);
320
+ };
321
+ /**
322
+ * Inlines `$ref` path items so that every operation is visited by the
323
+ * normalisation below (operationId assignment, schema hoisting). Each path
324
+ * gets its own copy, so paths sharing a path item are normalised
325
+ * independently.
326
+ */ const inlinePathItemRefs = (spec)=>{
327
+ Object.entries(spec.paths ?? {}).forEach(([path, pathItem])=>{
328
+ if (isRef(pathItem)) {
329
+ const { $ref, ...rest } = pathItem;
330
+ spec.paths[path] = {
331
+ ...structuredClone(resolveRef(spec, $ref)),
332
+ ...rest
333
+ };
220
334
  }
221
335
  });
336
+ };
222
337
  /**
223
338
  * In order to ensure we generate models consistently whether or not users used refs or inline schemas,
224
339
  * we hoist any inline refs to non-primitives
225
340
  */ export const normaliseOpenApiSpecForCodeGen = (inSpec)=>{
226
341
  // Clone the spec so we're free to mutate it
227
342
  let spec = cloneDeepWith(inSpec);
343
+ inlinePathItemRefs(spec);
228
344
  spec = rewriteConstToEnum(spec);
345
+ spec = rewriteMultiTypeToAnyOf(spec);
346
+ spec = rewriteCompositeSiblingProperties(spec);
229
347
  // Ensure spec has schemas set
230
348
  if (!spec?.components?.schemas) {
231
349
  spec.components = {
@@ -287,39 +405,66 @@ const hoistInlineObjectSubSchemas = (nameParts, schema, seenModelNameCounts)=>{
287
405
  if ('responses' in operation) {
288
406
  Object.entries(operation.responses ?? {}).forEach(([code, res])=>{
289
407
  const response = resolveIfRef(spec, res);
290
- const jsonResponseSchema = response?.content?.['application/json']?.schema;
408
+ const jsonMediaType = preferredJsonMediaType(Object.keys(response?.content ?? {}));
409
+ const jsonResponseSchema = jsonMediaType ? response.content[jsonMediaType].schema : undefined;
291
410
  if (jsonResponseSchema && !isRef(jsonResponseSchema) && ([
292
411
  'object',
293
412
  'array'
294
413
  ].includes(jsonResponseSchema.type) || isCompositeSchema(jsonResponseSchema) || jsonResponseSchema?.type === 'string' && jsonResponseSchema.enum)) {
295
414
  const schemaName = `${upperFirst(deduplicatedOpId)}${code}Response`;
296
415
  spec.components.schemas[schemaName] = jsonResponseSchema;
297
- response.content['application/json'].schema = {
416
+ response.content[jsonMediaType].schema = {
298
417
  $ref: `#/components/schemas/${schemaName}`
299
418
  };
300
419
  }
420
+ // Hoist inline streaming item schemas (OpenAPI 3.2 itemSchema) so
421
+ // each streamed item gets a named model.
422
+ STREAMING_CONTENT_TYPES.forEach((mediaType)=>{
423
+ const streamingContent = response?.content?.[mediaType];
424
+ const itemSchema = streamingContent?.itemSchema;
425
+ if (itemSchema && !isRef(itemSchema) && ([
426
+ 'object',
427
+ 'array'
428
+ ].includes(itemSchema.type) || isCompositeSchema(itemSchema) || itemSchema.type === 'string' && itemSchema.enum)) {
429
+ const schemaName = `${upperFirst(deduplicatedOpId)}${code}ResponseItem`;
430
+ spec.components.schemas[schemaName] = itemSchema;
431
+ streamingContent.itemSchema = {
432
+ $ref: `#/components/schemas/${schemaName}`
433
+ };
434
+ }
435
+ });
301
436
  });
302
437
  }
303
438
  if ('requestBody' in operation) {
304
439
  const requestBody = resolveIfRef(spec, operation.requestBody);
305
- const jsonRequestSchema = requestBody?.content?.['application/json']?.schema;
306
- if (jsonRequestSchema && !isRef(jsonRequestSchema) && ([
440
+ const contentMediaTypes = Object.keys(requestBody?.content ?? {});
441
+ // Hoist the JSON body, falling back to a form-data body (multipart or
442
+ // urlencoded) so an inline form object is fully typed and marshalled
443
+ // rather than left `unknown`.
444
+ const bodyMediaType = preferredJsonMediaType(contentMediaTypes) ?? contentMediaTypes.find((mt)=>[
445
+ 'multipart/form-data',
446
+ 'application/x-www-form-urlencoded'
447
+ ].includes(mt.split(';')[0]));
448
+ const bodyRequestSchema = bodyMediaType ? requestBody.content[bodyMediaType].schema : undefined;
449
+ if (bodyRequestSchema && !isRef(bodyRequestSchema) && ([
307
450
  'object',
308
451
  'array'
309
- ].includes(jsonRequestSchema.type) || isCompositeSchema(jsonRequestSchema) || jsonRequestSchema?.type === 'string' && jsonRequestSchema.enum)) {
452
+ ].includes(bodyRequestSchema.type) || isCompositeSchema(bodyRequestSchema) || bodyRequestSchema?.type === 'string' && bodyRequestSchema.enum)) {
310
453
  const schemaName = `${upperFirst(deduplicatedOpId)}RequestContent`;
311
- spec.components.schemas[schemaName] = jsonRequestSchema;
312
- requestBody.content['application/json'].schema = {
454
+ spec.components.schemas[schemaName] = bodyRequestSchema;
455
+ requestBody.content[bodyMediaType].schema = {
313
456
  $ref: `#/components/schemas/${schemaName}`
314
457
  };
315
458
  }
316
459
  }
317
- // Hoist parameter schemas
460
+ // Hoist parameter schemas. Composite and inline-object schemas are
461
+ // hoisted to named models so the parameter is fully typed (e.g. a
462
+ // `deepObject` query param's members are marshalled, not left `unknown`).
318
463
  if ('parameters' in operation) {
319
464
  (operation.parameters ?? []).forEach((p)=>{
320
465
  const param = resolveIfRef(spec, p);
321
466
  const paramSchema = param?.schema;
322
- if (paramSchema && !isRef(paramSchema) && isCompositeSchema(paramSchema)) {
467
+ if (paramSchema && !isRef(paramSchema) && (isCompositeSchema(paramSchema) || paramSchema.type === 'object' && !!paramSchema.properties)) {
323
468
  const schemaName = `${upperFirst(deduplicatedOpId)}Request${upperFirst(param.in)}${upperFirst(camelCase(param.name))}`;
324
469
  spec.components.schemas[schemaName] = paramSchema;
325
470
  param.schema = {