-
Notifications
You must be signed in to change notification settings - Fork 375
[playground] Add/enable protobuf kiosk sample in the playground #1863
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
Changes from all commits
81abb33
4a83312
d50495d
a759a6a
8703a5b
1d09b6c
8623baf
b3147b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import "@typespec/protobuf"; | ||
|
|
||
| using TypeSpec.Protobuf; | ||
|
|
||
| @package({ | ||
| name: "kiosk", | ||
| }) | ||
| namespace KioskExample; | ||
|
|
||
| @TypeSpec.Protobuf.service | ||
| interface Display { | ||
| /** | ||
| * Create a new kiosk. This enrolls the kiosk for sign display. | ||
| */ | ||
| createKiosk(...Kiosk): Kiosk; | ||
|
|
||
| /** | ||
| * List active kiosks. | ||
| */ | ||
| listKiosks(...WellKnown.Empty): { | ||
| @field(1) kiosks: Kiosk[]; | ||
| }; | ||
|
|
||
| /** | ||
| * Get a kiosk. | ||
| */ | ||
| getKiosk(@field(1) id: int32): Kiosk; | ||
|
|
||
| /** | ||
| * Delete a kiosk. | ||
| */ | ||
| deleteKiosk(@field(1) id: int32): void; | ||
|
|
||
| /** | ||
| * Create a new sign. | ||
| */ | ||
| createSign(...Sign): Sign; | ||
|
|
||
| /** | ||
| * List active signs. | ||
| */ | ||
| listSigns(...WellKnown.Empty): { | ||
| @field(1) signs: Sign[]; | ||
| }; | ||
|
|
||
| /** | ||
| * Get a sign. | ||
| */ | ||
| getSign(@field(1) id: int32): Sign; | ||
|
|
||
| /** | ||
| * Delete a sign. | ||
| */ | ||
| deleteSign(@field(1) id: int32): void; | ||
|
|
||
| /** | ||
| * Set a sign for display on one or more kiosks | ||
| */ | ||
| setSignIdForKioskIds(@field(1) kiosk_ids: int32[], @field(2) sign_id: int32): void; | ||
|
|
||
| /** | ||
| * Get the sign that should be displayed on a kiosk. | ||
| */ | ||
| getSignIdForKioskId(@field(1) kiosk_id: int32): GetSignIdResponse; | ||
| /** | ||
| * Get signs that should be displayed on a kiosk. Streams. | ||
| */ | ||
| @stream(StreamMode.Out) | ||
| getSignIdsforKioskId(@field(1) kiosk_id: int32): GetSignIdResponse; | ||
| } | ||
|
|
||
| model Kiosk { | ||
| // Output only. | ||
| @field(1) id?: int32; | ||
| // Required. | ||
| @field(2) name: string; | ||
| @field(3) size: ScreenSize; | ||
| @field(4) location: WellKnown.LatLng; | ||
| // Output only. | ||
| @field(5) create_time?: WellKnown.Timestamp; | ||
| } | ||
|
|
||
| model Sign { | ||
| // Output only. | ||
| @field(1) id?: int32; | ||
| // Required. | ||
| @field(2) name: string; | ||
| @field(3) text: string; | ||
| @field(4) image: bytes; | ||
| // Output only. | ||
| @field(5) create_time?: WellKnown.Timestamp; | ||
| } | ||
|
|
||
| model ScreenSize { | ||
| @field(1) width: int32; | ||
| @field(2) height: int32; | ||
| } | ||
|
|
||
| model GetSignIdResponse { | ||
| @field(1) sign_id: int32; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| export interface PlaygroundConfig { | ||
| defaultEmitter: string; | ||
| libraries: string[]; | ||
| samples: Record<string, string>; | ||
| samples: Record<string, SampleConfig>; | ||
| enableSwaggerUI: boolean; | ||
| links: { | ||
| newIssue: string; | ||
| documentation: string; | ||
| }; | ||
| } | ||
|
|
||
| export interface SampleConfig { | ||
| fileName: string; | ||
| preferredEmitter?: string; | ||
| content?: string; | ||
| } | ||
|
|
||
| export { createBrowserHost } from "./browser-host.js"; | ||
| export { Playground, PlaygroundProps } from "./components/playground.js"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,23 @@ const config = definePlaygroundViteConfig({ | |
| "@typespec/openapi", | ||
| "@typespec/versioning", | ||
| "@typespec/openapi3", | ||
| "@typespec/protobuf", | ||
| ], | ||
| samples: { | ||
| "API versioning": "samples/versioning.tsp", | ||
| "Discriminated unions": "samples/unions.tsp", | ||
| "HTTP service": "samples/http.tsp", | ||
| "REST framework": "samples/rest.tsp", | ||
| "API versioning": { | ||
| fileName: "samples/versioning.tsp", | ||
| preferredEmitter: "@typespec/openapi3", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it not be better to have this as an array of emitters that are compatible with this sample?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this PR I'm hoping to do the very minimum thing to light up typespec/protobuf in the existing playground so that we can share it. If we want to rework the playground a little bit to have an emitter -> sample flow then we should do that separately IMO and just let this be a dead simple autoselect for now.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure lets merge that and update after, can you just make a PR updating typespec-azure with the new option too |
||
| }, | ||
| "Discriminated unions": { | ||
| fileName: "samples/unions.tsp", | ||
| preferredEmitter: "@typespec/openapi3", | ||
| }, | ||
| "HTTP service": { fileName: "samples/http.tsp", preferredEmitter: "@typespec/openapi3" }, | ||
| "REST framework": { fileName: "samples/rest.tsp", preferredEmitter: "@typespec/openapi3" }, | ||
| "Protobuf Kiosk": { | ||
| fileName: "samples/kiosk.tsp", | ||
| preferredEmitter: "@typespec/protobuf", | ||
| }, | ||
| }, | ||
| enableSwaggerUI: true, | ||
| links: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { TypeSpecProtobufLibrary } from "./lib.js"; | ||
|
|
||
| export const namespace = "TypeSpec.Protobuf"; | ||
|
|
||
| export * from "./proto.js"; | ||
|
|
||
| export const $lib = TypeSpecProtobufLibrary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hhm, thats another issue didn' think of, we don't really want that dropdown to be showing for non openapi output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you get a kind of ugly warning about missing the OpenAPI version number if you set it to Swagger UI when the protobuf emitter is selected...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should have yet another config to load a plugin(swagger view) for certain emitters. become out of scope of your pr though