Skip to content

Instantly share code, notes, and snippets.

@who
Last active May 11, 2016 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save who/9cef971dc1f58f27ba3cd7cc46c908c5 to your computer and use it in GitHub Desktop.
Save who/9cef971dc1f58f27ba3cd7cc46c908c5 to your computer and use it in GitHub Desktop.

Getting Started

cd `mktemp -d /tmp/codegen.XXXXXXXX`;
git clone https://github.com/swagger-api/swagger-codegen.git;
cd swagger-codegen;
mvn package;

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar meta -o output/myLibrary -n FooBarGen -p com.foo.example.generated;

mvn clean package -f output/myLibrary/pom.xml;

java -cp output/myLibrary/target/FooBarGen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen;

java -cp output/myLibrary/target/FooBarGen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
  io.swagger.codegen.SwaggerCodegen generate -l FooBarGen\
  -i http://petstore.swagger.io/v2/swagger.json \
  -o myClient;

Viewing the debug operations

# To view the debug operations:
java -cp output/myLibrary/target/FooBarGen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen generate -l FooBarGen -i http://petstore.swagger.io/v2/swagger.json -o myOutput -DdebugOperations=true

Customize the options that the generator uses

View available options (FooBarGen)

java -cp output/myLibrary/target/FooBarGen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen config-help -l FooBarGen

output:

CONFIG OPTIONS
	sortParamsByRequiredFlag
	    Sort method arguments to place required parameters before optional parameters. (Default: true)

	ensureUniqueParams
	    Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)

Setting a config option in the generate call (FooBarGen)

First, create a config json file.

echo '{"sortParamsByRequiredFlag":false}' > /tmp/FooBarGen-config.json;

Second, pass this file to the codegen generage command using the -c flag

java -cp output/myLibrary/target/FooBarGen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
  io.swagger.codegen.SwaggerCodegen generate -l FooBarGen\
  -i http://petstore.swagger.io/v2/swagger.json \
  -o myClient \
  -c /tmp/FooBarGen-config.json;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment