Skip to content

Commit e84b800

Browse files
authored
Documentation update (microsoft#807)
* Document update * changelog update * review feedback * update @OneOf
1 parent b44b8d4 commit e84b800

File tree

4 files changed

+194
-11
lines changed

4 files changed

+194
-11
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ using the preview.
4848

4949
`@next` version of the package are the latest versions available on the `main` branch.
5050

51+
## Try Cadl without installing anything
52+
53+
You can try Cadl on the web without installing anything.
54+
55+
- [Cadl playground](https://cadlplayground.z22.web.core.windows.net)
56+
- [Cadl playground for Azure services](https://cadlplayground.z22.web.core.windows.net/cadl-azure/)
57+
5158
## Getting Started
5259

5360
### Using Docker
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@cadl-lang/openapi3",
5+
"comment": "Update Readme.md for new decorators.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@cadl-lang/openapi3"
10+
}

docs/tutorial.md

+148-11
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ Cadl comes with built-in models for common data types:
6767
- `duration`: A duration/time period. e.g 5s, 10h
6868
- `boolean`: true or false
6969
- `null`: the null value found in e.g. JSON.
70-
- `Map<K, V>`: a map from K to V.
70+
- `Record<T>`: a dictionary with string K and value T.
71+
- `unknown`: A top type in Cadl that all types can be assigned to.
72+
- `void`: A function return type indicating the function doesn't return a value.
73+
- `never`: The never type indicates the values that will never occur. Typically, you use the never type to represent the return type of a function that always throws an error.
7174

7275
#### Spread
7376

@@ -474,17 +477,71 @@ Dog type: Model
474477

475478
Cadl comes built-in with a number of decorators that are useful for defining service APIs regardless of what protocol or language you're targeting.
476479

477-
- @summary - attach a documentation string, typically a short, single-line description.
478-
- @doc - attach a documentation string. Works great with multi-line string literals.
479-
- @key - mark a model property as the key to identify instances of that type
480-
- @tag - attach a simple tag to a declaration
481-
- @secret - mark a string as a secret value that should be treated carefully to avoid exposure
482-
- @minValue/@maxValue - set the min and max values of number types
480+
- [@deprecated](#deprecated) - indicates that the decorator target has been deprecated.
481+
- [@doc](#doc) - attach a documentation string. Works great with multi-line string literals.
482+
- [@error](#error) - specify a model is representing an error
483+
- [@format](#format) - specify the data format hint for a string type
484+
- [@friendlyName](#friendlyname) - specify a friendly name to be used instead of declared model name
485+
- @indexer
486+
- [@inspectType/@inspectTypeName](#inspecttype) - displays information about a type during compilation
487+
- [@key](#key) - mark a model property as the key to identify instances of that type
488+
- [@knownValues](#knownvalues) - mark a string type with an enum that contains all known values
489+
- @list -
483490
- @minLength/@maxLength - set the min and max lengths for strings
484-
- @knownValues - mark a string type with an enum that contains all known values
485-
- @pattern - set the pattern for a string using regular expression syntax
486-
- @format - specify the data format hint for a string type
487-
- @error - specify a model is representing an error
491+
- @minValue/@maxValue - set the min and max values of number types
492+
- [@pattern](#pattern) - set the pattern for a string using regular expression syntax
493+
- [@secret](#secret) - mark a string as a secret value that should be treated carefully to avoid exposure
494+
- [@summary](#summary) - attach a documentation string, typically a short, single-line description.
495+
- [@tag](#tag) - attach a simple tag to a declaration
496+
- [@visibility/@withVisibility](#visibility-decorators)
497+
- [@withDefaultKeyVisibility](#withefaultkeyvisibility) - set the visibility of key properties in a model if not already set.
498+
- [@withOptionalProperties](#withoptionalproperties) - makes all properties of the target type optional.
499+
- [@withoutDefaultValues](#withoutdefaultvalues) - removes all read-only properties from the target type.
500+
- [@withoutOmittedProperties](#withoutomittedproperties) - removes all model properties that match a type.
501+
- [@withUpdateableProperties](#withupdateableproperties) - remove all read-only properties from the target type
502+
503+
##### @inspectType
504+
505+
Syntax:
506+
507+
```
508+
@inspectType(message)
509+
@inspectTypeName(message)
510+
```
511+
512+
`@inspectType` displays information about a type during compilation.
513+
`@inspectTypeName` displays information and name of type during compilation.
514+
They can be specified on any language element -- a model, an operation, a namespace, etc.
515+
516+
##### @deprecated
517+
518+
Syntax:
519+
520+
```
521+
@deprecated(message)
522+
```
523+
524+
`@deprecated` marks a type as deprecated. It can be specified on any language element -- a model, an operation, a namespace, etc.
525+
526+
##### @friendlyName
527+
528+
Syntax:
529+
530+
```
531+
@friendlyName(string)
532+
```
533+
534+
`@friendlyName` specifies an alternate model name to be used instead of declared model name. It can be specified on a model.
535+
536+
##### @pattern
537+
538+
Syntax:
539+
540+
```
541+
@pattern(regularExpressionText)
542+
```
543+
544+
`@pattern` specifies a regular expression on a string property.
488545

489546
##### @summary
490547

@@ -561,6 +618,24 @@ Otherwise, the name of the target property will be used.
561618

562619
`@key` can only be applied to model properties.
563620

621+
##### @secret
622+
623+
Syntax:
624+
625+
```
626+
@secret
627+
```
628+
629+
`@secret` mark a string as a secret value that should be treated carefully to avoid exposure
630+
631+
```
632+
@secret
633+
model Password is string;
634+
635+
```
636+
637+
`@secret` can only be applied to string model;
638+
564639
##### @format
565640

566641
Syntax:
@@ -625,6 +700,68 @@ model WriteDog {
625700
626701
```
627702

703+
#### @withDefaultKeyVisibility
704+
705+
Syntax:
706+
707+
```
708+
@withDefaultKeyVisibility(string)
709+
```
710+
711+
`@withDefaultKeyVisibility` - set the visibility of key properties in a model if not already set. The first argument accepts a string representing the desired default
712+
visibility value.
713+
If a key property already has a `visibility` decorator then the default visibility is not applied.
714+
715+
`@withDefaultKeyVisibility` can only be applied to model types.
716+
717+
#### @withOptionalProperties
718+
719+
Syntax:
720+
721+
```
722+
@withOptionalProperties()
723+
```
724+
725+
`@withOptionalProperties` makes all properties of the target type optional.
726+
727+
`@withOptionalProperties` can only be applied to model types.
728+
729+
#### @withoutDefaultValues
730+
731+
Syntax:
732+
733+
```
734+
@withoutDefaultValues()
735+
```
736+
737+
`@withoutDefaultValues` removes all read-only properties from the target type.
738+
739+
`@withoutDefaultValues` can only be applied to model types.
740+
741+
#### @withoutOmittedProperties
742+
743+
Syntax:
744+
745+
```
746+
@withoutOmittedProperties(type)
747+
```
748+
749+
`@withoutOmittedProperties` removes all model properties that match a type.
750+
751+
`@withoutOmittedProperties` can only be applied to model types.
752+
753+
#### @withUpdateableProperties
754+
755+
Syntax:
756+
757+
```
758+
@withUpdateableProperties()
759+
```
760+
761+
`@withUpdateableProperties` remove all read-only properties from the target type.
762+
763+
`@withUpdateableProperties` can only be applied to model types.
764+
628765
### Libraries
629766

630767
Cadl libraries are bundles of useful Cadl declarations and decorators into reusable packages. Cadl libraries are actually npm packages under the covers. Official Cadl libraries can be found with the `@cadl-lang/` or `@azure-tools/cadl-` npm package name prefix. Libraries can be either a language library, an emitter library or both.

packages/openapi3/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ union MyUnion {
4949
5050
```
5151

52+
## Decorators
53+
54+
- [@useRef](#useref)
55+
- [@oneOf](#oneof)
56+
57+
### @useRef
58+
59+
Syntax:
60+
61+
```
62+
@useRef(urlString)
63+
```
64+
65+
`@useRef`
66+
67+
`@useRef` is used to replace the Cadl model type in emitter output with a pre-existing named OpenAPI schema.
68+
69+
### @oneOf
70+
71+
Syntax:
72+
73+
```
74+
@oneOf()
75+
```
76+
77+
`@oneOf`emits `oneOf` keyword for a union type in the resulting OpenAPI 3.0 specification. It indicates that the value of union type can only contain exactly one of the subschemas.
78+
79+
`@oneOf` can only be applied to a union types.
80+
5281
## Emitter options:
5382

5483
Emitter options can be configured via the `cadl-project.yaml` configuration:

0 commit comments

Comments
 (0)