Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
improvements to csharp-netcore-function generator
  • Loading branch information
wing328 committed Apr 20, 2022
commit ffe1f11a11a80af679e94efe557fab6b2aa9fce0
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class CsharpNetcoreFunctionsServerCodegen extends AbstractCSharpCodegen {
public static final String GENERATE_BODY = "generateBody";
public static final String BUILD_TARGET = "buildTarget";
public static final String MODEL_CLASS_MODIFIER = "modelClassModifier";
public static final String TARGET_FRAMEWORK= "targetFramework";
public static final String TARGET_FRAMEWORK = "targetFramework";
public static final String FUNCTIONS_SDK_VERSION = "functionsSDKVersion";

public static final String COMPATIBILITY_VERSION = "compatibilityVersion";
Expand Down Expand Up @@ -283,7 +283,7 @@ public String getName() {

@Override
public String getHelp() {
return "Generates an ASP.NET Core Web API server.";
return "Creates Azure function templates on top of the models/converters created by the C# codegens. This function is contained in a partial class. Default Get/Create/Patch/Post etc. methods are created with an underscore prefix. The assumption is that when the function is implemented, the partial class will be completed with another partial class. The implementing code should be located in a method of the same name, only without the underscore prefix. If no such method is found then the function will throw a Not Implemented exception. This setup allows the endpoints to be specified in the schema at build time, and separated from the implementing function.";
}

@Override
Expand Down Expand Up @@ -379,8 +379,7 @@ protected void processOperation(CodegenOperation operation) {

// HACK: Unlikely in the wild, but we need to clean operation paths for MVC Routing
if (operation.path != null) {
if (operation.path.startsWith("/"))
{
if (operation.path.startsWith("/")) {
operation.path = operation.path.substring(1);
}
String original = operation.path;
Expand Down Expand Up @@ -419,10 +418,9 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
continue;
}

if(consumesString.toString().isEmpty()) {
if (consumesString.toString().isEmpty()) {
consumesString = new StringBuilder("\"" + consume.get("mediaType") + "\"");
}
else {
} else {
consumesString.append(", \"").append(consume.get("mediaType")).append("\"");
}

Expand All @@ -447,7 +445,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
}
}

if(!consumesString.toString().isEmpty()) {
if (!consumesString.toString().isEmpty()) {
operation.vendorExtensions.put("x-aspnetcore-consumes", consumesString.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
.gitignore
Docs/PetApi.md
Docs/StoreApi.md
Docs/UserApi.md
Org.OpenAPITools.sln
README.md
appveyor.yml
docs/ApiResponse.md
docs/Category.md
docs/Order.md
docs/Pet.md
docs/Tag.md
docs/User.md
generatedSrc/Client/ApiClient.cs
generatedSrc/Client/ApiException.cs
generatedSrc/Client/ApiResponse.cs
generatedSrc/Client/Configuration.cs
generatedSrc/Client/ExceptionFactory.cs
generatedSrc/Client/IApiAccessor.cs
generatedSrc/Client/OpenAPIDateConverter.cs
generatedSrc/Functions/PetApi.cs
generatedSrc/Functions/PetApi.cs
generatedSrc/Functions/StoreApi.cs
generatedSrc/Functions/StoreApi.cs
generatedSrc/Functions/UserApi.cs
generatedSrc/Functions/UserApi.cs
generatedSrc/Models/ApiResponse.cs
generatedSrc/Models/Category.cs
generatedSrc/Models/Order.cs
generatedSrc/Models/Pet.cs
generatedSrc/Models/Tag.cs
generatedSrc/Models/User.cs
generatedSrc/README.md
generatedSrc/project.json
git_push.sh
src/Org.OpenAPITools/Client/ApiClient.cs
src/Org.OpenAPITools/Client/ApiException.cs
src/Org.OpenAPITools/Client/ApiResponse.cs
src/Org.OpenAPITools/Client/ClientUtils.cs
src/Org.OpenAPITools/Client/Configuration.cs
src/Org.OpenAPITools/Client/ExceptionFactory.cs
src/Org.OpenAPITools/Client/GlobalConfiguration.cs
src/Org.OpenAPITools/Client/HttpMethod.cs
src/Org.OpenAPITools/Client/IApiAccessor.cs
src/Org.OpenAPITools/Client/IAsynchronousClient.cs
src/Org.OpenAPITools/Client/IReadableConfiguration.cs
src/Org.OpenAPITools/Client/ISynchronousClient.cs
src/Org.OpenAPITools/Client/Multimap.cs
src/Org.OpenAPITools/Client/OpenAPIDateConverter.cs
src/Org.OpenAPITools/Client/RequestOptions.cs
src/Org.OpenAPITools/Client/RetryConfiguration.cs
src/Org.OpenAPITools/Models/AbstractOpenAPISchema.cs
build.bat
build.sh
src/Org.OpenAPITools/.gitignore
src/Org.OpenAPITools/Converters/CustomEnumConverter.cs
src/Org.OpenAPITools/Functions/PetApi.cs
src/Org.OpenAPITools/Functions/StoreApi.cs
src/Org.OpenAPITools/Functions/UserApi.cs
src/Org.OpenAPITools/Models/ApiResponse.cs
src/Org.OpenAPITools/Models/Category.cs
src/Org.OpenAPITools/Models/Order.cs
src/Org.OpenAPITools/Models/Pet.cs
src/Org.OpenAPITools/Models/Tag.cs
src/Org.OpenAPITools/Models/User.cs
src/Org.OpenAPITools/OpenApi/TypeExtensions.cs
src/Org.OpenAPITools/Org.OpenAPITools.csproj
src/Org.OpenAPITools/host.json
src/Org.OpenAPITools/local.settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.1-SNAPSHOT
6.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Org.OpenAPITools", "src\Org.OpenAPITools\Org.OpenAPITools.csproj", "{5B19F3CA-CD16-44C9-9809-BDA788DA25A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5B19F3CA-CD16-44C9-9809-BDA788DA25A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B19F3CA-CD16-44C9-9809-BDA788DA25A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B19F3CA-CD16-44C9-9809-BDA788DA25A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B19F3CA-CD16-44C9-9809-BDA788DA25A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
157 changes: 11 additions & 146 deletions samples/client/petstore/csharp-netcore-functions/README.md
Original file line number Diff line number Diff line change
@@ -1,159 +1,24 @@
# Org.OpenAPITools - the C# library for the OpenAPI Petstore
# Org.OpenAPITools - Azure Functions v4 Server

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.

This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
## Run

- API version: 1.0.0
- SDK version: 1.0.0
- Build package: org.openapitools.codegen.languages.CsharpNetcoreFunctionsServerCodegen
Linux/OS X:

<a name="frameworks-supported"></a>
## Frameworks supported
- .NET Core >=1.0
- .NET Framework >=4.6
- Mono/Xamarin >=vNext

<a name="dependencies"></a>
## Dependencies

- [RestSharp](https://www.nuget.org/packages/RestSharp) - 106.11.7 or later
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 12.0.3 or later
- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later
- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.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
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations
sh build.sh
```

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).
NOTE: RestSharp for .Net Core creates a new socket for each api call, which can lead to a socket exhaustion problem. See [RestSharp#1406](https://github.com/restsharp/RestSharp/issues/1406).

<a name="installation"></a>
## Installation
Generate the DLL using your preferred tool (e.g. `dotnet build`)
Windows:

Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
```csharp
using Org.OpenAPITools.Apis;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Models;
```
<a name="usage"></a>
## Usage

To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
```csharp
Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;
build.bat
```
## Run in Docker

<a name="getting-started"></a>
## Getting Started

```csharp
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Apis;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Models;

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

Configuration config = new Configuration();
config.BasePath = "http://petstore.swagger.io/v2";
// Configure OAuth2 access token for authorization: petstore_auth
config.AccessToken = "YOUR_ACCESS_TOKEN";

var apiInstance = new PetApi(config);
var pet = new Pet(); // Pet | Pet object that needs to be added to the store

try
{
// Add a new pet to the store
Pet result = apiInstance.AddPet(pet);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling PetApi.AddPet: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}

}
}
}
```

<a name="documentation-for-api-endpoints"></a>
## Documentation for API Endpoints

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

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
*PetApi* | [**FindPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**GetPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**UpdatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**PlaceOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
*UserApi* | [**CreateUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
*UserApi* | [**CreateUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**CreateUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
*UserApi* | [**DeleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
*UserApi* | [**GetUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
*UserApi* | [**LoginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
*UserApi* | [**LogoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
*UserApi* | [**UpdateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user


<a name="documentation-for-models"></a>
## Documentation for Models

- [Models.ApiResponse](docs/ApiResponse.md)
- [Models.Category](docs/Category.md)
- [Models.Order](docs/Order.md)
- [Models.Pet](docs/Pet.md)
- [Models.Tag](docs/Tag.md)
- [Models.User](docs/User.md)


<a name="documentation-for-authorization"></a>
## Documentation for Authorization

<a name="api_key"></a>
### api_key

- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header

<a name="petstore_auth"></a>
### petstore_auth

- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
- **Scopes**:
- write:pets: modify pets in your account
- read:pets: read your pets

cd src/Org.OpenAPITools
docker build -t org.openapitools .
docker run -p 5000:8080 org.openapitools
```
9 changes: 9 additions & 0 deletions samples/client/petstore/csharp-netcore-functions/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:: Generated by: https://openapi-generator.tech
::

@echo off

dotnet restore src\Org.OpenAPITools
dotnet build src\Org.OpenAPITools
echo Now, run the following to start the project: dotnet run -p src\Org.OpenAPITools\Org.OpenAPITools.csproj --launch-profile web.
echo.
8 changes: 8 additions & 0 deletions samples/client/petstore/csharp-netcore-functions/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#
# Generated by: https://openapi-generator.tech
#

dotnet restore src/Org.OpenAPITools/ && \
dotnet build src/Org.OpenAPITools/ && \
echo "Now, run the following to start the project: func start"
Loading