-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2700 Add support for `@example` and `@opExample` [Playground demo](https://cadlplayground.z22.web.core.windows.net/prs/3572/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBIdHRwOwoKQGV4YW1wbGUoI3sKICBpZDogInNvbWUiLAogIGJhcjogInRoaW5nxRBkYXRlOiB1dGNEYXRlVGltZS5mcm9tSVNPKCIyMDIwLTAxLTAxVDAwOsUDWiIpxDV1bml4xDA6xQrENnN0YW1wMzLfPcU9ZW5jb2RlZEFzUmZjNzIzMd9%2B0kFkb2I6IHBsYWluxDbUMsYodGltZW91dDogZHVyYXRpb27KK1BUMU3NJUluU2Vjb25kc9guMS41U9YyRmxvYddlMMc1fSkKbW9kZWwgRm9vIOgBlHN0cmluZzvoAZTKD%2FEBk8QV%2BQFzOwoKICBA5gFVKMgyS25vd25FxBRpbmcucuYBaSn%2FAX1lxUvuAV7Ee%2FEBSM1zInPmAQciLCBpbnQzMsRm%2BgFV2Dtm5AFF1j3vAWA7Cn0K5wFOUGV08wFObmFtZcwQ8ADRfQoKQG9wRecDIwogIOUDJiAgcGFyYW1ldGVyczrIE%2FADPcUnZXTLINQi6ACDIkZsdWZmecsY%2FwK66QK6xAF9xgnHB3JldHVyblR5cGX9AJ3Wed93y3fFbsUFI3sgdGl0bMVOaXJzdCIsIGRlc2NyaXDkAYU6ICJTaG93IGNyZWF05AR6YeQBGCIgfQopCm9wxhdlUGV0KOoBmyzEIjrkAbQpxQY7Cg%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D) --------- Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
- Loading branch information
1 parent
4af9030
commit fef3f01
Showing
18 changed files
with
1,285 additions
and
79 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,8 @@ | ||
--- | ||
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking | ||
changeKind: feature | ||
packages: | ||
- "@typespec/openapi3" | ||
--- | ||
|
||
Add support for new `@example` and `@opExample` decorator |
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,43 @@ | ||
--- | ||
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking | ||
changeKind: feature | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
Add new `@example` and `@opExample` decorator to provide examples on types and operations. | ||
|
||
```tsp | ||
@example(#{ | ||
id: "some", | ||
date: utcDateTime.fromISO("2020-01-01T00:00:00Z"), | ||
timeout: duration.fromISO("PT1M"), | ||
}) | ||
model Foo { | ||
id: string; | ||
date: utcDateTime; | ||
@encode("seconds", int32) timeout: duration; | ||
} | ||
``` | ||
|
||
```tsp | ||
@opExample( | ||
#{ | ||
parameters: #{ | ||
pet: #{ | ||
id: "some", | ||
name: "Fluffy", | ||
dob: plainDate.fromISO("2020-01-01"), | ||
}, | ||
}, | ||
returnType: #{ | ||
id: "some", | ||
name: "Fluffy", | ||
dob: plainDate.fromISO("2020-01-01"), | ||
}, | ||
}, | ||
#{ title: "First", description: "Show creating a pet" } | ||
) | ||
op createPet(pet: Pet): Pet; | ||
``` |
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
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
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
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
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
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
Oops, something went wrong.