devhl-labs 7e529926a6
[csharp][generichost] Implement not required nullable properties (#16810)
* init

* fixed read and write

* completed changes using latest-nrt sample

* fixed all samples

* add null check on write, change on exception

* resolved conflicts

* build samples

* added backing property for not required properties

* more not required and nullable hanlding improvements

* revert sample updates for a merge master

* revert sample updates for a merge master

* sample build is working, need to remove warnings

* fixed warnings in .net 7 with nrt

* fixed manual tests

* fixed all samples

* fix npe

* removed debugging lines

* revert changes to unused file

* removed unused lambdas

* fix a serialization bug

* make option a hidden property

* updated documentation

* improved parameter ordering
2023-11-13 10:16:35 +08:00

16 KiB

Org.OpenAPITools - the C# library for the OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: " \

This C# SDK is automatically generated by the OpenAPI Generator project:

  • API version: 1.0.0
  • SDK version: 1.0.0
  • Build package: org.openapitools.codegen.languages.CSharpClientCodegen

Frameworks supported

  • .NET Core >=1.0
  • .NET Framework >=4.6
  • Mono/Xamarin >=vNext

Dependencies

The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:

Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations
Install-Package CompareNETObjects

Installation

Generate the DLL using your preferred tool (e.g. dotnet build)

Then include the DLL (under the bin folder) in the C# project, and use the namespaces:

using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;

Usage

To use the API client with a HTTP proxy, setup a System.Net.WebProxy

Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;

Connections

Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method.

To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see here for details). To use your own HttpClient instance just pass it to the ApiClass constructor.

HttpClientHandler yourHandler = new HttpClientHandler();
HttpClient yourHttpClient = new HttpClient(yourHandler);
var api = new YourApiClass(yourHttpClient, yourHandler);

If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory.

HttpClient yourHttpClient = new HttpClient();
var api = new YourApiClass(yourHttpClient);

You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available.

Here an example of DI setup in a sample web project:

services.AddHttpClient<YourApiClass>(httpClient =>
   new PetApi(httpClient));

Getting Started

using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;

namespace Example
{
    public class Example
    {
        public static void Main()
        {

            Configuration config = new Configuration();
            config.BasePath = "http://petstore.swagger.io:80/v2";
            // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes
            HttpClient httpClient = new HttpClient();
            HttpClientHandler httpClientHandler = new HttpClientHandler();
            var apiInstance = new AnotherFakeApi(httpClient, config, httpClientHandler);
            var modelClient = new ModelClient(); // ModelClient | client model

            try
            {
                // To test special tags
                ModelClient result = apiInstance.Call123TestSpecialTags(modelClient);
                Debug.WriteLine(result);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling AnotherFakeApi.Call123TestSpecialTags: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

        }
    }
}

Documentation for API Endpoints

All URIs are relative to http://petstore.swagger.io:80/v2

Class Method HTTP request Description
AnotherFakeApi Call123TestSpecialTags PATCH /another-fake/dummy To test special tags
DefaultApi FooGet GET /foo
DefaultApi GetCountry POST /country
DefaultApi Hello GET /hello Hello
DefaultApi RolesReportGet GET /roles/report
DefaultApi Test GET /test Retrieve an existing Notificationtest's Elements
FakeApi FakeHealthGet GET /fake/health Health check endpoint
FakeApi FakeOuterBooleanSerialize POST /fake/outer/boolean
FakeApi FakeOuterCompositeSerialize POST /fake/outer/composite
FakeApi FakeOuterNumberSerialize POST /fake/outer/number
FakeApi FakeOuterStringSerialize POST /fake/outer/string
FakeApi GetArrayOfEnums GET /fake/array-of-enums Array of Enums
FakeApi TestBodyWithFileSchema PUT /fake/body-with-file-schema
FakeApi TestBodyWithQueryParams PUT /fake/body-with-query-params
FakeApi TestClientModel PATCH /fake To test "client" model
FakeApi TestEndpointParameters POST /fake Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
FakeApi TestEnumParameters GET /fake To test enum parameters
FakeApi TestGroupParameters DELETE /fake Fake endpoint to test group parameters (optional)
FakeApi TestInlineAdditionalProperties POST /fake/inline-additionalProperties test inline additionalProperties
FakeApi TestInlineFreeformAdditionalProperties POST /fake/inline-freeform-additionalProperties test inline free-form additionalProperties
FakeApi TestJsonFormData GET /fake/jsonFormData test json serialization of form data
FakeApi TestQueryParameterCollectionFormat PUT /fake/test-query-parameters
FakeClassnameTags123Api TestClassname PATCH /fake_classname_test To test class name in snake case
PetApi AddPet POST /pet Add a new pet to the store
PetApi DeletePet DELETE /pet/{petId} Deletes a pet
PetApi FindPetsByStatus GET /pet/findByStatus Finds Pets by status
PetApi FindPetsByTags GET /pet/findByTags Finds Pets by tags
PetApi GetPetById GET /pet/{petId} Find pet by ID
PetApi UpdatePet PUT /pet Update an existing pet
PetApi UpdatePetWithForm POST /pet/{petId} Updates a pet in the store with form data
PetApi UploadFile POST /pet/{petId}/uploadImage uploads an image
PetApi UploadFileWithRequiredFile POST /fake/{petId}/uploadImageWithRequiredFile uploads an image (required)
StoreApi DeleteOrder DELETE /store/order/{order_id} Delete purchase order by ID
StoreApi GetInventory GET /store/inventory Returns pet inventories by status
StoreApi GetOrderById GET /store/order/{order_id} Find purchase order by ID
StoreApi PlaceOrder POST /store/order Place an order for a pet
UserApi CreateUser POST /user Create user
UserApi CreateUsersWithArrayInput POST /user/createWithArray Creates list of users with given input array
UserApi CreateUsersWithListInput POST /user/createWithList Creates list of users with given input array
UserApi DeleteUser DELETE /user/{username} Delete user
UserApi GetUserByName GET /user/{username} Get user by user name
UserApi LoginUser GET /user/login Logs user into the system
UserApi LogoutUser GET /user/logout Logs out current logged in user session
UserApi UpdateUser PUT /user/{username} Updated user

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

petstore_auth

api_key

  • Type: API key
  • API key parameter name: api_key
  • Location: HTTP header

api_key_query

  • Type: API key
  • API key parameter name: api_key_query
  • Location: URL query string

http_basic_test

  • Type: HTTP basic authentication

bearer_test

  • Type: Bearer Authentication

http_signature_test

  • Type: HTTP signature authentication