From 3277983320ec9ae3931ff888c51e8c67c22910b6 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 24 Feb 2025 15:07:31 -0800 Subject: [PATCH 1/3] Target the param property --- packages/typespec-autorest/src/openapi.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index 36084f9ed6..2a29dcf15a 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -1253,6 +1253,7 @@ export async function getOpenAPIForService( type: Type, schemaContext: SchemaContext, paramName: string, + target: DiagnosticTarget, multipart?: boolean, ): PrimitiveItems | undefined { const fullSchema = getSchemaForType(type, schemaContext); @@ -1285,7 +1286,7 @@ export async function getOpenAPIForService( if (isBytes(elementType)) { return { type: "array", items: { type: "string", format: "binary" } }; } - const schema = getSchemaForPrimitiveItems(elementType, schemaContext, paramName, true); + const schema = getSchemaForPrimitiveItems(elementType, schemaContext, paramName, type, true); if (schema === undefined) { return undefined; } @@ -1297,7 +1298,7 @@ export async function getOpenAPIForService( items: schema, }; } else { - const schema = getSchemaForPrimitiveItems(type, schemaContext, paramName, true); + const schema = getSchemaForPrimitiveItems(type, schemaContext, paramName, type, true); if (schema === undefined) { return undefined; @@ -1392,14 +1393,19 @@ export async function getOpenAPIForService( "type" | "items" > { if (param.type.kind === "Model" && isArrayModelType(program, param.type)) { - const itemSchema = getSchemaForPrimitiveItems(param.type.indexer.value, schemaContext, name); + const itemSchema = getSchemaForPrimitiveItems( + param.type.indexer.value, + schemaContext, + name, + param, + ); const schema = itemSchema && { ...itemSchema, }; delete (schema as any).description; return { type: "array", items: schema }; } else { - return getSchemaForPrimitiveItems(param.type, schemaContext, name) as any; + return getSchemaForPrimitiveItems(param.type, schemaContext, name, param) as any; } } From f174fb9b4f575616804ea5d478a707d2d2dbe94a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 24 Feb 2025 15:08:55 -0800 Subject: [PATCH 2/3] Fix --- packages/typespec-autorest/src/openapi.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index 2a29dcf15a..be89f369aa 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -1201,6 +1201,7 @@ export async function getOpenAPIForService( part.body.type, { visibility, ignoreMetadataAnnotations: false }, partName, + part.body.type, ); if (schema) { if (part.multi) { @@ -1276,6 +1277,7 @@ export async function getOpenAPIForService( type: Type, schemaContext: SchemaContext, paramName: string, + target: DiagnosticTarget, ): PrimitiveItems | undefined { if (isBytes(type)) { return { type: "file" }; @@ -1286,7 +1288,13 @@ export async function getOpenAPIForService( if (isBytes(elementType)) { return { type: "array", items: { type: "string", format: "binary" } }; } - const schema = getSchemaForPrimitiveItems(elementType, schemaContext, paramName, type, true); + const schema = getSchemaForPrimitiveItems( + elementType, + schemaContext, + paramName, + target, + true, + ); if (schema === undefined) { return undefined; } @@ -1298,7 +1306,7 @@ export async function getOpenAPIForService( items: schema, }; } else { - const schema = getSchemaForPrimitiveItems(type, schemaContext, paramName, type, true); + const schema = getSchemaForPrimitiveItems(type, schemaContext, paramName, target, true); if (schema === undefined) { return undefined; @@ -1369,7 +1377,7 @@ export async function getOpenAPIForService( const result = { in: "formData", ...base, - ...(getFormDataSchema(param.type, schemaContext, base.name) as any), + ...(getFormDataSchema(param.type, schemaContext, base.name, param) as any), default: param.defaultValue && getDefaultValue(param.defaultValue, param), }; From 7ce45263e86b827999841724e5431c6ef3f15c94 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 24 Feb 2025 15:14:16 -0800 Subject: [PATCH 3/3] Create fix-unsupported-param-target-2025-1-24-23-11-54.md --- .../fix-unsupported-param-target-2025-1-24-23-11-54.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/fix-unsupported-param-target-2025-1-24-23-11-54.md diff --git a/.chronus/changes/fix-unsupported-param-target-2025-1-24-23-11-54.md b/.chronus/changes/fix-unsupported-param-target-2025-1-24-23-11-54.md new file mode 100644 index 0000000000..77da8b0b1c --- /dev/null +++ b/.chronus/changes/fix-unsupported-param-target-2025-1-24-23-11-54.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@azure-tools/typespec-autorest" +--- + +Target param property when warn on unsupported parameter type