cadl/packages/http-client-csharp
Jorge Rangel aa531cfafc
[http-client-csharp] fix: generate deserialization switch for nested discriminators (#4982)
fixes: https://github.com/microsoft/typespec/issues/4979
2024-11-06 17:54:57 +00:00
..
emitter Don't propagate client parameters to operation (#4295) 2024-11-05 02:22:08 +00:00
eng Add cadl-ranch structure default sln (#4924) 2024-11-01 01:56:50 +00:00
generator [http-client-csharp] fix: generate deserialization switch for nested discriminators (#4982) 2024-11-06 17:54:57 +00:00
api-extractor.json Run apiview checks in pr to detect public api changes (#3283) 2024-05-10 01:02:05 +00:00
package-lock.json Bump send and express in /packages/http-client-csharp (#4435) 2024-10-21 06:06:27 +00:00
package.json build(deps): bump tsp 0.61.2 (#4693) 2024-10-17 05:33:53 +00:00
readme.md Cadl ranch test framework (#3964) 2024-07-25 21:27:15 +00:00

readme.md

TypeSpec csharp emitter library

This is a TypeSpec library that will emit a .NET SDK from TypeSpec.

Prerequisite

Install Node.js 16 or above. (Verify by node --version) Install .NET 8.0 SDK for your specific platform. (or a higher version)

Getting started

Initialize TypeSpec Project

Follow TypeSpec Getting Started to initialize your TypeSpec project.

Make sure npx tsp compile . runs correctly.

Add typespec csharp

Run npm install @typespec/http-client-csharp.

Generate .NET client

Run command npx tsp compile --emit @typespec/http-client-csharp <path-to-typespec-file>

e.g.

npx tsp compile main.tsp --emit @typespec/http-client-csharp

Configuration

You can further configure the SDK generated, using the emitter options on @typespec/http-client-csharp.

You can set options in the command line directly via --option @typespec/http-client-csharp.<optionName>=XXX, e.g. --option @typespec/http-client-csharp.namespace=MyService.Namespace

or

Modify tspconfig.yaml in typespec project, add emitter options under options/@typespec/http-client-csharp.

emit:
  - "@typespec/http-client-csharp"
options:
  "@typespec/http-client-csharp":
+    namespace: MyService.Namespace

Supported Emitter options:

  • namespace define the client library namespace. e.g. MyService.Namespace.
  • emitter-output-dir define the output dire path which will store the generated code.
  • generate-protocol-methods indicate if you want to generate protocol method for every operation or not. The default value is true.
  • generate-convenience-methods indicate if you want to generate convenience method for every operation or not. The default value is true.
  • unreferenced-types-handling define the strategy how to handle the unreferenced types. It can be removeOrInternalize, internalize or keepAll
  • model-namespace indicate if we want to put the models in their own namespace which is a sub namespace of the client library namespace plus ".Models". if it is set false, the models will be put in the same namespace of the client. The default value is true.
  • clear-output-folder indicate if you want to clear up the output folder.
  • package-name define the package name.

Convenience API

By default, TypeSpec csharp generates all protocol APIs and convenience APIs. A few exceptions are API of JSON Merge Patch, and API of long-running operation with ambiguous response type.

You can configure whether generate convenience API or not via convenienceAPI decorator.

CadlRanch Tests

We run the generator against the common set of test defined in https://github.com/Azure/cadl-ranch/tree/main/packages/cadl-ranch-specs. For details on how to run and debug these tests see CadlRanch Testing