Skip to content

Fix ExampleGenerator#3438

Open
vfpfafrf wants to merge 6 commits intoswagger-api:masterfrom
vfpfafrf:fix-examplegenerator
Open

Fix ExampleGenerator#3438
vfpfafrf wants to merge 6 commits intoswagger-api:masterfrom
vfpfafrf:fix-examplegenerator

Conversation

@vfpfafrf
Copy link
Copy Markdown

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'] = "";

@wing328
Copy link
Copy Markdown
Contributor

wing328 commented Jul 22, 2016

@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 wing328 added this to the v2.2.1 milestone Jul 22, 2016
@vfpfafrf
Copy link
Copy Markdown
Author

@wing328 I rollback method modifies to public/protected. May be it should be interface with abstract and default generator implementations ?

@wing328
Copy link
Copy Markdown
Contributor

wing328 commented Jul 25, 2016

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)

@vfpfafrf
Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants