Skip to content
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,7 @@
---
changeKind: fix
packages:
- "@typespec/openapi3"
---

Fix `@extension` being duplicated on both the parameter object and its `schema` in OpenAPI output. Parameter extensions are now emitted only on the parameter object.
9 changes: 9 additions & 0 deletions packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,15 @@ function createOAPIEmitter(
// Description is already provided in the parameter itself.
delete schema.description;

const extensions = getExtensions(program, param);
if (extensions && !("$ref" in schema)) {
for (const key of extensions.keys()) {
if (key in schema) {
delete schema[key];
}
}
}

const oaiParam: OpenAPI3ParameterBase = {
required: !param.optional,
description: getDoc(program, param),
Expand Down
27 changes: 27 additions & 0 deletions packages/openapi3/test/extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ describe("target", () => {
strictEqual(oapi.components.parameters.PetId["x-parameter-extension"], "foobaz");
});

it("does not duplicate parameter extensions on parameter schemas", async () => {
const oapi = await openApiFor(
`
@route("/{id}") @get op get(
@extension("x-my-ext", "path") @path id: string,
@extension("x-my-ext", "query") @query filter: string,
): void;
`,
);

const parameters = oapi.paths["/{id}"].get.parameters as Array<{
name: string;
schema: Record<string, unknown>;
[key: string]: unknown;
}>;
const pathParam = parameters.find((x) => x.name === "id");
const queryParam = parameters.find((x) => x.name === "filter");

ok(pathParam);
ok(queryParam);

expect(pathParam["x-my-ext"]).toEqual("path");
expect(pathParam.schema["x-my-ext"]).toBeUndefined();
expect(queryParam["x-my-ext"]).toEqual("query");
expect(queryParam.schema["x-my-ext"]).toBeUndefined();
});

it("adds at root of document when on namespace", async () => {
const oapi = await openApiFor(
`
Expand Down
Loading