From b19386ea21cc1e5792485bfcd992f6fa40a9d6e4 Mon Sep 17 00:00:00 2001 From: shiron Date: Thu, 13 Jun 2024 11:01:05 +0900 Subject: [PATCH 1/2] fix error when model property is invalid --- packages/openapi3/src/lib.ts | 6 ++++++ packages/openapi3/src/schema-emitter.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/openapi3/src/lib.ts b/packages/openapi3/src/lib.ts index 8b45badd1c..64ef47e267 100644 --- a/packages/openapi3/src/lib.ts +++ b/packages/openapi3/src/lib.ts @@ -245,6 +245,12 @@ export const libDef = { default: paramMessage`Status code range '${"start"} to '${"end"}' is not supported. OpenAPI 3.0 can only represent range 1XX, 2XX, 3XX, 4XX and 5XX. Example: \`@minValue(400) @maxValue(499)\` for 4XX.`, }, }, + "invalid-model-property": { + severity: "error", + messages: { + default: paramMessage`'${"type"}' cannot be specified as a model property.`, + }, + }, "unsupported-auth": { severity: "warning", messages: { diff --git a/packages/openapi3/src/schema-emitter.ts b/packages/openapi3/src/schema-emitter.ts index 44f10ae4a5..3e05cd9978 100644 --- a/packages/openapi3/src/schema-emitter.ts +++ b/packages/openapi3/src/schema-emitter.ts @@ -351,7 +351,14 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter< }); if (refSchema.kind !== "code") { - throw new Error("Unexpected non-code result from emit reference"); + reportDiagnostic(program, { + code: "invalid-model-property", + format: { + type: prop.type.kind, + }, + target: prop, + }); + return {}; } const isRef = refSchema.value instanceof Placeholder || "$ref" in refSchema.value; From c395e00bce5e46cda4cd76a0c10fb14768bdaa28 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 13 Jun 2024 07:54:11 -0700 Subject: [PATCH 2/2] Create main-2024-5-13-14-52-31.md --- .chronus/changes/main-2024-5-13-14-52-31.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/main-2024-5-13-14-52-31.md diff --git a/.chronus/changes/main-2024-5-13-14-52-31.md b/.chronus/changes/main-2024-5-13-14-52-31.md new file mode 100644 index 0000000000..e5fa0ec174 --- /dev/null +++ b/.chronus/changes/main-2024-5-13-14-52-31.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/openapi3" +--- + +Emit diagnostic when an invalid type is used as a property instead of crashing.