swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Trying to insert data into the auto generated code from a configuration file

Open Keyrat06 opened this issue 9 years ago • 1 comments

So I am editing a mustache file to get the auto generated code to wait for some time before doing an action.

The mustache file looks like: `double wait_time_double = {{wait_time}};' 'int wait_time = (int) (wait_time_double * 1000);' 'Thread.sleep(wait_time)'

I want to allow a user to set wait_time from a cli that I am making separate from swagger. So users never have to deal with the swagger interface for auto generating code. I am able to take the users input and add it to the swagger.json api file so it looks like this:

{"swagger": "2.0", "info": { "description": "A sample applications", "version": "0.0.1", "title": "Hello WebApp", "contact": "name": "Sample application" }

... more api code

"wait_time":"0.1" }

Then i call the code generator by calling: swagger-codegen generate -i swagger.json -t timplate.mustache -l java -o output.java

However; this does not get swagger to give the mustache file the wait_time variable.

Any help would be greatly appeciated

Swagger-codegen version

2.2.2

Keyrat06 avatar Jun 12 '17 22:06 Keyrat06

You can add as additional property to the swagger generate command instead of json. swagger-codegen-cli generate -i swagger.json -t timplate.mustache -l java -o output.java --additional-properties wait_time=0.1

ravinikam avatar Jun 15 '17 04:06 ravinikam