Skip to content

Commit

Permalink
update how-to guide for csharp (#188)
Browse files Browse the repository at this point in the history
Update the how-to guide document for csharp
  • Loading branch information
chunyu3 authored Feb 1, 2024
1 parent a770156 commit 091cb14
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 21 deletions.
22 changes: 11 additions & 11 deletions docs/howtos/DataPlane Generation - DPG/02client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ client.cats.pet()
using PetStore;

PetStoreClient client = new PetStoreClient();
client.GetDogs().Feed();
client.GetDogs().Pet();
client.GetCats().Feed();
client.GetCats().Pet();
client.GetDogsClient().Feed();
client.GetDogsClient().Pet();
client.GetCatsClient().Feed();
client.GetCatsClient().Pet();
```

</TabItem>
Expand Down Expand Up @@ -228,12 +228,12 @@ using PetStore;

PetStoreClient client = new PetStoreClient();
client.Info();
client.GetBillings().History();
client.GetPets().Info();
client.GetPets().GetPetsActions().Feed();
client.GetPets().GetPetsActions().Pet();
client.GetActions().Open();
client.GetActions().Close();
client.GetBillingsClient().History();
client.GetPetsClient().Info();
client.GetPetsClient().GetPetsActionsClient().Feed();
client.GetPetsClient().GetPetsActionsClient().Pet();
client.GetActionsClient().Open();
client.GetActionsClient().Close();
```

</TabItem>
Expand Down Expand Up @@ -565,7 +565,7 @@ client2.pet()
using PetStore;
using PetStore.SubNamespace;

PetActionClient petActionClient = new PetActionClient();
SubNamespacePetActionClient petActionClient = new SubNamespacePetActionClient();
FoodClient foodClient = new FoodClient();

petActionClient.Pet();
Expand Down
92 changes: 87 additions & 5 deletions docs/howtos/DataPlane Generation - DPG/03convenient.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,26 @@ FIXME
<TabItem value="csharp" label="CSharp" >

```csharp
FIXME
namespace PetStoreNamespace.Models
{
public partial class OutputModel
{
public string Name { get; }
}
}

namespace PetStoreNamespace
{
public partial class PetStoreNamespaceClient
{
// protocol method
public virtual async Task<Response> GetModelAsync(string name, RequestContext context) {}
public virtual Response GetModel(string name, RequestContext context) {}
// convenience method
public virtual async Task<Response<OutputModel>> GetModelAsync(string name, CancellationToken cancellationToken = default) {}
public virtual Response<OutputModel> GetModel(string name, CancellationToken cancellationToken = default) {}
}
}
```

</TabItem>
Expand Down Expand Up @@ -120,7 +139,18 @@ using Azure.ClientGenerator.Core;
<TabItem value="csharp" label="CSharp" >

```c#
FIXME
// Model class is not generated.
// Convenient method is not generated.

namespace PetStoreNamespace
{
public partial class PetStoreNamespaceClient
{
// protocol method
public virtual async Task<Response> GetModelAsync(string name, RequestContext context) {}
public virtual Response GetModel(string name, RequestContext context) {}
}
}
```

</TabItem>
Expand Down Expand Up @@ -177,7 +207,27 @@ class _GetModel:
<TabItem value="csharp" label="CSharp" >

```csharp
FIXME
// Model class is internal
namespace PetStoreNamespace.Models
{
internal partial class OutputModel
{
public string Name { get; }
}
}
// Client method is internal
namespace PetStoreNamespace
{
public partial class PetStoreNamespaceClient
{
//protocol method
internal virtual async Task<Response> GetModelAsync(string name, RequestContext context) {}
internal virtual Response GetModel(string name, RequestContext context) {}
//convenience method
internal virtual async Task<Response<OutputModel>> GetModelAsync(string name, CancellationToken cancellationToken = default) {}
internal virtual Response<OutputModel> GetModel(string name, CancellationToken cancellationToken = default) {}
}
}
```

</TabItem>
Expand Down Expand Up @@ -218,7 +268,7 @@ changes the way the API is exposed for those models.

By default, the code generator will infer the usage based on the TypeSpec. If this inference doesn't
correspond to expectation, this can be customized with the `usage` decorator. Possible values are
`input` and `ouput`, and can be combined with `Usage.input | Usage.output`.
`input` and `output`, and can be combined with `Usage.input | Usage.output`.
> **NOTE:** If a model is never used, it will not be generated. Assigning a usage will force generation.
Expand Down Expand Up @@ -250,7 +300,39 @@ using Azure.ClientGenerator.Core;
<TabItem value="csharp" label="CSharp" >
```csharp
FIXME
// If a model is input-only, it has one public constructor with all required properties as parameters.
// The required properties only have getter. Optional properties have both getter and setter.
// A collection property which is not nullable only has getter whatever it is required or not.
namespace Azure.AI.OpenAI.Models
{
public partial class AzureCognitiveSearchIndexFieldMappingOptions
{
public AzureCognitiveSearchIndexFieldMappingOptions()
public string TitleFieldName { get; set; }
public string UrlFieldName { get; set; }
public string FilepathFieldName { get; set; }
public IList<string> ContentFieldNames { get; }
public string ContentFieldSeparator { get; set; }
public IList<string> VectorFieldNames { get; }
public IList<string> ImageVectorFieldNames { get; }
}
}
// If a model is output-only, it does not have any public constructor, and all properties only have getter, no setter.
// If a model is roundtrip (input + output), it has one public constructor with all required properties as parameters.
// All properties except colletion properties which are not nullable will have both getter and setter.
// A collection property which is not nullable only has getter.
namespace Azure.AI.OpenAI.Models
{
public partial class ImageGenerations
{
public ImageGenerations(DateTimeOffset created, IEnumerable<ImageGenerationData> data)
public DateTimeOffset Created { get; set; }
public IList<ImageGenerationData> Data { get; }
}
}
```
</TabItem>
Expand Down
63 changes: 60 additions & 3 deletions docs/howtos/DataPlane Generation - DPG/04renaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,26 @@ FIXME
<TabItem value="csharp" label="CSharp" >

```csharp
FIXME
namespace PetStoreNamespace.Models
{
public partial class InputModel
{
public string Name { get; }
}
}

namespace PetStoreNamespace
{
public partial class PetStoreNamespaceClient
{
// protocol method
public virtual async Task<Response> GetModelAsync(string name, RequestContext context) {}
public virtual Response GetModel(string name, RequestContext context) {}
// convenience method
public virtual async Task<Response<InputModel>> GetModelAsync(string name, CancellationToken cancellationToken = default) {}
public virtual Response<InputModel> GetModel(string name, CancellationToken cancellationToken = default) {}
}
}
```

</TabItem>
Expand Down Expand Up @@ -121,7 +140,26 @@ FIXME
<TabItem value="csharp" label="CSharp" >
```c#
FIXME
namespace PetStoreNamespace.Models
{
public partial class ParameterOptions
{
public string Name { get; }
}
}
namespace PetStoreNamespace
{
public partial class PetStoreNamespaceClient
{
// protocol method
public virtual async Task<Response> GetModelAsync(string name, RequestContext context) {}
public virtual Response GetModel(string name, RequestContext context) {}
// convenience method
public virtual async Task<Response<ParameterOptions>> GetModelAsync(string name, CancellationToken cancellationToken = default) {}
public virtual Response<ParameterOptions> GetModel(string name, CancellationToken cancellationToken = default) {}
}
}
```
</TabItem>
Expand Down Expand Up @@ -177,7 +215,26 @@ client.get_computed_model()
<TabItem value="csharp" label="CSharp" >
```csharp
FIXME
namespace PetStoreNamespace.Models
{
public partial class InputModel
{
public string Name { get; }
}
}
namespace PetStoreNamespace
{
public partial class PetStoreNamespaceClient
{
// protocol method
public virtual async Task<Response> ReadModelAsync(string name, RequestContext context) {}
public virtual Response ReadModel(string name, RequestContext context) {}
// convenience method
public virtual async Task<Response<InputModel>> ReadModelAsync(string name, CancellationToken cancellationToken = default) {}
public virtual Response<InputModel> ReadModel(string name, CancellationToken cancellationToken = default) {}
}
}
```
</TabItem>
Expand Down
48 changes: 46 additions & 2 deletions docs/howtos/DataPlane Generation - DPG/05union.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ At a glance, JS and Python supports natively union, while Java and C# will use o
<TabItem value="typespec" label="TypeSpec" default>

```typespec
@service({
title: "Analyze",
version: "v1",
})
namespace Analyze;
@route("/analyze")
@post
op analyze(@query mode: "strict" | "lenient", @body image: bytes): AnalyzeResult;
Expand Down Expand Up @@ -46,7 +51,46 @@ def completions(input: CompletionInput) -> CompletionResult:
<TabItem value="csharp" label="CSharp" >

```csharp
FIXME
// Union "strict" | "lenient" will be generate as extensible enum
namespace Analyze.Models
{
public readonly partial struct Mode : IEquatable<Mode>
{
public static Mode Strict { get; } = new Mode(StrictValue);
public static Mode Lenient { get; } = new Mode(LenientValue);
}
}

// other union which cannot be convert to enum will generate as BinaryData
namespace Analyze.Models
{
public partial class CompletionInput
{
public CompletionInput(BinaryData input)
public BinaryData Input { get; }
}
}
namespace Analyze
{
public partial class AnalyzeClient
{
//protocol method
public virtual async Task<Response> AnalyzeAsync(string mode, RequestContent content, RequestContext context = null) {}
public virtual Response Analyze(string mode, RequestContent content, RequestContext context = null) {}
//convenience method
public virtual async Task<Response<AnalyzeResult>> AnalyzeAsync(Mode mode, BinaryData image, CancellationToken cancellationToken = default) {}
public virtual Response<AnalyzeResult> Analyze(Mode mode, BinaryData image, CancellationToken cancellationToken = default) {}


//protocol method
public virtual async Task<Response> CompletionsAsync(RequestContent content, RequestContext context = null) {}
public virtual Response Completions(RequestContent content, RequestContext context = null) {}
//convenience method
public virtual async Task<Response<CompletionResult>> CompletionsAsync(CompletionInput input, CancellationToken cancellationToken = default) {}
public virtual Response<CompletionResult> Completions(CompletionInput input, CancellationToken cancellationToken = default) {}

}
}
```

</TabItem>
Expand All @@ -70,7 +114,7 @@ public final class CompletionInput {
public BinaryData getInput()
}

public final class Client {
public final class AnalyzeClient {
public Response<BinaryData> analyzeWithResponse(String mode, BinaryData image, RequestOptions requestOptions)
public Response<BinaryData> completionsWithResponse(BinaryData input, RequestOptions requestOptions)
public AnalyzeResult analyze(Mode mode, byte[] image)
Expand Down

0 comments on commit 091cb14

Please sign in to comment.