Open KeyboardNerd opened 6 years ago
Can you post a part of the generated code?
This is where build fails:
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "9.10.46.0 (Newtonsoft.Json v9.0.0.0)")]
public partial class MinLength : int, System.ComponentModel.INotifyPropertyChanged
{
public string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
public static MinLength FromJson(string data)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<MinLength>(data);
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
allOf is handled as inheritance:
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
This is a bug or enhancement. Inheritance should not be applied when schema is any or a primitive type.
Can you set `"type": "integer"?
BTW: I recommend to just use NSwag.Core for a complete Swagger 2.0 (and 3.0) model...
FYI, when generating CSharp types for the OData 4 CSDL schema, I'm getting the same error: edm.cs(550, 52): [CS0509] 'PositiveIntegerDefault0': cannot derive from sealed type 'int'
Generated code:
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "11.0.2.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class PositiveIntegerDefault0 : int
{
}
positiveInteger
is a type defined in https://json-schema.org/draft-04/schema, so this might come up for other schemas that reference it.
This isn't critical for my work, just sharing info.
When using CSharpGenerator for OpenAPI v2.0 Json Schema, the generated code contains the following error:
'MinLength': cannot derive from sealed type 'int' ConsoleApplication1
I think this is related to 'MinLength' is using
$ref
to reference the type on this line. This is reproducible onNJsonChema.CodeGeneration version 9.10.46
Do you have any work around?
Thanks.
The code I'm using is as following: