forked from loafle/openapi-generator-original
rollback codegen template
This commit is contained in:
parent
f610958209
commit
7b6480f7f8
@ -9,7 +9,7 @@ your changes applied.
|
|||||||
The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.
|
The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.
|
||||||
|
|
||||||
|
|
||||||
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||||
|
|
||||||
## How do I use this?
|
## How do I use this?
|
||||||
At this point, you've likely generated a client setup. It will include something along these lines:
|
At this point, you've likely generated a client setup. It will include something along these lines:
|
||||||
|
@ -8,186 +8,184 @@ import java.io.File;
|
|||||||
|
|
||||||
public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig {
|
public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig {
|
||||||
|
|
||||||
// source folder where to write the files
|
// source folder where to write the files
|
||||||
protected String sourceFolder = "src";
|
protected String sourceFolder = "src";
|
||||||
protected String apiVersion = "1.0.0";
|
protected String apiVersion = "1.0.0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the type of generator.
|
* Configures the type of generator.
|
||||||
*
|
*
|
||||||
* @return the CodegenType for this generator
|
* @return the CodegenType for this generator
|
||||||
* @see io.swagger.codegen.CodegenType
|
* @see io.swagger.codegen.CodegenType
|
||||||
*/
|
*/
|
||||||
public CodegenType getTag() {
|
public CodegenType getTag() {
|
||||||
return CodegenType.CLIENT;
|
return CodegenType.CLIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures a friendly name for the generator. This will be used by the generator
|
* Configures a friendly name for the generator. This will be used by the generator
|
||||||
* to select the library with the -l flag.
|
* to select the library with the -l flag.
|
||||||
*
|
*
|
||||||
* @return the friendly name for the generator
|
* @return the friendly name for the generator
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "{{name}}";
|
return "{{name}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||||
* tips, parameters here
|
* tips, parameters here
|
||||||
*
|
*
|
||||||
* @return A string value for the help message
|
* @return A string value for the help message
|
||||||
*/
|
*/
|
||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return "Generates a {{name}} client library.";
|
return "Generates a {{name}} client library.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public {{generatorClass}}() {
|
public {{generatorClass}}() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// set the output folder here
|
// set the output folder here
|
||||||
outputFolder = "generated-code/{{name}}";
|
outputFolder = "generated-code/{{name}}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models. You can write model files using the modelTemplateFiles map.
|
* Models. You can write model files using the modelTemplateFiles map.
|
||||||
* if you want to create one template for file, you can do so here.
|
* if you want to create one template for file, you can do so here.
|
||||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||||
* a different extension
|
* a different extension
|
||||||
*/
|
*/
|
||||||
modelTemplateFiles.put(
|
modelTemplateFiles.put(
|
||||||
"model.mustache", // the template to use
|
"model.mustache", // the template to use
|
||||||
".sample"); // the extension for each file to write
|
".sample"); // the extension for each file to write
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||||
* as with models, add multiple entries with different extensions for multiple files per
|
* as with models, add multiple entries with different extensions for multiple files per
|
||||||
* class
|
* class
|
||||||
*/
|
*/
|
||||||
apiTemplateFiles.put(
|
apiTemplateFiles.put(
|
||||||
"api.mustache", // the template to use
|
"api.mustache", // the template to use
|
||||||
".sample"); // the extension for each file to write
|
".sample"); // the extension for each file to write
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template Location. This is the location which templates will be read from. The generator
|
* Template Location. This is the location which templates will be read from. The generator
|
||||||
* will use the resource stream to attempt to read the templates.
|
* will use the resource stream to attempt to read the templates.
|
||||||
*/
|
*/
|
||||||
templateDir = "{{name}}";
|
templateDir = "{{name}}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api Package. Optional, if needed, this can be used in templates
|
* Api Package. Optional, if needed, this can be used in templates
|
||||||
*/
|
*/
|
||||||
apiPackage = "io.swagger.client.api";
|
apiPackage = "io.swagger.client.api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model Package. Optional, if needed, this can be used in templates
|
* Model Package. Optional, if needed, this can be used in templates
|
||||||
*/
|
*/
|
||||||
modelPackage = "io.swagger.client.model";
|
modelPackage = "io.swagger.client.model";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reserved words. Override this with reserved words specific to your language
|
* Reserved words. Override this with reserved words specific to your language
|
||||||
*/
|
*/
|
||||||
reservedWords = new HashSet
|
reservedWords = new HashSet<String> (
|
||||||
<String> (
|
Arrays.asList(
|
||||||
Arrays.asList(
|
"sample1", // replace with static values
|
||||||
"sample1", // replace with static values
|
"sample2")
|
||||||
"sample2")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional Properties. These values can be passed to the templates and
|
* Additional Properties. These values can be passed to the templates and
|
||||||
* are available in models, apis, and supporting files
|
* are available in models, apis, and supporting files
|
||||||
*/
|
*/
|
||||||
additionalProperties.put("apiVersion", apiVersion);
|
additionalProperties.put("apiVersion", apiVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supporting Files. You can write single files for the generator with the
|
* Supporting Files. You can write single files for the generator with the
|
||||||
* entire object tree available. If the input file has a suffix of `.mustache
|
* entire object tree available. If the input file has a suffix of `.mustache
|
||||||
* it will be processed by the template engine. Otherwise, it will be copied
|
* it will be processed by the template engine. Otherwise, it will be copied
|
||||||
*/
|
*/
|
||||||
supportingFiles.add(new SupportingFile("myFile.mustache", // the input template or file
|
supportingFiles.add(new SupportingFile("myFile.mustache", // the input template or file
|
||||||
"", // the destination folder, relative `outputFolder`
|
"", // the destination folder, relative `outputFolder`
|
||||||
"myFile.sample") // the output file
|
"myFile.sample") // the output file
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Language Specific Primitives. These types will not trigger imports by
|
* Language Specific Primitives. These types will not trigger imports by
|
||||||
* the client generator
|
* the client generator
|
||||||
*/
|
*/
|
||||||
languageSpecificPrimitives = new HashSet
|
languageSpecificPrimitives = new HashSet<String>(
|
||||||
<String>(
|
Arrays.asList(
|
||||||
Arrays.asList(
|
"Type1", // replace these with your types
|
||||||
"Type1", // replace these with your types
|
|
||||||
"Type2")
|
"Type2")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||||
* those terms here. This logic is only called if a variable matches the reseved words
|
* those terms here. This logic is only called if a variable matches the reseved words
|
||||||
*
|
*
|
||||||
* @return the escaped term
|
* @return the escaped term
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String escapeReservedWord(String name) {
|
public String escapeReservedWord(String name) {
|
||||||
return "_" + name; // add an underscore to the name
|
return "_" + name; // add an underscore to the name
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||||
* instantiated
|
* instantiated
|
||||||
*/
|
*/
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||||
* instantiated
|
* instantiated
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||||
* types. There is typically special handling for different property types
|
* types. There is typically special handling for different property types
|
||||||
*
|
*
|
||||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Property p) {
|
public String getTypeDeclaration(Property p) {
|
||||||
if(p instanceof ArrayProperty) {
|
if(p instanceof ArrayProperty) {
|
||||||
ArrayProperty ap = (ArrayProperty) p;
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
Property inner = ap.getItems();
|
Property inner = ap.getItems();
|
||||||
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
else if (p instanceof MapProperty) {
|
else if (p instanceof MapProperty) {
|
||||||
MapProperty mp = (MapProperty) p;
|
MapProperty mp = (MapProperty) p;
|
||||||
Property inner = mp.getAdditionalProperties();
|
Property inner = mp.getAdditionalProperties();
|
||||||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||||
*
|
*
|
||||||
* @return a string value of the type or complex model for this property
|
* @return a string value of the type or complex model for this property
|
||||||
* @see io.swagger.models.properties.Property
|
* @see io.swagger.models.properties.Property
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getSwaggerType(Property p) {
|
public String getSwaggerType(Property p) {
|
||||||
String swaggerType = super.getSwaggerType(p);
|
String swaggerType = super.getSwaggerType(p);
|
||||||
String type = null;
|
String type = null;
|
||||||
if(typeMapping.containsKey(swaggerType)) {
|
if(typeMapping.containsKey(swaggerType)) {
|
||||||
type = typeMapping.get(swaggerType);
|
type = typeMapping.get(swaggerType);
|
||||||
if(languageSpecificPrimitives.contains(type))
|
if(languageSpecificPrimitives.contains(type))
|
||||||
return toModelName(type);
|
return toModelName(type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
type = swaggerType;
|
type = swaggerType;
|
||||||
return toModelName(type);
|
return toModelName(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,105 +1,102 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>{{name}}-swagger-codegen</artifactId>
|
<artifactId>{{name}}-swagger-codegen</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>{{name}}-swagger-codegen</name>
|
<name>{{name}}-swagger-codegen</name>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<prerequisites>
|
<prerequisites>
|
||||||
<maven>2.2.0</maven>
|
<maven>2.2.0</maven>
|
||||||
</prerequisites>
|
</prerequisites>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.12</version>
|
<version>2.12</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<systemProperties>
|
<systemProperties>
|
||||||
<property>
|
<property>
|
||||||
<name>loggerPath</name>
|
<name>loggerPath</name>
|
||||||
<value>conf/log4j.properties</value>
|
<value>conf/log4j.properties</value>
|
||||||
</property>
|
</property>
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||||
<parallel>methods</parallel>
|
<parallel>methods</parallel>
|
||||||
<forkMode>pertest</forkMode>
|
<forkMode>pertest</forkMode>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- attach test jar -->
|
<!-- attach test jar -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>2.2</version>
|
<version>2.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar</goal>
|
<goal>jar</goal>
|
||||||
<goal>test-jar</goal>
|
<goal>test-jar</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>add_sources</id>
|
<id>add_sources</id>
|
||||||
<phase>generate-sources</phase>
|
<phase>generate-sources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>add-source</goal>
|
<goal>add-source</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>
|
<source>src/main/java</source>
|
||||||
src/main/java</source>
|
</sources>
|
||||||
</sources>
|
</configuration>
|
||||||
</configuration>
|
</execution>
|
||||||
</execution>
|
<execution>
|
||||||
<execution>
|
<id>add_test_sources</id>
|
||||||
<id>add_test_sources</id>
|
<phase>generate-test-sources</phase>
|
||||||
<phase>generate-test-sources</phase>
|
<goals>
|
||||||
<goals>
|
<goal>add-test-source</goal>
|
||||||
<goal>add-test-source</goal>
|
</goals>
|
||||||
</goals>
|
<configuration>
|
||||||
<configuration>
|
<sources>
|
||||||
<sources>
|
<source>src/test/java</source>
|
||||||
<source>
|
</sources>
|
||||||
src/test/java</source>
|
</configuration>
|
||||||
</sources>
|
</execution>
|
||||||
</configuration>
|
</executions>
|
||||||
</execution>
|
</plugin>
|
||||||
</executions>
|
<plugin>
|
||||||
</plugin>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<plugin>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<version>2.3.2</version>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<configuration>
|
||||||
<version>2.3.2</version>
|
<source>1.6</source>
|
||||||
<configuration>
|
<target>1.6</target>
|
||||||
<source>
|
</configuration>
|
||||||
1.6</source>
|
</plugin>
|
||||||
<target>1.6</target>
|
</plugins>
|
||||||
</configuration>
|
</build>
|
||||||
</plugin>
|
<dependencies>
|
||||||
</plugins>
|
<dependency>
|
||||||
</build>
|
<groupId>io.swagger</groupId>
|
||||||
<dependencies>
|
<artifactId>swagger-codegen</artifactId>
|
||||||
<dependency>
|
<version>${swagger-codegen-version}</version>
|
||||||
<groupId>io.swagger</groupId>
|
<scope>provided</scope>
|
||||||
<artifactId>swagger-codegen</artifactId>
|
</dependency>
|
||||||
<version>${swagger-codegen-version}</version>
|
</dependencies>
|
||||||
<scope>provided</scope>
|
<properties>
|
||||||
</dependency>
|
<swagger-codegen-version>2.1.2-M1</swagger-codegen-version>
|
||||||
</dependencies>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
<properties>
|
<junit-version>4.8.1</junit-version>
|
||||||
<swagger-codegen-version>2.1.2-M1</swagger-codegen-version>
|
</properties>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
|
||||||
<junit-version>4.8.1</junit-version>
|
|
||||||
</properties>
|
|
||||||
</project>
|
</project>
|
Loading…
x
Reference in New Issue
Block a user