Fix ExampleGenerator
Fixes several issues in ExampleGenerator:
- Incorrect float & double generation (values taken from DecimalProperty)
Definition:
"Test" : {
"type" : "object",
"properties" : {
"pFloat" : {
"type" : "number",
"format" : "float"
},
"pDouble" : {
"type" : "number",
"format" : "double"
}
}
}
Result:
examples['application/json'] = {
"pFloat" : 1.3579000000000001069366817318950779736042022705078125,
"pDouble" : 1.3579000000000001069366817318950779736042022705078125
};
- Incorrect object example generation as string, not an object:
Definition:
"Test" : {
"type" : "object",
"properties" : {
"obj" : {
"type" : "object"
}
}
}
Result:
examples['application/json'] = {
"obj" : "{}"
};
- ComposedModel generates empty example result
Definition:
"Test" : {
"allOf" : [
{
"$ref" : "#/definitions/TypeOne"
},
{
"$ref" : "#/definitions/TypeTwo"
}
]
},
"TypeOne" : {
"type" : "object",
...
},
"TypeTwo" : {
"type" : "object",
...
}
Result:
examples['application/json'] = "";
@vfpfafrf thanks for the PR. I noticed that you've changed some methods from public/protected to private. Can we keep those as public/protected as there are use cases in which the developers customize the generator?
@wing328 I rollback method modifies to public/protected. May be it should be interface with abstract and default generator implementations ?
May be it should be interface with abstract and default generator implementations ?
Yes, I think that's better as the same Example Generator cannot meet the syntax requirement of all languages (e.g. C# float value needs to end with "f", e.g. 1.37f)
C# float value needs to end with "f", e.g. 1.37f
I dont think this is a problem - example objects use deserialization from JSON-string - from swagger-codegen/modules/swagger-codegen/src/main/resources/aspnet5/mapReturn.mustache (or from listReturn.mustache)
var example = exampleJson != null
? JsonConvert.DeserializeObject<Dictionary<{{#returnType}}{{{returnType}}}{{/returnType}}>>(exampleJson)
: new Dictionary<{{#returnType}}{{{returnType}}}{{/returnType}}>();
But the problem is in swagger-codegen/modules/swagger-codegen/src/main/resources/aspnet5/controller.mustache where exampleJson declared as null-object, so result is always empty:
string exampleJson = null;
I don't have experience in C#, so i can't fix it in right way