Fix "meta" command (#157)

* Fix "meta" generator

* Add script in bin/ to test the use case

* Add result in samples/

* Update read-me

* Implement 'escapeQuotationMark'
This commit is contained in:
Jérémie Bresson 2018-04-20 09:25:51 +02:00 committed by William Cheng
parent 03490e9230
commit f3736d66b7
25 changed files with 704 additions and 66 deletions

View File

@ -238,18 +238,18 @@ To generate a PHP client for http://petstore.swagger.io/v2/swagger.json, please
git clone https://github.com/swagger-api/swagger-codegen git clone https://github.com/swagger-api/swagger-codegen
cd swagger-codegen cd swagger-codegen
mvn clean package mvn clean package
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \ -i http://petstore.swagger.io/v2/swagger.json \
-l php \ -l php \
-o /var/tmp/php_api_client -o /var/tmp/php_api_client
``` ```
(if you're on Windows, replace the last command with `java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l php -o c:\temp\php_api_client`) (if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l php -o c:\temp\php_api_client`)
You can also download the JAR (latest release) directly from [maven.org](http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar) You can also download the JAR (latest release) directly from [maven.org](http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar)
To get a list of **general** options available, please run `java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar help generate` To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate`
To get a list of PHP specified options (which can be passed to the generator with a config file via the `-c` option), please run `java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l php` To get a list of PHP specified options (which can be passed to the generator with a config file via the `-c` option), please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar config-help -l php`
## Generators ## Generators
@ -265,7 +265,7 @@ You can build a client against the swagger sample [petstore](http://petstore.swa
This will run the generator with this command: This will run the generator with this command:
```sh ```sh
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \ -i http://petstore.swagger.io/v2/swagger.json \
-l java \ -l java \
-o samples/client/petstore/java -o samples/client/petstore/java
@ -343,7 +343,7 @@ You can look at `modules/swagger-codegen/src/main/resources/${your-language}` fo
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: 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:
```sh ```sh
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar meta \ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar meta \
-o output/myLibrary -n myClientCodegen -p com.my.company.codegen -o output/myLibrary -n myClientCodegen -p com.my.company.codegen
``` ```
@ -352,18 +352,18 @@ This will write, in the folder `output/myLibrary`, all the files you need to get
You would then compile your library in the `output/myLibrary` folder with `mvn package` and execute the codegen like such: You would then compile your library in the `output/myLibrary` folder with `mvn package` and execute the codegen like such:
```sh ```sh
java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/openapi-generator-cli/target/openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator
``` ```
For Windows users, you will need to use `;` instead of `:` in the classpath, e.g. For Windows users, you will need to use `;` instead of `:` in the classpath, e.g.
``` ```
java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar;modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar;modules/openapi-generator-cli/target/openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator
``` ```
Note the `myClientCodegen` is an option now, and you can use the usual arguments for generating your library: Note the `myClientCodegen` is an option now, and you can use the usual arguments for generating your library:
```sh ```sh
java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \ java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/openapi-generator-cli/target/openapi-generator-cli.jar \
io.swagger.codegen.SwaggerCodegen generate -l myClientCodegen\ org.openapitools.codegen.OpenAPIGenerator generate -l myClientCodegen\
-i http://petstore.swagger.io/v2/swagger.json \ -i http://petstore.swagger.io/v2/swagger.json \
-o myClient -o myClient
``` ```
@ -493,7 +493,7 @@ TypeScriptNodeClientCodegen.java
Each of these files creates reasonable defaults so you can get running quickly. But if you want to configure package names, prefixes, model folders, etc. you can use a json config file to pass the values. Each of these files creates reasonable defaults so you can get running quickly. But if you want to configure package names, prefixes, model folders, etc. you can use a json config file to pass the values.
```sh ```sh
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \ -i http://petstore.swagger.io/v2/swagger.json \
-l java \ -l java \
-o samples/client/petstore/java \ -o samples/client/petstore/java \
@ -510,7 +510,7 @@ Supported config options can be different per language. Running `config-help -l
**These options are applied via configuration file (e.g. config.json) or by passing them with `-D{optionName}={optionValue}`**. (If `-D{optionName}` does not work, please open a [ticket](https://github.com/swagger-api/swagger-codegen/issues/new) and we'll look into it) **These options are applied via configuration file (e.g. config.json) or by passing them with `-D{optionName}={optionValue}`**. (If `-D{optionName}` does not work, please open a [ticket](https://github.com/swagger-api/swagger-codegen/issues/new) and we'll look into it)
```sh ```sh
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar config-help -l java
``` ```
Output Output
@ -655,7 +655,7 @@ To push the auto-generated SDK to GitHub, we provide `git_push.sh` to streamline
2) Generate the SDK 2) Generate the SDK
```sh ```sh
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l perl \ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l perl \
--git-user-id "wing328" \ --git-user-id "wing328" \
--git-repo-id "petstore-perl" \ --git-repo-id "petstore-perl" \

36
bin/meta-codegen.sh Executable file
View File

@ -0,0 +1,36 @@
#!/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/openapi-generator-cli/target/openapi-generator-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
fi
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="meta -n myClientCodegen -p com.my.company.codegen -o samples/meta-codegen/lib $@"
java $JAVA_OPTS -jar $executable $ags
mvn verify -f samples/meta-codegen/lib/pom.xml
ags2="generate -l myClientCodegen -i modules/openapi-generator/src/test/resources/2_0/petstore.json -o samples/meta-codegen/usage $@"
java $JAVA_OPTS -cp samples/meta-codegen/lib/target/myClientCodegen-swagger-codegen-1.0.0.jar:$executable org.openapitools.codegen.OpenAPIGenerator $ags2

View File

@ -1,15 +1,18 @@
package org.openapitools.codegen.cmd; package org.openapitools.codegen.cmd;
import ch.lambdaj.function.convert.Converter; import static ch.lambdaj.collection.LambdaCollections.with;
import static com.google.common.base.Joiner.on;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Mustache;
import io.airlift.airline.Command; import io.airlift.airline.Command;
import io.airlift.airline.Option; import io.airlift.airline.Option;
import org.apache.commons.io.FileUtils;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.DefaultGenerator; import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.SupportingFile; import org.openapitools.codegen.SupportingFile;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -19,8 +22,7 @@ import java.io.Reader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static ch.lambdaj.collection.LambdaCollections.with; import ch.lambdaj.function.convert.Converter;
import static com.google.common.base.Joiner.on;
/** /**
* User: lanwen Date: 24.03.15 Time: 20:22 * User: lanwen Date: 24.03.15 Time: 20:22
@ -56,26 +58,22 @@ public class Meta implements Runnable {
String mainClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name) + "Generator"; String mainClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name) + "Generator";
List<SupportingFile> supportingFiles = List<SupportingFile> supportingFiles =
ImmutableList ImmutableList.of(
.of(new SupportingFile("pom.mustache", "", "pom.xml"), new SupportingFile("pom.mustache", "", "pom.xml"),
new SupportingFile("generatorClass.mustache", on(File.separator) new SupportingFile("generatorClass.mustache", on(File.separator).join("src/main/java", asPath(targetPackage)), mainClass.concat(".java")),
.join("src/main/java", asPath(targetPackage)), mainClass new SupportingFile("README.mustache", "", "README.md"),
.concat(".java")), new SupportingFile("README.mustache", new SupportingFile("api.template", "src/main/resources" + File.separator + name,"api.mustache"),
"", "README.md"), new SupportingFile("api.template", new SupportingFile("model.template", "src/main/resources" + File.separator + name,"model.mustache"),
"src/main/resources" + File.separator + name, new SupportingFile("myFile.template", String.join(File.separator, "src", "main", "resources", name), "myFile.mustache"),
"api.mustache"), new SupportingFile("model.template", new SupportingFile("services.mustache", "src/main/resources/META-INF/services", CodegenConfig.class.getCanonicalName()));
"src/main/resources" + File.separator + name,
"model.mustache"), new SupportingFile("services.mustache",
"src/main/resources/META-INF/services",
"org.openapitools.codegen.CodegenConfig"));
String codegenVersion = Version.readVersionFromResources(); String currentVersion = Version.readVersionFromResources();
Map<String, Object> data = Map<String, Object> data =
new ImmutableMap.Builder<String, Object>().put("generatorPackage", targetPackage) new ImmutableMap.Builder<String, Object>().put("generatorPackage", targetPackage)
.put("generatorClass", mainClass).put("name", name) .put("generatorClass", mainClass).put("name", name)
.put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass) .put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass)
.put("codegenVersion", codegenVersion).build(); .put("openapiGeneratorVersion", currentVersion).build();
with(supportingFiles).convert(processFiles(targetDir, data)); with(supportingFiles).convert(processFiles(targetDir, data));

View File

@ -148,44 +148,26 @@ public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig
} }
/** /**
* Optional - type declaration. This is a String which is used by the templates to instantiate your * override with any special text escaping logic to handle unsafe
* types. There is typically special handling for different property types * characters so as to avoid code injection
* *
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates * @param input String to be cleaned up
* @return string with unsafe characters removed or escaped
*/ */
@Override @Override
public String getTypeDeclaration(Property p) { public String escapeUnsafeCharacters(String input) {
if(p instanceof ArrayProperty) { //TODO: check that this logic is safe to escape unsafe characters to avoid code injection
ArrayProperty ap = (ArrayProperty) p; return input;
Property inner = ap.getItems();
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
}
else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
}
return super.getTypeDeclaration(p);
} }
/** /**
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into * Escape single and/or double quote to avoid code injection
* 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 * @param input String to be cleaned up
* @see io.swagger.models.properties.Property * @return string with quotation mark removed or escaped
*/ */
@Override public String escapeQuotationMark(String input) {
public String getSwaggerType(Property p) { //TODO: check that this logic is safe to escape quotation mark to avoid code injection
String swaggerType = super.getSwaggerType(p); return input.replace("\"", "\\\"");
String type = null;
if(typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if(languageSpecificPrimitives.contains(type))
return toModelName(type);
}
else
type = swaggerType;
return toModelName(type);
} }
} }

View File

@ -0,0 +1 @@
# This is a sample model mustache template.

View File

@ -0,0 +1 @@
# This is a sample supporting file mustache template.

View File

@ -107,15 +107,15 @@
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.swagger</groupId> <groupId>org.openapitools</groupId>
<artifactId>swagger-codegen</artifactId> <artifactId>openapi-generator</artifactId>
<version>${swagger-codegen-version}</version> <version>${openapi-generator-version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-codegen-version>{{swaggerCodegenVersion}}</swagger-codegen-version> <openapi-generator-version>{{openapiGeneratorVersion}}</openapi-generator-version>
<maven-plugin-version>1.0.0</maven-plugin-version> <maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version> <junit-version>4.8.1</junit-version>
</properties> </properties>

View File

@ -0,0 +1,74 @@
# Swagger Codegen for the myClientCodegen library
## Overview
This is a boiler-plate project to generate your own client library with Swagger. Its goal is
to get you started with the basic plumbing so you can put in your own logic. It won't work without
your changes applied.
## What's Swagger?
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 [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) for additional information about the Swagger project, including additional libraries with support for other languages and more.
## How do I use this?
At this point, you've likely generated a client setup. It will include something along these lines:
```
.
|- README.md // this file
|- pom.xml // build script
|-- src
|--- main
|---- java
|----- com.my.company.codegen.MyclientcodegenGenerator.java // generator file
|---- resources
|----- myClientCodegen // template files
|----- META-INF
|------ services
|------- org.openapitools.codegen.CodegenConfig
```
You _will_ need to make changes in at least the following:
`MyclientcodegenGenerator.java`
Templates in this folder:
`src/main/resources/myClientCodegen`
Once modified, you can run this:
```
mvn package
```
In your generator project. A single jar file will be produced in `target`. You can now use that with codegen:
```
java -cp /path/to/swagger-codegen-cli.jar:/path/to/your.jar org.openapitools.codegen.Codegen -l myClientCodegen -i /path/to/openapi.yaml -o ./test
```
Now your templates are available to the client generator and you can write output values
## But how do I modify this?
The `MyclientcodegenGenerator.java` has comments in it--lots of comments. There is no good substitute
for reading the code more, though. See how the `MyclientcodegenGenerator` implements `CodegenConfig`.
That class has the signature of all values that can be overridden.
For the templates themselves, you have a number of values available to you for generation.
You can execute the `java` command from above while passing different debug flags to show
the object you have available during client generation:
```
# The following additional debug options are available for all codegen targets:
# -DdebugSwagger prints the OpenAPI Specification as interpreted by the codegen
# -DdebugModels prints models passed to the template engine
# -DdebugOperations prints operations passed to the template engine
# -DdebugSupportingFiles prints additional data passed to the template engine
java -DdebugOperations -cp /path/to/swagger-codegen-cli.jar:/path/to/your.jar org.openapitools.codegen.Codegen -l myClientCodegen -i /path/to/swagger.yaml -o ./test
```
Will, for example, output the debug info for operations. You can use this info
in the `api.mustache` file.

View File

@ -0,0 +1,122 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>myClientCodegen-swagger-codegen</artifactId>
<packaging>jar</packaging>
<name>myClientCodegen-swagger-codegen</name>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator</artifactId>
<version>${openapi-generator-version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openapi-generator-version>3.0.0-SNAPSHOT</openapi-generator-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
</project>

View File

@ -0,0 +1,173 @@
package com.my.company.codegen;
import org.openapitools.codegen.*;
import io.swagger.models.properties.*;
import java.util.*;
import java.io.File;
public class MyclientcodegenGenerator extends DefaultCodegen implements CodegenConfig {
// source folder where to write the files
protected String sourceFolder = "src";
protected String apiVersion = "1.0.0";
/**
* Configures the type of generator.
*
* @return the CodegenType for this generator
* @see org.openapitools.codegen.CodegenType
*/
public CodegenType getTag() {
return CodegenType.CLIENT;
}
/**
* Configures a friendly name for the generator. This will be used by the generator
* to select the library with the -l flag.
*
* @return the friendly name for the generator
*/
public String getName() {
return "myClientCodegen";
}
/**
* Returns human-friendly help for the generator. Provide the consumer with help
* tips, parameters here
*
* @return A string value for the help message
*/
public String getHelp() {
return "Generates a myClientCodegen client library.";
}
public MyclientcodegenGenerator() {
super();
// set the output folder here
outputFolder = "generated-code/myClientCodegen";
/**
* Models. You can write model files using the modelTemplateFiles map.
* 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
* a different extension
*/
modelTemplateFiles.put(
"model.mustache", // the template to use
".sample"); // the extension for each file to write
/**
* 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
* class
*/
apiTemplateFiles.put(
"api.mustache", // the template to use
".sample"); // the extension for each file to write
/**
* 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.
*/
templateDir = "myClientCodegen";
/**
* Api Package. Optional, if needed, this can be used in templates
*/
apiPackage = "io.swagger.client.api";
/**
* Model Package. Optional, if needed, this can be used in templates
*/
modelPackage = "io.swagger.client.model";
/**
* Reserved words. Override this with reserved words specific to your language
*/
reservedWords = new HashSet<String> (
Arrays.asList(
"sample1", // replace with static values
"sample2")
);
/**
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
/**
* 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
* it will be processed by the template engine. Otherwise, it will be copied
*/
supportingFiles.add(new SupportingFile("myFile.mustache", // the input template or file
"", // the destination folder, relative `outputFolder`
"myFile.sample") // the output file
);
/**
* Language Specific Primitives. These types will not trigger imports by
* the client generator
*/
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList(
"Type1", // replace these with your types
"Type2")
);
}
/**
* 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 reserved words
*
* @return the escaped term
*/
@Override
public String escapeReservedWord(String 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
* instantiated
*/
public String modelFileFolder() {
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
}
/**
* Location to write api files. You can use the apiPackage() as defined when the class is
* instantiated
*/
@Override
public String apiFileFolder() {
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
}
/**
* override with any special text escaping logic to handle unsafe
* characters so as to avoid code injection
*
* @param input String to be cleaned up
* @return string with unsafe characters removed or escaped
*/
@Override
public String escapeUnsafeCharacters(String input) {
//TODO: check that this logic is safe to escape unsafe characters to avoid code injection
return input;
}
/**
* Escape single and/or double quote to avoid code injection
*
* @param input String to be cleaned up
* @return string with quotation mark removed or escaped
*/
public String escapeQuotationMark(String input) {
//TODO: check that this logic is safe to escape quotation mark to avoid code injection
return input.replace("\"", "\\\"");
}
}

View File

@ -0,0 +1 @@
com.my.company.codegen.MyclientcodegenGenerator

View File

@ -0,0 +1,28 @@
# This is a sample api mustache template. It is representing a ficticous
# language and won't be usable or compile to anything without lots of changes.
# Use it as an example. You can access the variables in the generator object
# like such:
# use the package from the `apiPackage` variable
package: {{package}}
# operations block
{{#operations}}
classname: {{classname}}
# loop over each operation in the API:
{{#operation}}
# each operation has an `operationId`:
operationId: {{operationId}}
# and parameters:
{{#allParams}}
{{paramName}}: {{dataType}}
{{/allParams}}
{{/operation}}
# end of operations block
{{/operations}}

View File

@ -0,0 +1 @@
# This is a sample model mustache template.

View File

@ -0,0 +1 @@
# This is a sample supporting file mustache template.

View File

@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1 @@
3.0.0-SNAPSHOT

View File

@ -0,0 +1 @@
# This is a sample supporting file mustache template.

View File

@ -0,0 +1,76 @@
# This is a sample api mustache template. It is representing a ficticous
# language and won't be usable or compile to anything without lots of changes.
# Use it as an example. You can access the variables in the generator object
# like such:
# use the package from the `apiPackage` variable
package: io.swagger.client.api
# operations block
classname: PetApi
# loop over each operation in the API:
# each operation has an `operationId`:
operationId: addPet
# and parameters:
pet: Pet
# each operation has an `operationId`:
operationId: deletePet
# and parameters:
petId: Long
apiKey: String
# each operation has an `operationId`:
operationId: findPetsByStatus
# and parameters:
status: List
# each operation has an `operationId`:
operationId: findPetsByTags
# and parameters:
tags: List
# each operation has an `operationId`:
operationId: getPetById
# and parameters:
petId: Long
# each operation has an `operationId`:
operationId: updatePet
# and parameters:
pet: Pet
# each operation has an `operationId`:
operationId: updatePetWithForm
# and parameters:
petId: String
name: String
status: String
# each operation has an `operationId`:
operationId: uploadFile
# and parameters:
petId: Long
additionalMetadata: String
file: File
# end of operations block

View File

@ -0,0 +1,42 @@
# This is a sample api mustache template. It is representing a ficticous
# language and won't be usable or compile to anything without lots of changes.
# Use it as an example. You can access the variables in the generator object
# like such:
# use the package from the `apiPackage` variable
package: io.swagger.client.api
# operations block
classname: StoreApi
# loop over each operation in the API:
# each operation has an `operationId`:
operationId: deleteOrder
# and parameters:
orderId: String
# each operation has an `operationId`:
operationId: getInventory
# and parameters:
# each operation has an `operationId`:
operationId: getOrderById
# and parameters:
orderId: String
# each operation has an `operationId`:
operationId: placeOrder
# and parameters:
order: Order
# end of operations block

View File

@ -0,0 +1,72 @@
# This is a sample api mustache template. It is representing a ficticous
# language and won't be usable or compile to anything without lots of changes.
# Use it as an example. You can access the variables in the generator object
# like such:
# use the package from the `apiPackage` variable
package: io.swagger.client.api
# operations block
classname: UserApi
# loop over each operation in the API:
# each operation has an `operationId`:
operationId: createUser
# and parameters:
user: User
# each operation has an `operationId`:
operationId: createUsersWithArrayInput
# and parameters:
user: List
# each operation has an `operationId`:
operationId: createUsersWithListInput
# and parameters:
user: List
# each operation has an `operationId`:
operationId: deleteUser
# and parameters:
username: String
# each operation has an `operationId`:
operationId: getUserByName
# and parameters:
username: String
# each operation has an `operationId`:
operationId: loginUser
# and parameters:
username: String
password: String
# each operation has an `operationId`:
operationId: logoutUser
# and parameters:
# each operation has an `operationId`:
operationId: updateUser
# and parameters:
username: String
user: User
# end of operations block

View File

@ -0,0 +1 @@
# This is a sample model mustache template.

View File

@ -0,0 +1 @@
# This is a sample model mustache template.

View File

@ -0,0 +1 @@
# This is a sample model mustache template.

View File

@ -0,0 +1 @@
# This is a sample model mustache template.

View File

@ -0,0 +1 @@
# This is a sample model mustache template.