-
Notifications
You must be signed in to change notification settings - Fork 351
Add getOpenAPI3 to OpenAPI3 emitter
#2950
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c0cf627
Add a function for getting openapi3 documents as an object
bterlson 68beafb
changes
bterlson 79b0a00
Merge branch 'main' into openapi3-function
bterlson 7a52d77
Add test
bterlson 03e9e74
Restructure output
bterlson 6d26a66
simplify types
bterlson 24fd58d
Update packages/openapi3/src/openapi.ts
bterlson f679c03
return diagnostics along with output
bterlson c2ce44f
Merge branch 'openapi3-function' of https://github.com/bterlson/cadl …
bterlson ebff169
undo unnecessary changes
bterlson 91cc671
Update packages/openapi3/src/types.ts
bterlson 4c0cc0d
make everything readonly
bterlson 75454c1
clean up logic
bterlson 551c643
Merge branch 'openapi3-function' of https://github.com/bterlson/cadl …
bterlson 577ff70
Add changes for versioning
bterlson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/openapi3" | ||
| --- | ||
|
|
||
| Add `getOpenAPI3` function that takes a TypeSpec program and returns the emitted OpenAPI as an object. Useful for other emitters and tools that want to work with emitted OpenAPI directly without writing it to disk. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { strictEqual } from "assert"; | ||
| import { it } from "vitest"; | ||
| import { getOpenAPI3 } from "../src/openapi.js"; | ||
| import { createOpenAPITestHost } from "./test-host.js"; | ||
|
|
||
| it("can get openapi as an object", async () => { | ||
| const host = await createOpenAPITestHost(); | ||
| host.addTypeSpecFile( | ||
| "./main.tsp", | ||
| `import "@typespec/http"; | ||
| import "@typespec/rest"; | ||
| import "@typespec/openapi"; | ||
| import "@typespec/openapi3"; | ||
| using TypeSpec.Rest; | ||
| using TypeSpec.Http; | ||
| using TypeSpec.OpenAPI; | ||
|
|
||
| @service | ||
| namespace Foo; | ||
|
|
||
| @get op get(): Item; | ||
|
|
||
| model Item { x: true } | ||
| model Bar { }; // unreachable | ||
| ` | ||
| ); | ||
| await host.compile("main.tsp"); | ||
| const output = await getOpenAPI3(host.program, { "omit-unreachable-types": false }); | ||
| strictEqual((output[0] as any).document.document.components!.schemas!["Item"].type, "object"); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.