You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating clients with the posted api definition, the .Net Client has a generated Serialize helper function for the Cartype: localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.Serialize(cartype)); // form parameter
instead of the ParameterToString function: localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.ParameterToString(cartype)); // form parameter
openapi-generator version
maven 7.6.0 for .Net Client
OpenAPI declaration file content or url
openapi: 3.0.3info:
version: 1.1.1title: MyTitleservers:
- url: "http://localhost:50505"paths:
/api/myApi/CustomCar:
post:
tags:
- Custom Carssummary: Imports a custom Car.operationId: GenerateCustomCarrequestBody:
description: The description of the new car.content:
multipart/form-data:
schema:
$ref: "#/components/schemas/CustomCar"required: trueresponses:
202:
description: Accepted400:
description: Bad input.404:
description: Nothing here.500:
description: Error.components:
schemas:
CarType:
description: Possible car types.type: stringnullable: falseenum:
- Van
- Hachback
- Convertable
- Nonedefault: VanCustomCar:
description: A model which represents a custom Car.type: objectproperties:
cartype:
$ref: "#/components/schemas/CarType"
Generated CustomCarsApi.cs:
// CustomCarsApi.csnamespace MyCusomWebapiClient.Api
{[...]/// <summary>/// Represents a collection of functions to interact with the API endpoints/// </summary>publicpartialclassCustomCarsApi:ICustomCarsApi{[...]/// <summary>/// Imports a custom Car. /// </summary>/// <exception cref="MyCusomWebapiClient.Client.ApiException">Thrown when fails to make API call</exception>/// <param name="cartype"> (optional)</param>/// <param name="operationIndex">Index associated with the operation.</param>/// <returns>ApiResponse of Object(void)</returns>public MyCusomWebapiClient.Client.ApiResponse<Object>GenerateCustomCarWithHttpInfo(CarType?cartype=default(CarType?),intoperationIndex=0){
MyCusomWebapiClient.Client.RequestOptions localVarRequestOptions=new MyCusomWebapiClient.Client.RequestOptions();string[]_contentTypes=newstring[]{"multipart/form-data"};// to determine the Accept headerstring[]_accepts=newstring[]{};varlocalVarContentType= MyCusomWebapiClient.Client.ClientUtils.SelectHeaderContentType(_contentTypes);if(localVarContentType!=null){
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);}varlocalVarAccept= MyCusomWebapiClient.Client.ClientUtils.SelectHeaderAccept(_accepts);if(localVarAccept!=null){
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);}if(cartype!=null){
localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.Serialize(cartype));// form parameter}
localVarRequestOptions.Operation ="CustomCarsApi.GenerateCustomCar";
localVarRequestOptions.OperationIndex =operationIndex;// make the HTTP requestvarlocalVarResponse=this.Client.Post<Object>("/api/myApi/CustomCar", localVarRequestOptions,this.Configuration);if(this.ExceptionFactory !=null){Exception_exception=this.ExceptionFactory("GenerateCustomCar", localVarResponse);if(_exception!=null){throw _exception;}}returnlocalVarResponse;}[...]}
Here the problematic part is:
[...]if(cartype!=null){
localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.Serialize(cartype));// form parameter}[...]
this results in ""Van"" to be added to the form parameters, instead of the expected "Van" (default case).
The expected behavior can be achieved by changing the CustomCar Component and specifically add the string as type for the cartype, as follows:
CustomCar:
description: A model which represents a custom Car.type: objectproperties:
cartype:
type: string$ref: "#/components/schemas/CarType"
Resulting in MyCusomWebapiClient.Client.ClientUtils.ParameterToString() being used for the form parameter.
[...]if(cartype!=null){
localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.ParameterToString(cartype));// form parameter}[...]
Description
When generating clients with the posted api definition, the .Net Client has a generated Serialize helper function for the Cartype:
localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.Serialize(cartype)); // form parameter
instead of the ParameterToString function:
localVarRequestOptions.FormParameters.Add("cartype", MyCusomWebapiClient.Client.ClientUtils.ParameterToString(cartype)); // form parameter
openapi-generator version
maven 7.6.0 for .Net Client
OpenAPI declaration file content or url
Generated CustomCarsApi.cs:
Here the problematic part is:
this results in ""Van"" to be added to the form parameters, instead of the expected "Van" (default case).
The expected behavior can be achieved by changing the CustomCar Component and specifically add the string as type for the cartype, as follows:
Resulting in MyCusomWebapiClient.Client.ClientUtils.ParameterToString() being used for the form parameter.
Generation Details
java argumentList :
"-jar openapi-generator-cli-7.6.0
"generate"
"-i $($apiDefinition.Path)"
"-g csharp"
"-o $tempClientDirectory"
"--additional-properties packageName=$($apiDefinition.ClientPackageName)"
"--additional-properties targetFramework=net8.0"
"--global-property skipFormModel=false"
)
Issue
The issue is basically, that the type is not deduced by the generator itself.
The text was updated successfully, but these errors were encountered: