Skip to content

Conversation

@witemple-msft
Copy link
Member

CC @bterlson @timotheeguerin

This PR adds support for the Protobuf emitter to the TypeSpec playground. It adds the Protobuf library/emitter to the list of libraries and makes a kiosk.tsp sample available. This sample is based on one of Google's official examples for Protobuf. Since this is the first sample in the playground that isn't intended to be used with the OpenAPI 3 emitter, I made a couple of changes:

  • Changed the "OpenAPI" output label on the far right of the screen to say "Output Files," more accurately labeling the function of this selection item (which is to display raw output files regardless of their format).
  • Restructured the sample manifest to allow samples to have a preferredEmitter. When a sample is selected, the preferred emitter is automatically selected as well. If the sample has not preferred emitter, then the default emitter is used, but I added preferredEmitter to all the current samples.
  • I made a few changes to the protobuf library to avoid circular imports by introducing an index.ts module.
  • I removed use of os.EOL in the Protobuf library since the playground does not polyfill any surface of os.
  • I added a utility type (google.protobuf.LatLng) that is used by the Kiosk sample.

image

I also fixed a little bug where the emitter dropdown says "Select sample..." instead of "Select emitter..."

@github-actions
Copy link
Contributor

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/1863/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/1863/

const [selected, setSelected] = useState<"raw" | "swagger-ui">("raw");
const options = [
{ label: "OpenAPI", value: "raw" },
{ label: "Output Files", value: "raw" },
Copy link
Member

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

Copy link
Member Author

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...

Copy link
Member

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

"REST framework": "samples/rest.tsp",
"API versioning": {
fileName: "samples/versioning.tsp",
preferredEmitter: "@typespec/openapi3",
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@timotheeguerin timotheeguerin Apr 26, 2023

Choose a reason for hiding this comment

The 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

@witemple-msft witemple-msft merged commit 482d970 into microsoft:main Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants