-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing multi-protocol file (#5519)
It was reported that the link for multi-protocol wasn't working: #5454 After looking, the file is not present, looks like it got lost during migration, this is the original file: https://github.com/timotheeguerin/typespec/blob/663d057c08c496d0fb3a858c8a528e9900c05bde/packages/website/src/pages/multi-protocol.md Adding the file again and verifying
- Loading branch information
1 parent
f390cfb
commit 34e9146
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,59 @@ | ||
--- | ||
layout: ../layouts/content.astro | ||
--- | ||
|
||
# Multi protocol | ||
|
||
TypeSpec is a protocol agnostic language. It could be used with many different protocols independently or together. | ||
|
||
## Examples | ||
|
||
### Protobuf service and emit a json schema for the models. | ||
|
||
In this example we have a protobuf service and we want to emit a json schema for the models which we can use later to validate the data in our service implementation. | ||
|
||
```tsp tryit="{"emit": ["@typespec/protobuf", "@typespec/json-schema"]}" | ||
import "@typespec/protobuf"; | ||
import "@typespec/http"; | ||
import "@typespec/json-schema"; | ||
using TypeSpec.Protobuf; | ||
using TypeSpec.Http; | ||
@JsonSchema.jsonSchema | ||
@Protobuf.package({ | ||
name: "kiosk", | ||
}) | ||
@TypeSpec.service | ||
namespace KioskExample; | ||
// models.tsp | ||
model Kiosk { | ||
@field(1) id?: int32; | ||
@field(2) name: string; | ||
@field(3) size: ScreenSize; | ||
@field(4) location: LatLng; | ||
@field(5) create_time?: int32; | ||
} | ||
model ScreenSize { | ||
@field(1) width: int32; | ||
@field(2) height: int32; | ||
} | ||
model LatLng { | ||
@field(1) lat: float64; | ||
@field(2) lng: float64; | ||
} | ||
model ListResponse { | ||
@field(1) kiosks: Kiosk[]; | ||
} | ||
@Protobuf.service | ||
interface Kiosks { | ||
@post createKiosk(...Kiosk): Kiosk; | ||
@list listKiosks(): ListResponse; | ||
@get getKiosk(@path @field(1) id: int32): Kiosk; | ||
@delete deleteKiosk(@path @field(1) id: int32): void; | ||
} | ||
``` |