Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The Swagger Specification has undergone 3 revisions since initial creation in 20

Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes
----------------------- | ------------ | -------------------------- | -----
2.1.1-M2-SNAPSHOT | 2015-04-06 | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen)
2.1.0 | 2015-06-09 | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen)
2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/v2.0.17)
1.0.4 | 2012-04-12 | 1.0, 1.1 | [tag v1.0.4](https://github.com/swagger-api/swagger-codegen/tree/swagger-codegen_2.9.1-1.1)

Expand Down Expand Up @@ -154,7 +154,8 @@ Great for creating libraries on your ci server, from the [Swagger Editor](http:/
There are different aspects of customizing the code generator beyond just creating or modifying templates. Each language has a supporting configuration file to handle different type mappings, etc:

```
$ ls -1 modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/
$ ls -1 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/
AkkaScalaClientCodegen.java
AndroidClientCodegen.java
AsyncScalaClientCodegen.java
CSharpClientCodegen.java
Expand All @@ -167,6 +168,7 @@ PhpClientCodegen.java
Python3ClientCodegen.java
PythonClientCodegen.java
Qt5CPPGenerator.java
RetrofitClientCodegen.java
RubyClientCodegen.java
ScalaClientCodegen.java
ScalatraServerCodegen.java
Expand All @@ -175,6 +177,7 @@ StaticDocCodegen.java
StaticHtmlGenerator.java
SwaggerGenerator.java
SwaggerYamlGenerator.java
SwiftGenerator.java
TizenClientCodegen.java
```

Expand Down Expand Up @@ -237,7 +240,7 @@ To change, for example, the prefix for the Objective-C generated files, simply s
```
package com.mycompany.swagger.codegen;

import com.wordnik.swagger.codegen.languages.*;
import io.swagger.codegen.languages.*;

public class MyObjcCodegen extends ObjcClientCodegen {
static {
Expand Down
31 changes: 31 additions & 0 deletions bin/akka-scala-petstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/akka-scala -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l akka-scala -o samples/client/petstore/akka-scala"

java $JAVA_OPTS -jar $executable $ags
25 changes: 13 additions & 12 deletions modules/swagger-codegen-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>com.wordnik</groupId>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-project</artifactId>
<version>2.1.1-M2-SNAPSHOT</version>
<version>2.1.1</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -16,12 +16,12 @@
<build>
<finalName>swagger-codegen-cli</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
Expand All @@ -30,7 +30,7 @@
<configuration>
<archive>
<manifest>
<mainClass>com.wordnik.swagger.codegen.SwaggerCodegen</mainClass>
<mainClass>io.swagger.codegen.SwaggerCodegen</mainClass>
</manifest>
</archive>
</configuration>
Expand Down Expand Up @@ -62,7 +62,8 @@
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
Expand All @@ -74,7 +75,7 @@
<dependencies>

<dependency>
<groupId>com.wordnik</groupId>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.wordnik.swagger.codegen;
package io.swagger.codegen;

import com.wordnik.swagger.codegen.cmd.ConfigHelp;
import com.wordnik.swagger.codegen.cmd.Generate;
import com.wordnik.swagger.codegen.cmd.Langs;
import com.wordnik.swagger.codegen.cmd.Meta;
import io.airlift.airline.Cli;
import io.airlift.airline.Help;
import io.swagger.codegen.cmd.ConfigHelp;
import io.swagger.codegen.cmd.Generate;
import io.swagger.codegen.cmd.Langs;
import io.swagger.codegen.cmd.Meta;

/**
* User: lanwen
* Date: 24.03.15
* Time: 17:56
*
* <p>
* Command line interface for swagger codegen
* use `swagger-codegen-cli.jar help` for more info
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
package com.wordnik.swagger.codegen.cmd;
package io.swagger.codegen.cmd;

import com.wordnik.swagger.codegen.CliOption;
import com.wordnik.swagger.codegen.CodegenConfig;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;

import java.util.ServiceLoader;

import static java.util.ServiceLoader.load;

@Command(name = "config-help", description = "Config help for chosen lang")
public class ConfigHelp implements Runnable {

@Option(name = {"-l", "--lang"}, title = "language", required = true,
description = "language to get config help for")
private String lang;

@Override
public void run() {
System.out.println();
CodegenConfig config = forName(lang);
System.out.println("CONFIG OPTIONS");
for (CliOption langCliOption : config.cliOptions()) {
System.out.println("\t" + langCliOption.getOpt());
System.out.println("\t " + langCliOption.getDescription());
System.out.println();
}
}

/**
* Tries to load config class with SPI first, then with class name directly from classpath
*
* @param name name of config, or full qualified class name in classpath
* @return config class
*/
Expand All @@ -46,4 +37,16 @@ private static CodegenConfig forName(String name) {
throw new RuntimeException("Can't load config class with name ".concat(name), e);
}
}

@Override
public void run() {
System.out.println();
CodegenConfig config = forName(lang);
System.out.println("CONFIG OPTIONS");
for (CliOption langCliOption : config.cliOptions()) {
System.out.println("\t" + langCliOption.getOpt());
System.out.println("\t " + langCliOption.getDescription());
System.out.println();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.wordnik.swagger.codegen.cmd;

import com.wordnik.swagger.codegen.CliOption;
import com.wordnik.swagger.codegen.ClientOptInput;
import com.wordnik.swagger.codegen.ClientOpts;
import com.wordnik.swagger.codegen.CodegenConfig;
import com.wordnik.swagger.codegen.DefaultGenerator;
import com.wordnik.swagger.models.Swagger;
package io.swagger.codegen.cmd;

import config.Config;
import config.ConfigParser;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.ClientOptInput;
import io.swagger.codegen.ClientOpts;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.DefaultGenerator;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -57,15 +57,37 @@ public class Generate implements Runnable {
"Pass in a URL-encoded string of name:header with a comma separating multiple values")
private String auth;

@Option( name= {"-D"}, title = "system properties", description = "sets specified system properties in " +
@Option(name = {"-D"}, title = "system properties", description = "sets specified system properties in " +
"the format of name=value,name=value")
private String systemProperties;
@Option( name= {"-c", "--config"}, title = "configuration file", description = "Path to json configuration file. " +

@Option(name = {"-c", "--config"}, title = "configuration file", description = "Path to json configuration file. " +
"File content should be in a json format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...} " +
"Supported options can be different for each language. Run config-help -l {lang} command for language specific config options.")
private String configFile;

/**
* Tries to load config class with SPI first, then with class name directly from classpath
*
* @param name name of config, or full qualified class name in classpath
* @return config class
*/
private static CodegenConfig forName(String name) {
ServiceLoader<CodegenConfig> loader = load(CodegenConfig.class);
for (CodegenConfig config : loader) {
if (config.getName().equals(name)) {
return config;
}
}

// else try to load directly
try {
return (CodegenConfig) Class.forName(name).newInstance();
} catch (Exception e) {
throw new RuntimeException("Can't load config class with name ".concat(name), e);
}
}

@Override
public void run() {
verbosed(verbose);
Expand All @@ -84,13 +106,13 @@ public void run() {
if (null != templateDir) {
config.additionalProperties().put(TEMPLATE_DIR_PARAM, new File(templateDir).getAbsolutePath());
}
if(null != configFile){

if (null != configFile) {
Config genConfig = ConfigParser.read(configFile);
if (null != genConfig) {
for (CliOption langCliOption : config.cliOptions()) {
if (genConfig.hasOption(langCliOption.getOpt())) {
config.additionalProperties().put(langCliOption.getOpt(), genConfig.getOption(langCliOption.getOpt()));
config.additionalProperties().put(langCliOption.getOpt(), genConfig.getOption(langCliOption.getOpt()));
}
}
}
Expand All @@ -103,18 +125,19 @@ public void run() {
}

private void setSystemProperties() {
if( systemProperties != null && systemProperties.length() > 0 ){
for( String property : systemProperties.split(",")) {
if (systemProperties != null && systemProperties.length() > 0) {
for (String property : systemProperties.split(",")) {
int ix = property.indexOf('=');
if( ix > 0 && ix < property.length()-1 ){
System.setProperty( property.substring(0, ix), property.substring(ix+1) );
if (ix > 0 && ix < property.length() - 1) {
System.setProperty(property.substring(0, ix), property.substring(ix + 1));
}
}
}
}

/**
* If true parameter, adds system properties which enables debug mode in generator
*
* @param verbose - if true, enables debug mode
*/
private void verbosed(boolean verbose) {
Expand All @@ -132,25 +155,4 @@ private void verbosed(boolean verbose) {
System.setProperty("debugOperations", "");
System.setProperty("debugSupportingFiles", "");
}

/**
* Tries to load config class with SPI first, then with class name directly from classpath
* @param name name of config, or full qualified class name in classpath
* @return config class
*/
private static CodegenConfig forName(String name) {
ServiceLoader<CodegenConfig> loader = load(CodegenConfig.class);
for (CodegenConfig config : loader) {
if (config.getName().equals(name)) {
return config;
}
}

// else try to load directly
try {
return (CodegenConfig) Class.forName(name).newInstance();
} catch (Exception e) {
throw new RuntimeException("Can't load config class with name ".concat(name), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wordnik.swagger.codegen.cmd;
package io.swagger.codegen.cmd;

import ch.lambdaj.collection.LambdaIterable;
import com.wordnik.swagger.codegen.CodegenConfig;
import io.airlift.airline.Command;
import io.swagger.codegen.CodegenConfig;

import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.collection.LambdaCollections.with;
Expand Down
Loading