You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/tutorial.md
+148-11
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,10 @@ Cadl comes with built-in models for common data types:
67
67
-`duration`: A duration/time period. e.g 5s, 10h
68
68
-`boolean`: true or false
69
69
-`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.
71
74
72
75
#### Spread
73
76
@@ -474,17 +477,71 @@ Dog type: Model
474
477
475
478
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.
476
479
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 -
483
490
-@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
-[@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.
488
545
489
546
##### @summary
490
547
@@ -561,6 +618,24 @@ Otherwise, the name of the target property will be used.
561
618
562
619
`@key` can only be applied to model properties.
563
620
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
+
564
639
##### @format
565
640
566
641
Syntax:
@@ -625,6 +700,68 @@ model WriteDog {
625
700
626
701
```
627
702
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
+
628
765
### Libraries
629
766
630
767
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.
Copy file name to clipboardexpand all lines: packages/openapi3/README.md
+29
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,35 @@ union MyUnion {
49
49
50
50
```
51
51
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
+
52
81
## Emitter options:
53
82
54
83
Emitter options can be configured via the `cadl-project.yaml` configuration:
0 commit comments