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 error when model property is invalid #3574

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions packages/openapi3/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
9 changes: 8 additions & 1 deletion packages/openapi3/src/schema-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading