diff --git a/website/src/content/docs/docs/howtos/Generate client libraries/06types.mdx b/website/src/content/docs/docs/howtos/Generate client libraries/06types.mdx index 9defa74f3c..05ccc575b2 100644 --- a/website/src/content/docs/docs/howtos/Generate client libraries/06types.mdx +++ b/website/src/content/docs/docs/howtos/Generate client libraries/06types.mdx @@ -703,14 +703,6 @@ public final class Animal implements JsonSerializable { -```typespec -model Animal { - name: string; - kind: string; - ...Record; -} -``` - ```typespec model Animal { name: string; @@ -963,7 +955,7 @@ TypeSpec uses `@discriminator` decorator to add a discriminator to a model. -TypeSpec now has two ways to represent a discriminated set. +Client emitters now only support a single way to represent a discriminated set in TypeSpec. 1. Use model @@ -1005,20 +997,6 @@ model Ragdoll extends Cat { } ``` -2. Use union - -```typespec -@discriminator("kind") -union Cat { - Siamese, - Ragdoll, -} - -model Siamese {} - -model Ragdoll {} -``` - @@ -1250,7 +1228,6 @@ about nullability by inspecting the type of a property. model Foo { basicNullableProperty: string | null; modelNullableProperty: Bar | null; - unionNullableProperty: Bar | Baz | null; enumNullableProperty: LR | null; } @@ -1258,10 +1235,6 @@ model Bar { prop: string; } -model Baz { - prop: int32; -} - enum LR { left, right, @@ -1316,52 +1289,6 @@ A nullable type has kind `nullable` and property `valueType`. The kind of the ty } } }, - { - "kind": "property", - "name": "unionNullableProperty", - "serializedName": "unionNullableProperty", - "optional": false, - "type": { - "kind": "nullable", - "valueType": { - "kind": "union", - "values": [ - { - "kind": "model", - "name": "Bar", - "properties": [ - { - "kind": "property", - "name": "prop", - "serializedName": "prop", - "optional": false, - "type": { - "kind": "string", - "encode": "string" - } - } - ] - }, - { - "kind": "model", - "name": "Baz", - "properties": [ - { - "kind": "property", - "name": "prop", - "serializedName": "prop", - "optional": false, - "type": { - "kind": "int32", - "encode": "int32" - } - } - ] - } - ] - } - } - }, { "kind": "property", "name": "enumNullableProperty", @@ -1409,9 +1336,6 @@ from corehttp.utils import CaseInsensitiveEnumMeta class Bar(_model_base.Model): prop: Optional[str] = rest_field() -class Baz(_model_base.Model): - prop: Optional[str] = rest_field() - class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta): LEFT = "left" RIGHT = "right" @@ -1419,7 +1343,6 @@ class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta): class Foo(_model_base.Model): basicNullableProperty: Optional[str] = rest_field() modelNullableProperty: Optional["_models.Bar"] = rest_field() - unionNullableProperty: Optional[Union["_models.Bar", "_models.Baz"]] = rest_field() enumNullableProperty: Optional["LR"] = rest_field() ``` @@ -2314,108 +2237,6 @@ public enum WidgetOrientation { -### Union with multiple types - -These are unions where the values don't share same type. - - - - -```typespec -model Shirt { - sizing: 32 | 34 | int32 | "small" | "medium" | string; -} -``` - - - - -```json -{ - "kind": "union", - "name": "ShirtSizings", - "generatedName": true, - "values": [ - { - "kind": "constant", - "value": 32, - "valueType": { - "kind": "int32" - } - }, - { - "kind": "constant", - "value": 34, - "valueType": { - "kind": "int32" - } - }, - { - "kind": "constant", - "value": "small", - "valueType": { - "kind": "string" - } - }, - { - "kind": "constant", - "value": "medium", - "valueType": { - "kind": "string" - } - }, - { - "kind": "string" - } - ] -} -``` - - - - -Python will generate this as a union since these entries don't share the same type - -```python -from typing import Literal - -type ShirtSizing = Literal[32] | Literal[34] | int | Literal["small"] | Literal["medium"] | str - -model Shirt: - sizing: ShirtSizing -``` - - - - -```csharp -public partial class Shirt -{ - public BinaryData Shirt; -} -``` - - - - -```typescript -export interface Shirt { - sizing: 32 | 34 | number | "small" | "medium" | string; -} -``` - - - - -```java -public final class Shirt { - private BinaryData sizing; -} -``` - - - - ## Enums ### Standard @@ -2706,7 +2527,7 @@ We will take the `@encode` decorator into account, determining how we serialize -```tsp +```typespec model Test { @encode(DateTimeKnownEncoding.rfc3339) prop: utcDateTime; @@ -2769,7 +2590,7 @@ When you specify an encoding type, say that you want to encode an integer as a s -```tsp +```typespec model Test { @encode(string) prop: int64; diff --git a/website/src/content/docs/docs/howtos/Generate client libraries/08methodInputs.mdx b/website/src/content/docs/docs/howtos/Generate client libraries/08methodInputs.mdx index 39bc12cc6d..ab84a94da8 100644 --- a/website/src/content/docs/docs/howtos/Generate client libraries/08methodInputs.mdx +++ b/website/src/content/docs/docs/howtos/Generate client libraries/08methodInputs.mdx @@ -14,6 +14,11 @@ This document outlines the method input signatures that language emitters will g ```typespec +model User { + firstName: string; + lastName: string; +} + @get op get(): User; ``` @@ -101,6 +106,11 @@ func (client *Client) Get(ctx context.Context, options *ClientGetOptions) (Clien ```typespec +model User { + firstName: string; + lastName: string; +} + @post op post(@body body: User): void; ``` @@ -624,7 +634,8 @@ model BlobProperties { @path name: string; - @header testHeader: string; + @header + testHeader: string; } @route("blob_properties/{name}")