mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-12 00:21:18 +00:00
* the result I want to obtain * add csharp-petstore-net-40.bat for windows * just ran bin\windows\csharp-petstore-all.bat * Removed those directories: - samples\client\petstore\csharp - samples\client\petstore\csharp-dotnet2 then ran : bin\windows\csharp-petstore-all.bat * - update JsonSubTypes to 1.1.3 by using nuget dependency (the package is compatible with net40) - allign all version of Newtonsoft.Json to 10.0.3 * the result of bin\windows\csharp-petstore-all.bat * ran bin\security\windows\csharp-petstore.bat
205 lines
6.9 KiB
Plaintext
205 lines
6.9 KiB
Plaintext
# {{packageName}} - the C# library for the {{appName}}
|
|
|
|
{{#appDescription}}
|
|
{{{appDescription}}}
|
|
{{/appDescription}}
|
|
|
|
This C# SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
|
|
|
|
- API version: {{appVersion}}
|
|
- SDK version: {{packageVersion}}
|
|
{{^hideGenerationTimestamp}}
|
|
- Build date: {{generatedDate}}
|
|
{{/hideGenerationTimestamp}}
|
|
- Build package: {{generatorClass}}
|
|
{{#infoUrl}}
|
|
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
|
{{/infoUrl}}
|
|
|
|
<a name="frameworks-supported"></a>
|
|
## Frameworks supported
|
|
{{#netStandard}}
|
|
- .NET Core >=1.0
|
|
- .NET Framework >=4.6
|
|
- Mono/Xamarin >=vNext
|
|
- UWP >=10.0
|
|
{{/netStandard}}
|
|
{{^netStandard}}
|
|
{{^supportUWP}}
|
|
- .NET 4.0 or later
|
|
- Windows Phone 7.1 (Mango)
|
|
{{/supportUWP}}
|
|
{{#supportUWP}}
|
|
- UWP
|
|
{{/supportUWP}}
|
|
{{/netStandard}}
|
|
|
|
<a name="dependencies"></a>
|
|
## Dependencies
|
|
{{#netStandard}}
|
|
- FubarCoder.RestSharp.Portable.Core >=4.0.7
|
|
- FubarCoder.RestSharp.Portable.HttpClient >=4.0.7
|
|
- Newtonsoft.Json >=10.0.3
|
|
{{/netStandard}}
|
|
{{^netStandard}}
|
|
- [RestSharp](https://www.nuget.org/packages/RestSharp) - 105.1.0 or later
|
|
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 7.0.0 or later
|
|
|
|
The DLLs included in the package may not be the latest version. We recommend using [NuGet] (https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:
|
|
```
|
|
Install-Package RestSharp
|
|
Install-Package Newtonsoft.Json
|
|
```
|
|
|
|
NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See [RestSharp#742](https://github.com/restsharp/RestSharp/issues/742)
|
|
{{/netStandard}}
|
|
|
|
<a name="installation"></a>
|
|
## Installation
|
|
{{#netStandard}}
|
|
Generate the DLL using your preferred tool
|
|
{{/netStandard}}
|
|
{{^netStandard}}
|
|
Run the following command to generate the DLL
|
|
- [Mac/Linux] `/bin/sh build.sh`
|
|
- [Windows] `build.bat`
|
|
{{/netStandard}}
|
|
|
|
Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
|
|
```csharp
|
|
using {{packageName}}.{{apiPackage}};
|
|
using {{packageName}}.Client;
|
|
using {{packageName}}.{{modelPackage}};
|
|
```
|
|
{{^netStandard}}
|
|
<a name="packaging"></a>
|
|
## Packaging
|
|
|
|
A `.nuspec` is included with the project. You can follow the Nuget quickstart to [create](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-package) and [publish](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#publish-the-package) packages.
|
|
|
|
This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly:
|
|
|
|
```
|
|
nuget pack -Build -OutputDirectory out {{packageName}}.csproj
|
|
```
|
|
|
|
Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual.
|
|
|
|
{{/netStandard}}
|
|
<a name="getting-started"></a>
|
|
## Getting Started
|
|
|
|
```csharp
|
|
using System;
|
|
using System.Diagnostics;
|
|
using {{packageName}}.{{apiPackage}};
|
|
using {{packageName}}.Client;
|
|
using {{packageName}}.{{modelPackage}};
|
|
|
|
namespace Example
|
|
{
|
|
public class {{operationId}}Example
|
|
{
|
|
public void main()
|
|
{
|
|
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
|
|
{{#hasAuthMethods}}
|
|
{{#authMethods}}
|
|
{{#isBasic}}
|
|
// Configure HTTP basic authorization: {{{name}}}
|
|
Configuration.Default.Username = "YOUR_USERNAME";
|
|
Configuration.Default.Password = "YOUR_PASSWORD";
|
|
{{/isBasic}}
|
|
{{#isApiKey}}
|
|
// Configure API key authorization: {{{name}}}
|
|
Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY");
|
|
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
|
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");
|
|
{{/isApiKey}}
|
|
{{#isOAuth}}
|
|
// Configure OAuth2 access token for authorization: {{{name}}}
|
|
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
|
|
{{/isOAuth}}
|
|
{{/authMethods}}
|
|
|
|
{{/hasAuthMethods}}
|
|
var apiInstance = new {{classname}}();
|
|
{{#allParams}}
|
|
{{#isPrimitiveType}}
|
|
var {{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
|
|
{{/isPrimitiveType}}
|
|
{{^isPrimitiveType}}
|
|
var {{paramName}} = new {{{dataType}}}(); // {{{dataType}}} | {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
|
|
{{/isPrimitiveType}}
|
|
{{/allParams}}
|
|
|
|
try
|
|
{
|
|
{{#summary}}
|
|
// {{{.}}}
|
|
{{/summary}}
|
|
{{#returnType}}{{{.}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
|
|
Debug.WriteLine(result);{{/returnType}}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Print("Exception when calling {{classname}}.{{operationId}}: " + e.Message );
|
|
}
|
|
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
<a name="documentation-for-api-endpoints"></a>
|
|
## Documentation for API Endpoints
|
|
|
|
All URIs are relative to *{{{basePath}}}*
|
|
|
|
Class | Method | HTTP request | Description
|
|
------------ | ------------- | ------------- | -------------
|
|
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
|
|
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
|
|
|
<a name="documentation-for-models"></a>
|
|
## Documentation for Models
|
|
|
|
{{#modelPackage}}
|
|
{{#models}}{{#model}} - [{{{modelPackage}}}.{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
|
|
{{/model}}{{/models}}
|
|
{{/modelPackage}}
|
|
{{^modelPackage}}
|
|
No model defined in this package
|
|
{{/modelPackage}}
|
|
|
|
<a name="documentation-for-authorization"></a>
|
|
## Documentation for Authorization
|
|
|
|
{{^authMethods}}
|
|
All endpoints do not require authorization.
|
|
{{/authMethods}}
|
|
{{#authMethods}}
|
|
{{#last}}
|
|
Authentication schemes defined for the API:
|
|
{{/last}}
|
|
{{/authMethods}}
|
|
{{#authMethods}}
|
|
<a name="{{name}}"></a>
|
|
### {{name}}
|
|
|
|
{{#isApiKey}}- **Type**: API key
|
|
- **API key parameter name**: {{keyParamName}}
|
|
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
|
{{/isApiKey}}
|
|
{{#isBasic}}- **Type**: HTTP basic authentication
|
|
{{/isBasic}}
|
|
{{#isOAuth}}- **Type**: OAuth
|
|
- **Flow**: {{flow}}
|
|
- **Authorization URL**: {{authorizationUrl}}
|
|
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
|
{{#scopes}} - {{scope}}: {{description}}
|
|
{{/scopes}}
|
|
{{/isOAuth}}
|
|
|
|
{{/authMethods}}
|