swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.91k stars 6.03k forks source link

Codegen doesn't use "example" for response body #2387

Open pcads opened 8 years ago

pcads commented 8 years ago

Not sure if this is by design or bug. I have example for every object under definitions section. When I use codegen to generate a nodejs server, I am hoping at least the response body for GET should use the example data, but it doesn't.

Example data shows up under "Response Class", but when I click "Try it out!", in stead of example data, I get generic json object generated by Codegen using the schema. Like {"userName": "aeiou"}

Do I miss anything? Thanks

wing328 commented 8 years ago

@pcads I don't think the nodejs server stub generator supports the feature you mentioned and we welcome contribution to make the improvement.

The msutache template for nodejs is a good starting point:

https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/nodejs

pcads commented 8 years ago

I am not familiar with mustache. I will take a look and hopefully I could do something. Thanks

wing328 commented 8 years ago

My apologies. In the nodejs template, I did find the use of {{examples}} mustache tag:

service.mustache:  {{#examples}}examples['{{contentType}}'] = {{{example}}};
service.mustache:  {{/examples}}

Can you try starting the nodejs server with the following command instead?

NODE_ENV=development node index
pcads commented 8 years ago

I tried with NODE_ENV=development node index, still doesn't work.

djskinner commented 8 years ago

Yeah I don't think using the example data is in the node template. I was using it earlier and the controllers serve up dummy data that contains the likes of {"userName": "aeiou"}