Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Target param property when error on invalid type #2258

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
24 changes: 19 additions & 5 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ export async function getOpenAPIForService(
part.body.type,
{ visibility, ignoreMetadataAnnotations: false },
partName,
part.body.type,
);
if (schema) {
if (part.multi) {
Expand Down Expand Up @@ -1253,6 +1254,7 @@ export async function getOpenAPIForService(
type: Type,
schemaContext: SchemaContext,
paramName: string,
target: DiagnosticTarget,
multipart?: boolean,
): PrimitiveItems | undefined {
const fullSchema = getSchemaForType(type, schemaContext);
Expand All @@ -1275,6 +1277,7 @@ export async function getOpenAPIForService(
type: Type,
schemaContext: SchemaContext,
paramName: string,
target: DiagnosticTarget,
): PrimitiveItems | undefined {
if (isBytes(type)) {
return { type: "file" };
Expand All @@ -1285,7 +1288,13 @@ 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,
target,
true,
);
if (schema === undefined) {
return undefined;
}
Expand All @@ -1297,7 +1306,7 @@ export async function getOpenAPIForService(
items: schema,
};
} else {
const schema = getSchemaForPrimitiveItems(type, schemaContext, paramName, true);
const schema = getSchemaForPrimitiveItems(type, schemaContext, paramName, target, true);

if (schema === undefined) {
return undefined;
Expand Down Expand Up @@ -1368,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),
};

Expand All @@ -1392,14 +1401,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;
}
}

Expand Down
Loading