The main question is that if the enum can or cannot have "." in the middle of the name, my example is the following:
So someone sent me this openapi yaml file, bellow, that i am generating a controller in c# for. This is the yaml I received:
/actions/MyAction:
post:
summary: blahblah
tags:
- action
parameters:
- in: body
name: MyAction
required: true
schema:
type: object
properties:
data:
type: object
properties:
target:
type: string
location:
description: thelocation
type: string
enum:
- location.Outdoor1
- location.Outdoor2
- location.Outdoor3
The object class generated in c# for :
public partial class Data2
{
[Newtonsoft.Json.JsonProperty("target", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public stringTarget { get; set; }
[Newtonsoft.Json.JsonProperty("location", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
public Data2Location? Location { get; set; }
}
And for the enum i have:
public enum Data2Location
{
[System.Runtime.Serialization.EnumMember(Value = @"location.Outdoor1")]
location_Outdoor1= 0,
[System.Runtime.Serialization.EnumMember(Value = @"location.Outdoor2")]
location_Outdoor2 = 1,
[System.Runtime.Serialization.EnumMember(Value = @"location.Outdoor3")]
location_Outdoor3= 2,
}
the controller
[Microsoft.AspNetCore.Mvc.HttpPost, Microsoft.AspNetCore.Mvc.Route("actions/MyAction")]
public Microsoft.AspNetCore.Mvc.IActionResult MyAction([Microsoft.AspNetCore.Mvc.FromBody] Data2data)
{
return _implementation.MyAction(data);
}
My troubles are with the enum "thelocation" because when i send a request from Postman the all object comes null in the method above for the request: post to http://localhost:5000/api/v1/actions/Myaction With body:
{
"data": {
"target": "thetarget"
"location":"location.Outdoor2"
}
}