Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp] Fix getModelFromParameter #18137

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ protected void patchVendorExtensionNullableValueType(CodegenParameter parameter)
* Returns the model related to the given parameter
*/
private CodegenModel getModelFromParameter(List<ModelMap> allModels, CodegenParameter parameter) {
return parameter.isModel
return parameter.isModel || parameter.getIsEnumOrRef()
? allModels.stream().map(m -> m.getModel()).filter(m -> m.getClassname().equals(parameter.dataType)).findFirst().orElse(null)
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ tags:
- name: user
description: Operations about user
paths:
/test:
get:
summary: Test API
parameters:
- in: query
name: testQuery
schema:
$ref: '#/components/schemas/TestEnum'
required: false
responses:
'200':
description: OK
/pet:
post:
tags:
Expand Down Expand Up @@ -620,6 +632,11 @@ components:
name: api_key
in: header
schemas:
TestEnum:
type: string
enum:
- A
- B
Order:
title: Pet Order
description: An order for a pets from the pet store
Expand Down
4 changes: 2 additions & 2 deletions samples/client/echo_api/csharp-restsharp/docs/PathApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Example
var pathString = "pathString_example"; // string |
var pathInteger = 56; // int |
var enumNonrefStringPath = "success"; // string |
var enumRefStringPath = new StringEnumRef(); // StringEnumRef |
var enumRefStringPath = (StringEnumRef) "success"; // StringEnumRef |

try
{
Expand Down Expand Up @@ -80,7 +80,7 @@ catch (ApiException e)
| **pathString** | **string** | | |
| **pathInteger** | **int** | | |
| **enumNonrefStringPath** | **string** | | |
| **enumRefStringPath** | [**StringEnumRef**](StringEnumRef.md) | | |
| **enumRefStringPath** | **StringEnumRef** | | |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ public Org.OpenAPITools.Client.ApiResponse<string> TestsPathStringPathStringInte
throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'enumNonrefStringPath' when calling PathApi->TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}

// verify the required parameter 'enumRefStringPath' is set
if (enumRefStringPath == null)
{
throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'enumRefStringPath' when calling PathApi->TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}

Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();

string[] _contentTypes = new string[] {
Expand Down Expand Up @@ -349,12 +343,6 @@ public Org.OpenAPITools.Client.ApiResponse<string> TestsPathStringPathStringInte
throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'enumNonrefStringPath' when calling PathApi->TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}

// verify the required parameter 'enumRefStringPath' is set
if (enumRefStringPath == null)
{
throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'enumRefStringPath' when calling PathApi->TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}


Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace Example
Configuration config = new Configuration();
config.BasePath = "http://localhost";
var apiInstance = new MultipartApi(config);
var status = new MultipartMixedStatus(); // MultipartMixedStatus |
var status = (MultipartMixedStatus) "ALLOWED"; // MultipartMixedStatus |
var file = new System.IO.MemoryStream(System.IO.File.ReadAllBytes("/path/to/file.txt")); // System.IO.Stream | a file
var marker = new MultipartMixedRequestMarker(); // MultipartMixedRequestMarker | (optional)
var statusArray = new List<MultipartMixedStatus>(); // List<MultipartMixedStatus> | (optional)
Expand Down Expand Up @@ -158,7 +158,7 @@ catch (ApiException e)

| Name | Type | Description | Notes |
|------|------|-------------|-------|
| **status** | [**MultipartMixedStatus**](MultipartMixedStatus.md) | | |
| **status** | **MultipartMixedStatus** | | |
| **file** | **System.IO.Stream****System.IO.Stream** | a file | |
| **marker** | [**MultipartMixedRequestMarker**](MultipartMixedRequestMarker.md) | | [optional] |
| **statusArray** | [**List&lt;MultipartMixedStatus&gt;**](MultipartMixedStatus.md) | | [optional] |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,6 @@ public Org.OpenAPITools.Client.ExceptionFactory ExceptionFactory
/// <returns>ApiResponse of Object(void)</returns>
public Org.OpenAPITools.Client.ApiResponse<Object> MultipartMixedWithHttpInfo(MultipartMixedStatus status, System.IO.Stream file, MultipartMixedRequestMarker marker = default(MultipartMixedRequestMarker), List<MultipartMixedStatus> statusArray = default(List<MultipartMixedStatus>), int operationIndex = 0)
{
// verify the required parameter 'status' is set
if (status == null)
{
throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'status' when calling MultipartApi->MultipartMixed");
}

// verify the required parameter 'file' is set
if (file == null)
{
Expand Down Expand Up @@ -514,7 +508,7 @@ public Org.OpenAPITools.Client.ExceptionFactory ExceptionFactory
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}

localVarRequestOptions.FormParameters.Add("status", Org.OpenAPITools.Client.ClientUtils.Serialize(status)); // form parameter
localVarRequestOptions.FormParameters.Add("status", Org.OpenAPITools.Client.ClientUtils.ParameterToString(status)); // form parameter
if (marker != null)
{
localVarRequestOptions.FormParameters.Add("marker", Org.OpenAPITools.Client.ClientUtils.Serialize(marker)); // form parameter
Expand Down Expand Up @@ -572,12 +566,6 @@ public Org.OpenAPITools.Client.ExceptionFactory ExceptionFactory
/// <returns>Task of ApiResponse</returns>
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<Object>> MultipartMixedWithHttpInfoAsync(MultipartMixedStatus status, System.IO.Stream file, MultipartMixedRequestMarker marker = default(MultipartMixedRequestMarker), List<MultipartMixedStatus> statusArray = default(List<MultipartMixedStatus>), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
// verify the required parameter 'status' is set
if (status == null)
{
throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'status' when calling MultipartApi->MultipartMixed");
}

// verify the required parameter 'file' is set
if (file == null)
{
Expand Down Expand Up @@ -607,7 +595,7 @@ public Org.OpenAPITools.Client.ExceptionFactory ExceptionFactory
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}

localVarRequestOptions.FormParameters.Add("status", Org.OpenAPITools.Client.ClientUtils.Serialize(status)); // form parameter
localVarRequestOptions.FormParameters.Add("status", Org.OpenAPITools.Client.ClientUtils.ParameterToString(status)); // form parameter
if (marker != null)
{
localVarRequestOptions.FormParameters.Add("marker", Org.OpenAPITools.Client.ClientUtils.Serialize(marker)); // form parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build.sh
src/Org.OpenAPITools/.gitignore
src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs
src/Org.OpenAPITools/Authentication/ApiAuthentication.cs
src/Org.OpenAPITools/Controllers/DefaultApi.cs
src/Org.OpenAPITools/Controllers/FakeApi.cs
src/Org.OpenAPITools/Controllers/PetApi.cs
src/Org.OpenAPITools/Controllers/StoreApi.cs
Expand All @@ -22,6 +23,7 @@ src/Org.OpenAPITools/Models/Dog.cs
src/Org.OpenAPITools/Models/Order.cs
src/Org.OpenAPITools/Models/Pet.cs
src/Org.OpenAPITools/Models/Tag.cs
src/Org.OpenAPITools/Models/TestEnum.cs
src/Org.OpenAPITools/Models/User.cs
src/Org.OpenAPITools/OpenApi/TypeExtensions.cs
src/Org.OpenAPITools/Program.cs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;
using Newtonsoft.Json;
using Org.OpenAPITools.Attributes;
using Org.OpenAPITools.Models;

namespace Org.OpenAPITools.Controllers
{
/// <summary>
///
/// </summary>
[ApiController]
public class DefaultApiController : ControllerBase
{
/// <summary>
/// Test API
/// </summary>
/// <param name="testQuery"></param>
/// <response code="200">OK</response>
[HttpGet]
[Route("/v2/test")]
[ValidateModelState]
[SwaggerOperation("TestGet")]
public virtual IActionResult TestGet([FromQuery (Name = "testQuery")]TestEnum? testQuery)
{

//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200);

throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Org.OpenAPITools.Converters;

namespace Org.OpenAPITools.Models
{
/// <summary>
/// Gets or Sets TestEnum
/// </summary>
[TypeConverter(typeof(CustomEnumConverter<TestEnum>))]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public enum TestEnum
{

/// <summary>
/// Enum AEnum for A
/// </summary>
[EnumMember(Value = "A")]
AEnum = 1,

/// <summary>
/// Enum BEnum for B
/// </summary>
[EnumMember(Value = "B")]
BEnum = 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@
"name" : "user"
} ],
"paths" : {
"/test" : {
"get" : {
"parameters" : [ {
"explode" : true,
"in" : "query",
"name" : "testQuery",
"required" : false,
"schema" : {
"$ref" : "#/components/schemas/TestEnum"
},
"style" : "form"
} ],
"responses" : {
"200" : {
"description" : "OK"
}
},
"summary" : "Test API"
}
},
"/pet" : {
"post" : {
"description" : "",
Expand Down Expand Up @@ -828,6 +848,10 @@
}
},
"schemas" : {
"TestEnum" : {
"enum" : [ "A", "B" ],
"type" : "string"
},
"Order" : {
"description" : "An order for a pets from the pet store",
"example" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build.sh
src/Org.OpenAPITools/.gitignore
src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs
src/Org.OpenAPITools/Authentication/ApiAuthentication.cs
src/Org.OpenAPITools/Controllers/DefaultApi.cs
src/Org.OpenAPITools/Controllers/FakeApi.cs
src/Org.OpenAPITools/Controllers/PetApi.cs
src/Org.OpenAPITools/Controllers/StoreApi.cs
Expand All @@ -22,6 +23,7 @@ src/Org.OpenAPITools/Models/Dog.cs
src/Org.OpenAPITools/Models/Order.cs
src/Org.OpenAPITools/Models/Pet.cs
src/Org.OpenAPITools/Models/Tag.cs
src/Org.OpenAPITools/Models/TestEnum.cs
src/Org.OpenAPITools/Models/User.cs
src/Org.OpenAPITools/OpenApi/TypeExtensions.cs
src/Org.OpenAPITools/Program.cs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;
using Newtonsoft.Json;
using Org.OpenAPITools.Attributes;
using Org.OpenAPITools.Models;

namespace Org.OpenAPITools.Controllers
{
/// <summary>
///
/// </summary>
[ApiController]
public class DefaultApiController : ControllerBase
{
/// <summary>
/// Test API
/// </summary>
/// <param name="testQuery"></param>
/// <response code="200">OK</response>
[HttpGet]
[Route("/v2/test")]
[ValidateModelState]
[SwaggerOperation("TestGet")]
public virtual IActionResult TestGet([FromQuery (Name = "testQuery")]TestEnum? testQuery)
{

//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200);

throw new NotImplementedException();
}
}
}
Loading
Loading