Sto usando JSON.NET per generare schema JSON dalla classe di oggetti C#. Ma non ero in grado di aggiungere altri attributi dello schema JSON, ad es. maxLength, pattern (regex per convalidare la posta elettronica), ecc.Usa JSON.NET per generare schema JSON con attributi aggiuntivi
Di seguito è riportato il mio codice di lavoro, posso solo generare schema json con l'attributo richiesto. Sarebbe bello se qualcuno potesse pubblicare qualche esempio di codice su come aggiungere quegli attributi extra per lo schema json.
Grazie,
codice mio esempio
public class Customer
{
[JsonProperty(Required = Required.Always)]
public int CustomerID { get; set; }
[JsonProperty(Required = Required.Always)]
public string FirstName { get; set; }
[JsonProperty(Required = Required.Always)]
public string LastName { get; set; }
[JsonProperty(Required = Required.Always)]
public string Email { get; set; }
[JsonProperty(Required = Required.AllowNull)]
public string Phone { get; set; }
}
a
{
"title" : "Customer",
"type" : "object",
"properties" : {
"CustomerID" : {
"required" : true,
"type" : "integer"
},
"FirstName" : {
"required" : true,
"type" : "string"
},
"LastName" : {
"required" : true,
"type" : "string"
},
"Email" : {
"required" : true,
"type" : "string"
},
"Phone" : {
"required" : true,
"type" : [
"string",
"null"
]
}
}
}
non ho ben vedere come questo affronta la questione . – unomi