doc/design/GeneratedClientDesign.md
This document tracks design rules and decisions for .NET clients generated by the DPG generator. It may later be extended to include other generator designs.
<!-- ## Clients TBD ## Client Protocol Operations TBD ## Client Convenience Operations -->Models are defined as partial classes with one or more constructors, properties, and methods that read from/write to wire formats.
The .NET team discourages using C# Records in public APIs, so we will not use them for model types.
Generated models will be defined in a .Models namespace.
Tracking finalization of namespace decision autorest.csharp #2514
The following table shows a mapping from Cadl built-in types to the corresponding types used in .NET models.
| Cadl Type | .NET Type | OpenAPI Type | GitHub Issue | Notes |
|---|---|---|---|---|
| string | string | string | autorest.csharp #2337 | PrimitivePropertyModel.cs PrimitivePropertyModel.Serialization.cs |
| bytes | BinaryData | type: string, format: byte | autorest.csharp #2337 | |
| int32 | int | type: integer, format: int32 | autorest.csharp #2337 | |
| int64 | long | type: integer, format: int64 | autorest.csharp #2337 | |
| safeint | long | n/a | autorest.csharp #2337 | |
| float32 | float | type: number, format: float | autorest.csharp #2337 | |
| float64 | double | type: number, format: double | autorest.csharp #2337 | |
| zonedDateTime | DateTimeOffset | type: string, format: date-time | autorest.csharp #2337 | Serialized differently based on body/header |
| duration | TimeSpan | type: string, format: duration | autorest.csharp #2337 | |
| boolean | bool | boolean | autorest.csharp #2337 |
Model APIs will differ depending on whether the model is an input model, an output model, or a round-trip model (both input and output).
The following describes the model shapes for different cases of properties.
| Item | Input | Output | Round-Trip | GitHub Issue |
|---|---|---|---|---|
| Constructor Accessibility | public | internal | public | |
| Required Property | get-only | get-only | get/set | autorest.csharp #2463 |
| Optional Property | get/set | get-only | get/set | autorest.csharp #2339 |
| Collection Property | IList<T> get-only | IReadOnlyList<T> get-only | IList<T> get-only | autorest.csharp #2471 |
Models have one or more constructors as follows.
Argument.AssertNotNullIEnumerable<T> parametersIEnumerable parameter using System.Linq .ToList()IReadOnlyList<T> parameters for Output models and IList<T> parameters for Round-trip modelsSee examples:
There are a number of outstanding open issues regarding how to represent collections being tracked:
Enums may be generated as a CLR enum or a C# "Strongly-typed string" as follows.
enum not found in a corresponding @knownValues decorator is generated as a C# enum@knownValues decorator is generated as a C# "Strongly-typed string" (sometimes called "extensible enum") and the corresponding Cadl enum is not generated as a C# enumGitHub issue: autorest.csharp #2477
See examples:
Models that are properties of other models are called nested models. A model that appears only as a non-root of a model graph is defined as partial class according to the same rules as root models.
GitHub issue: autorest.csharp #2489
See examples:
Requirements for model graphs with circular dependencies will be defined in a later iteration. GitHub issue autorest.csharp #2506
Models that appear as properties of other models have their shape determined as follows:
#nullable disable because Azure SDK libraries have not yet exposed nullable reference types outside of Azure.Core. The reason we have not done this is because the API compatibility tools we use cannot detect API breaking changes to nullable reference types.