Skip to content

Commit

Permalink
Attach namespace extensions to the root of the doc (#3890)
Browse files Browse the repository at this point in the history
This PR seeks to update the emitter by adding the extensions defined on
a namespace to the root of the OpenApi document.
Fixes #3837

---------

Co-authored-by: Timothee Guerin <[email protected]>
  • Loading branch information
MaggieKimani1 and timotheeguerin authored Jul 18, 2024
1 parent 61807aa commit 8d8e454
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/mk-set-root-extensions-2024-6-18-19-20-36.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/openapi3"
---

`@extension` used on the service namespace will set extension at the root of the document
1 change: 1 addition & 0 deletions packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ function createOAPIEmitter(
root.servers = resolveServers(servers);
}

attachExtensions(program, service.type, root);
serviceNamespaceName = getNamespaceFullName(service.type);
currentPath = root.paths;

Expand Down
11 changes: 11 additions & 0 deletions packages/openapi3/test/openapi-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ describe("openapi3: extension decorator", () => {
strictEqual(oapi.components.parameters.PetId["x-parameter-extension"], "foobaz");
});

it("adds an extension to a namespace", async () => {
const oapi = await openApiFor(
`
@extension("x-namespace-extension", "foobar")
@service namespace Service {};
`
);

strictEqual(oapi["x-namespace-extension"], "foobar");
});

it("check format and pattern decorator on model", async () => {
const oapi = await openApiFor(
`
Expand Down

0 comments on commit 8d8e454

Please sign in to comment.