Merge pull request #571 from lanwen/cli-doc

update docs and bash about CLI usage, deprecate old cli classes
This commit is contained in:
Tony Tam
2015-03-28 08:50:46 -07:00
8 changed files with 65 additions and 41 deletions

View File

@@ -52,23 +52,41 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-o samples/client/petstore/java
```
With a number of options. You can get the options with the -h flag:
With a number of options. You can get the options with the `help generate` command:
```
usage: Codegen
-a,--auth addes authorization headers when fetching the
swagger definitions remotely. Pass in a
URL-encoded string of name:header with a comma
separating multiple values
-d,--debug-info prints additional info for debugging
-h,--help shows this message
-i,--input-spec <arg> location of the swagger spec, as URL or file
-l,--lang <arg> client language to generate.
Available languages include:
[android, async-scala, java, jaxrs, nodejs,
objc, scalatra, scala, dynamic-html, html,
swagger, tizen, php, ruby, python]
-o,--output <arg> where to write the generated files
-t,--template-dir <arg> folder containing the template files
NAME
swagger generate - Generate code with chosen lang
SYNOPSIS
swagger generate [(-a <authorization> | --auth <authorization>)]
(-i <spec file> | --input-spec <spec file>)
(-l <language> | --lang <language>)
[(-o <output directory> | --output <output directory>)]
[(-t <template directory> | --template-dir <template directory>)]
[(-v | --verbose)]
OPTIONS
-a <authorization>, --auth <authorization>
adds authorization headers when fetching the swagger definitions
remotely. Pass in a URL-encoded string of name:header with a comma
separating multiple values
-i <spec file>, --input-spec <spec file>
location of the swagger spec, as URL or file (required)
-l <language>, --lang <language>
client language to generate (maybe class name in classpath,
required)
-o <output directory>, --output <output directory>
where to write the generated files (current dir by default)
-t <template directory>, --template-dir <template directory>
folder containing the template files
-v, --verbose
verbose mode
```
You can then compile and run the client, as well as unit tests against it:
@@ -91,18 +109,17 @@ It's just as easy--just use the `-i` flag to point to either a server or file.
### Modifying the client library format
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger codegen processes mustache templates with the [jmustache](https://github.com/samskivert/jmustache) engine. You can modify our templates or make your own.
You can look at `modules/swagger-codegen/src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your tempalte folder. It actually is that easy.
You can look at `modules/swagger-codegen/src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your template folder. It actually is that easy.
### Making your own codegen modules
If you're starting a project with a new language and don't see what you need, swagger-codegen can help you create a project to generate your own libraries:
```
java -cp modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
com.wordnik.swagger.codegen.MetaGenerator \
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-cli.jar meta \
-o output/myLibrary -n myClientCodegen -p com.my.company.codegen
```
This will write, in the folder `output/myLibrary`, all the files you need to get started, including a README.md. Once modified and compiled, you can load your library with the codegen and generate clients with your own, custom-rolled logic.
This will write, in the folder `output/myLibrary`, all the files you need to get started, including a README.md. Once modified and compiled, you can load your library with the codegen and generate clients with your own, custom-rolled logic.
### Where is Javascript???
See our [javascript library](http://github.com/swagger-api/swagger-js)--it's completely dynamic and doesn't require

View File

@@ -20,9 +20,8 @@ fi
cd $APP_DIR
./bin/android-java-petstore.sh
./bin/dynamic-html.sh
./bin/html.sh
./bin/html-petstore.sh
./bin/jaxrs-petstore-server.sh
./bin/java-petstore-filemap.sh
./bin/java-petstore.sh
./bin/php-petstore.sh
./bin/python-petstore.sh

View File

@@ -1,7 +0,0 @@
package com.wordnik.swagger.codegen;
public class Readme {
public String getInfo() {
return "See the documentation for swagger-codegen";
}
}

View File

@@ -10,6 +10,11 @@ import io.airlift.airline.Help;
* User: lanwen
* Date: 24.03.15
* Time: 17:56
*
* Command line interface for swagger codegen
* use `swagger-codegen-cli.jar help` for more info
*
* @since 2.1.3-M1
*/
public class SwaggerCodegen {

View File

@@ -31,28 +31,28 @@ public class Generate implements Runnable {
public static final String TEMPLATE_DIR_PARAM = "templateDir";
@Option(name = {"-v", "--verbose"}, description = "verbose mode")
public boolean verbose;
private boolean verbose;
@Option(name = {"-l", "--lang"}, title = "language", required = true,
description = "client language to generate (maybe class name in classpath, required)")
public String lang;
private String lang;
@Option(name = {"-o", "--output"}, title = "output directory",
description = "where to write the generated files (current dir by default)")
public String output = "";
private String output = "";
@Option(name = {"-i", "--input-spec"}, title = "spec file", required = true,
description = "location of the swagger spec, as URL or file (required)")
public String spec;
private String spec;
@Option(name = {"-t", "--template-dir"}, title = "template directory",
description = "folder containing the template files")
public String templateDir;
private String templateDir;
@Option(name = {"-a", "--auth"}, title = "authorization",
description = "adds authorization headers when fetching the swagger definitions remotely. " +
"Pass in a URL-encoded string of name:header with a comma separating multiple values")
public String auth;
private String auth;
@Override
public void run() {

View File

@@ -33,22 +33,22 @@ import static com.google.common.base.Joiner.on;
"specify, and includes default templates to include.")
public class Meta implements Runnable {
public static final Logger LOG = LoggerFactory.getLogger(Meta.class);
private static final Logger LOG = LoggerFactory.getLogger(Meta.class);
public static final String TEMPLATE_DIR_CLASSPATH = "codegen";
public static final String MUSTACHE_EXTENSION = ".mustache";
private static final String TEMPLATE_DIR_CLASSPATH = "codegen";
private static final String MUSTACHE_EXTENSION = ".mustache";
@Option(name = {"-o", "--output"}, title = "output directory",
description = "where to write the generated files (current dir by default)")
public String outputFolder = "";
private String outputFolder = "";
@Option(name = {"-n", "--name"}, title = "name",
description = "the human-readable name of the generator")
public String name = "default";
private String name = "default";
@Option(name = {"-p", "--package"}, title = "package",
description = "the package to put the main class into (defaults to com.wordnik.swagger.codegen)")
public String targetPackage = "com.wordnik.swagger.codegen";
private String targetPackage = "com.wordnik.swagger.codegen";
@Override
public void run() {

View File

@@ -12,6 +12,11 @@ import org.apache.commons.cli.*;
import java.io.File;
import java.util.*;
/**
* @deprecated use instead {@link com.wordnik.swagger.codegen.DefaultGenerator}
* or cli interface from https://github.com/swagger-api/swagger-codegen/pull/547
*/
@Deprecated
public class Codegen extends DefaultGenerator {
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
static String configString;

View File

@@ -16,6 +16,11 @@ import java.io.File;
import java.io.Reader;
import java.util.*;
/**
* @deprecated use instead {@link com.wordnik.swagger.codegen.DefaultGenerator}
* or cli interface from https://github.com/swagger-api/swagger-codegen/pull/547
*/
@Deprecated
public class MetaGenerator extends AbstractGenerator {
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
static String configString;