Merge remote-tracking branch 'origin/3.2.x' into 4.0.x

This commit is contained in:
Jeremie Bresson 2018-07-18 12:32:55 +02:00
commit eb09731a65
255 changed files with 8075 additions and 1622 deletions

3
.gitignore vendored
View File

@ -83,6 +83,9 @@ samples/client/petstore/scala/build/
samples/client/petstore/java/resttemplate/hello.txt
samples/client/petstore/java/retrofit2/hello.txt
samples/client/petstore/java/feign/hello.txt
samples/client/petstore/java/jersey2-java6/project/
samples/client/petstore/java/jersey2-java8/project/
samples/client/petstore/java/jersey2/project/
#PHP
samples/client/petstore/php/OpenAPIToolsClient-php/composer.lock

29
CI/.travis.yml.jdk6 Normal file
View File

@ -0,0 +1,29 @@
dist: trusty
sudo: required
language: java
addons:
apt:
packages:
- openjdk-6-jdk
jdk: openjdk6
cache:
directories:
- $HOME/.m2
- $HOME/.ivy2
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
install:
- jdk_switcher use openjdk6
- java -version
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk version
- sdk install gradle 2.9
- sdk list gradle
- sdk version
- gradle --version
script:
- cd samples/client/petstore/java/jersey2-java6 && gradle test

View File

@ -0,0 +1,122 @@
apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'org.openapitools'
version = '1.0.0'
buildscript {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
dependencies {
provided 'javax.annotation:jsr250-api:1.0'
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
install {
repositories.mavenInstaller {
pom.artifactId = 'petstore-jersey2-java6'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
swagger_annotations_version = "1.5.20"
jackson_version = "2.9.6"
jersey_version = "2.6"
commons_io_version=2.5
commons_lang3_version=3.6
junit_version = "4.12"
threetenbp_version = "2.6.4"
}
dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
compile "org.glassfish.jersey.media:jersey-media-json-jackson:$jersey_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "commons-io:commons-io:$commons_io_version"
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$threetenbp_version"
compile "com.brsanthu:migbase64:2.2"
testCompile "junit:junit:$junit_version"
}

View File

@ -87,7 +87,8 @@ OpenAPI Generator Version | Release Date | OpenAPI Spec compatibility | Notes
---------------------------- | ------------ | -------------------------- | -----
4.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes (no fallback)
3.2.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.2.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
3.1.1 (current master, upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.1.1-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
3.1.2-SNAPSHOT (current master, upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.1.2-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
[3.1.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.1) | 18.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
[3.1.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.0) | 06.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
[3.0.3](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.3) | 27.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
[3.0.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.2) | 18.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
@ -144,16 +145,16 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.0/openapi-generator-cli-3.1.0.jar`
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.1/openapi-generator-cli-3.1.1.jar`
For **Mac/Linux** users:
```sh
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.0/openapi-generator-cli-3.1.0.jar -O openapi-generator-cli.jar
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.1/openapi-generator-cli-3.1.1.jar -O openapi-generator-cli.jar
```
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
```
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.0/openapi-generator-cli-3.1.0.jar
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.1/openapi-generator-cli-3.1.1.jar
```
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
@ -585,7 +586,7 @@ If you want to join the committee, please kindly apply by sending an email to te
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
| ObjC | |
| Perl | @wing328 (2017/07) |
| PHP | @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09) |
| PHP | @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09) @ybelenko (2018/07) |
| PowerShell | |
| Python | @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11)|
| R | |

View File

@ -18,6 +18,7 @@ install:
- cmd: SET MAVEN_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: SET M2_HOME=C:\maven\apache-maven-3.2.5
- cmd: java -version
- cmd: dir/w
- git clone https://github.com/wing328/swagger-samples
- ps: Start-Process -FilePath 'C:\maven\apache-maven-3.2.5\bin\mvn' -ArgumentList 'jetty:run' -WorkingDirectory "$env:appveyor_build_folder\swagger-samples\java\java-jersey-jaxrs-ci"

View File

@ -32,4 +32,8 @@ ags="generate --artifact-id petstore-jersey2-java6 -i modules/openapi-generator/
echo "Removing files and folders under samples/client/petstore/java/jersey2-java6/src/main"
rm -rf samples/client/petstore/java/jersey2-java6/src/main
find samples/client/petstore/java/jersey2-java6 -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
echo "Restoring build.gradle ... "
cp CI/samples.ci/client/petstore/java/jersey2-java6/build.gradle samples/client/petstore/java/jersey2-java6/
java $JAVA_OPTS -jar $executable $ags

View File

@ -22,7 +22,7 @@ sleep 5
./bin/php-silex-petstore-server.sh > /dev/null 2>&1
./bin/php-symfony-petstore.sh > /dev/null 2>&1
./bin/php-lumen-petstore-server.sh > /dev/null 2>&1
./bin/php-slim-petstore-server.sh > /dev/null 2>&1
./bin/php-slim-server-petstore.sh > /dev/null 2>&1
./bin/php-ze-ph-petstore-server.sh > /dev/null 2>&1
./bin/openapi3/php-petstore.sh > /dev/null 2>&1
./bin/typescript-angular-petstore-all.sh > /dev/null 2>&1

0
bin/windows/typescript-node-petstore-with-npm.bat Normal file → Executable file
View File

0
bin/windows/typescript-node-petstore.bat Normal file → Executable file
View File

View File

@ -246,8 +246,8 @@ If your API client is using named parameters in the function call (e.g. Perl req
The following gnereators are not yet fully migrated and tested
- `rust-server`
- `apex`
- ~~rust-server~~ (migrated)
- `apex` (migration scheduled in Jul/Aug 2018)
and we welcome contributions from the community to help with the migration

View File

@ -11,6 +11,20 @@ Another approach to find breaking changes is to look at issue and pull requests
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28with%20fallback%29[Breaking change (with fallback)]
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28without%20fallback%29[Breaking change (without fallback)]
=== From 3.1.x to 3.2.0
Version `3.2.0` is a minor version of OpenAPI-Generator, in comparison to `3.1.x` it contains some breaking changes, but with the possibility to fallback to the old behavior.
The default value of some options might change.
Projects relying on generated code might need to be adapted.
==== Model (all languages)
In `CodegenModel` and in `CodegenOperation` we use now our own class `org.openapitools.codegen.CodegenDiscriminator` instead of `io.swagger.v3.oas.models.media.Discriminator`.
For the templates, this is not an API change, because the same values are available.
If you have your own `Codegen` class (to support your own generator for example) then you might get some compile error due to the change.
=== From 3.0.x to 3.1.0
Version `3.1.0` is the first minor version of OpenAPI-Generator, in comparison to `3.0.3` it contains some breaking changes, but with the possibility to fallback to the old behavior.

View File

@ -34,7 +34,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:3.1.0"
classpath "org.openapitools:openapi-generator-gradle-plugin:3.1.1"
}
}

View File

@ -16,5 +16,5 @@ gradle buildGoSdk
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
```bash
gradle -PopenApiGeneratorVersion=3.1.0 openApiValidate
gradle -PopenApiGeneratorVersion=3.1.1 openApiValidate
```

View File

@ -1 +1 @@
openApiGeneratorVersion=3.1.0
openApiGeneratorVersion=3.1.1

View File

@ -11,7 +11,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<executions>
<execution>
<goals>

View File

@ -213,6 +213,9 @@ public class CodegenConstants {
public static final String EXCLUDE_TESTS = "excludeTests";
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";
public static final String SOURCECODEONLY_GENERATION = "generateSourceCodeOnly";
public static final String SOURCECODEONLY_GENERATION_DESC = "Specifies that only a library source code is to be generated.";
// Not user-configurable. System provided for use in templates.
public static final String GENERATE_APIS = "generateApis";

View File

@ -0,0 +1,88 @@
package org.openapitools.codegen;
import java.util.*;
public class CodegenDiscriminator {
private String propertyName;
private Map<String, String> mapping;
private Set<MappedModel> mappedModels = new LinkedHashSet<>();
public String getPropertyName() {
return propertyName;
}
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
public Map<String, String> getMapping() {
return mapping;
}
public void setMapping(Map<String, String> mapping) {
this.mapping = mapping;
}
public Set<MappedModel> getMappedModels() {
return mappedModels;
}
public void setMappedModels(Set<MappedModel> mappedModels) {
this.mappedModels = mappedModels;
}
public static class MappedModel {
private String mappingName;
private String modelName;
public MappedModel(String mappingName, String modelName) {
this.mappingName = mappingName;
this.modelName = modelName;
}
public String getMappingName() {
return mappingName;
}
public void setMappingName(String mappingName) {
this.mappingName = mappingName;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MappedModel that = (MappedModel) o;
return Objects.equals(mappingName, that.mappingName) &&
Objects.equals(modelName, that.modelName);
}
@Override
public int hashCode() {
return Objects.hash(mappingName, modelName);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CodegenDiscriminator that = (CodegenDiscriminator) o;
return Objects.equals(propertyName, that.propertyName) &&
Objects.equals(mapping, that.mapping) &&
Objects.equals(mappedModels, that.mappedModels);
}
@Override
public int hashCode() {
return Objects.hash(propertyName, mapping, mappedModels);
}
}

View File

@ -18,15 +18,14 @@
package org.openapitools.codegen;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.media.Discriminator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.Objects;
public class CodegenModel {
public String parent, parentSchema;
@ -40,7 +39,7 @@ public class CodegenModel {
public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName;
public String classFilename; // store the class file name, mainly used for import
public String unescapedDescription;
public Discriminator discriminator;
public CodegenDiscriminator discriminator;
public String defaultValue;
public String arrayModelType;
public boolean isAlias; // Is this effectively an alias of another simple type
@ -349,7 +348,7 @@ public class CodegenModel {
this.unescapedDescription = unescapedDescription;
}
public Discriminator getDiscriminator() {
public CodegenDiscriminator getDiscriminator() {
return discriminator;
}
@ -357,7 +356,7 @@ public class CodegenModel {
return discriminator == null ? null : discriminator.getPropertyName();
}
public void setDiscriminator(Discriminator discriminator) {
public void setDiscriminator(CodegenDiscriminator discriminator) {
this.discriminator = discriminator;
}

View File

@ -18,17 +18,15 @@
package org.openapitools.codegen;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.media.Discriminator;
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.tags.Tag;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Arrays;
public class CodegenOperation {
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
@ -40,7 +38,7 @@ public class CodegenOperation {
isRestful, isDeprecated;
public String path, operationId, returnType, httpMethod, returnBaseType,
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
public Discriminator discriminator;
public CodegenDiscriminator discriminator;
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
public CodegenParameter bodyParam;
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();

View File

@ -26,7 +26,12 @@ import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.ComposedSchema;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.CookieParameter;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
import io.swagger.v3.oas.models.parameters.Parameter;
@ -43,6 +48,7 @@ import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
import org.openapitools.codegen.examples.ExampleGenerator;
import org.openapitools.codegen.serializer.SerializerUtils;
import org.openapitools.codegen.utils.ModelUtils;
@ -66,6 +72,7 @@ import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
@ -1110,7 +1117,7 @@ public class DefaultCodegen implements CodegenConfig {
* Return the example value of the parameter.
*
* @param codegenParameter Codegen parameter
* @param parameter Parameter
* @param parameter Parameter
*/
public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) {
if (parameter.getExample() != null) {
@ -1120,7 +1127,7 @@ public class DefaultCodegen implements CodegenConfig {
if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) {
Example example = parameter.getExamples().values().iterator().next();
if(example.getValue() != null) {
if (example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
return;
}
@ -1139,7 +1146,7 @@ public class DefaultCodegen implements CodegenConfig {
* Return the example value of the parameter.
*
* @param codegenParameter Codegen parameter
* @param requestBody Request body
* @param requestBody Request body
*/
public void setParameterExampleValue(CodegenParameter codegenParameter, RequestBody requestBody) {
Content content = requestBody.getContent();
@ -1157,7 +1164,7 @@ public class DefaultCodegen implements CodegenConfig {
if (mediaType.getExamples() != null && !mediaType.getExamples().isEmpty()) {
Example example = mediaType.getExamples().values().iterator().next();
if(example.getValue() != null) {
if (example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
return;
}
@ -1469,6 +1476,10 @@ public class DefaultCodegen implements CodegenConfig {
// unalias schema
schema = ModelUtils.unaliasSchema(allDefinitions, schema);
if (schema == null) {
LOGGER.warn("Schema {} not found", name);
return null;
}
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
@ -1489,7 +1500,7 @@ public class DefaultCodegen implements CodegenConfig {
m.getVendorExtensions().putAll(schema.getExtensions());
}
m.isAlias = typeAliases.containsKey(name);
m.discriminator = schema.getDiscriminator();
m.discriminator = createDiscriminator(name, schema, allDefinitions);
if (schema.getXml() != null) {
m.xmlPrefix = schema.getXml().getPrefix();
@ -1516,7 +1527,7 @@ public class DefaultCodegen implements CodegenConfig {
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
for (Schema innerModel : composed.getAllOf()) {
if (m.discriminator == null) {
m.discriminator = schema.getDiscriminator();
m.discriminator = createDiscriminator(name, schema, allDefinitions);
}
if (innerModel.getXml() != null) {
m.xmlPrefix = innerModel.getXml().getPrefix();
@ -1614,7 +1625,7 @@ public class DefaultCodegen implements CodegenConfig {
m.isInteger = Boolean.TRUE;
}
}
if (ModelUtils.isStringSchema(schema)){
if (ModelUtils.isStringSchema(schema)) {
m.isString = Boolean.TRUE;
}
@ -1631,6 +1642,34 @@ public class DefaultCodegen implements CodegenConfig {
return m;
}
private CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, Map<String, Schema> allDefinitions) {
if(schema.getDiscriminator() == null) {
return null;
}
CodegenDiscriminator discriminator = new CodegenDiscriminator();
discriminator.setPropertyName(schema.getDiscriminator().getPropertyName());
discriminator.setMapping(schema.getDiscriminator().getMapping());
if(schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
String name = ModelUtils.getSimpleRef(e.getValue());
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
}
} else {
allDefinitions.forEach((childName, child) -> {
if (child instanceof ComposedSchema && ((ComposedSchema) child).getAllOf() != null) {
Set<String> parentSchemas = ((ComposedSchema) child).getAllOf().stream()
.filter(s -> s.get$ref() != null)
.map(s -> ModelUtils.getSimpleRef(s.get$ref()))
.collect(Collectors.toSet());
if (parentSchemas.contains(schemaName)) {
discriminator.getMappedModels().add(new MappedModel(childName, childName));
}
}
});
}
return discriminator;
}
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
addParentContainer(codegenModel, codegenModel.name, schema);
}
@ -4373,15 +4412,32 @@ public class DefaultCodegen implements CodegenConfig {
if (schema.getAdditionalProperties() != null) {// http body is map
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
} else if (codegenProperty != null) {
String codegenModelName, codegenModelDescription;
if (codegenModel != null) {
codegenModelName = codegenModel.classname;
codegenModelDescription = codegenModel.description;
} else {
LOGGER.warn("The following schema has undefined (null) baseType. " +
"It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. " +
"A correct 'consumes' for form parameters should be " +
"'application/x-www-form-urlencoded' or 'multipart/form-data'");
LOGGER.warn("schema: " + schema);
LOGGER.warn("codegenModel is null. Default to UNKNOWN_BASE_TYPE");
codegenModelName = "UNKNOWN_BASE_TYPE";
codegenModelDescription = "UNKNOWN_DESCRIPTION";
}
if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = codegenModel.classname;
codegenParameter.baseName = codegenModelName;
} else {
codegenParameter.baseName = bodyParameterName;
}
codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.baseType = codegenModel.classname;
codegenParameter.dataType = getTypeDeclaration(codegenModel.classname);
codegenParameter.description = codegenModel.description;
codegenParameter.baseType = codegenModelName;
codegenParameter.dataType = getTypeDeclaration(codegenModelName);
codegenParameter.description = codegenModelDescription;
imports.add(codegenParameter.baseType);
if (codegenProperty.complexType != null) {
@ -4465,6 +4521,6 @@ public class DefaultCodegen implements CodegenConfig {
}
public boolean isDataTypeString(String dataType) {
return "String".equals(dataType);
return "String".equals(dataType);
}
}

View File

@ -127,6 +127,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
typeMapping.put("string", "string");
typeMapping.put("byte", "int");
typeMapping.put("boolean", "bool");
typeMapping.put("date", "\\DateTime");
typeMapping.put("Date", "\\DateTime");
typeMapping.put("DateTime", "\\DateTime");
typeMapping.put("file", "\\SplFileObject");
@ -170,17 +171,25 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
// Update the invokerPackage for the default apiPackage and modelPackage
apiPackage = invokerPackage + "\\" + apiDirName;
modelPackage = invokerPackage + "\\" + modelDirName;
} else {
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
}
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
// Update model package to contain the specified model package name and the invoker package
modelPackage = invokerPackage + "\\" + (String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE);
}
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
// Update api package to contain the specified api package name and the invoker package
apiPackage = invokerPackage + "\\" + (String) additionalProperties.get(CodegenConstants.API_PACKAGE);
}
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
// if (additionalProperties.containsKey(COMPOSER_PROJECT_NAME)) {
// this.setComposerProjectName((String) additionalProperties.get(COMPOSER_PROJECT_NAME));
@ -329,7 +338,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
} else if (StringUtils.isNotBlank(p.get$ref())) { // model
String type = super.getTypeDeclaration(p);
return (!languageSpecificPrimitives.contains(type))
? "\\" + modelPackage + "\\" + type : type;
@ -542,11 +551,11 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
type = p.dataType;
}
if ("String".equalsIgnoreCase(type)) {
if ("String".equalsIgnoreCase(type) || p.isString) {
if (example == null) {
example = p.paramName + "_example";
example = "'" + p.paramName + "_example'";
}
example = "\"" + escapeText(example) + "\"";
example = escapeText(example);
} else if ("Integer".equals(type) || "int".equals(type)) {
if (example == null) {
example = "56";
@ -559,21 +568,23 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
if (example == null) {
example = "True";
}
} else if ("\\SplFileObject".equalsIgnoreCase(type)) {
} else if ("\\SplFileObject".equalsIgnoreCase(type) || p.isFile) {
if (example == null) {
example = "/path/to/file";
example = "/path/to/file.txt";
}
example = "\"" + escapeText(example) + "\"";
} else if ("Date".equalsIgnoreCase(type)) {
} else if ("\\Date".equalsIgnoreCase(type)) {
if (example == null) {
example = "2013-10-20";
}
example = "new \\DateTime(\"" + escapeText(example) + "\")";
} else if ("DateTime".equalsIgnoreCase(type)) {
} else if ("\\DateTime".equalsIgnoreCase(type)) {
if (example == null) {
example = "2013-10-20T19:20:30+01:00";
}
example = "new \\DateTime(\"" + escapeText(example) + "\")";
} else if ("object".equals(type)) {
example = "new \\stdClass";
} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
example = "new " + getTypeDeclaration(type) + "()";
@ -631,8 +642,8 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
enumName = enumName.replaceFirst("^_", "");
enumName = enumName.replaceFirst("_$", "");
if (enumName.matches("\\d.*")) { // starts with number
return "_" + enumName;
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
return escapeReservedWord(enumName);
} else {
return enumName;
}
@ -642,6 +653,9 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
public String toEnumName(CodegenProperty property) {
String enumName = underscore(toModelName(property.name)).toUpperCase();
// remove [] for array or map of enum
enumName = enumName.replace("[]", "");
if (enumName.matches("\\d.*")) { // starts with number
return "_" + enumName;
} else {
@ -660,6 +674,8 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation op : operationList) {
// for API test method name
// e.g. public function test{{vendorExtensions.x-testOperationId}}()
op.vendorExtensions.put("x-testOperationId", camelize(op.operationId));
}
return objs;
@ -673,7 +689,17 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "");
return input.replace("*/", "*_/").replace("/*", "/_*");
}
@Override
public String escapeText(String input) {
if (input == null) {
return input;
}
// Trim the string to avoid leading and trailing spaces.
return super.escapeText(input).trim();
}
protected String extractSimpleName(String phpClassName) {

View File

@ -0,0 +1,162 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* Copyright 2018 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRubyCodegen.class);
AbstractRubyCodegen() {
super();
setReservedWordsLowerCase(
Arrays.asList(
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
"else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif",
"if", "not", "return", "undef", "yield")
);
languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("String");
languageSpecificPrimitives.add("Integer");
languageSpecificPrimitives.add("Float");
languageSpecificPrimitives.add("Date");
languageSpecificPrimitives.add("DateTime");
languageSpecificPrimitives.add("Array");
languageSpecificPrimitives.add("Hash");
languageSpecificPrimitives.add("File");
languageSpecificPrimitives.add("Object");
typeMapping.clear();
typeMapping.put("string", "String");
typeMapping.put("char", "String");
typeMapping.put("int", "Integer");
typeMapping.put("integer", "Integer");
typeMapping.put("long", "Integer");
typeMapping.put("short", "Integer");
typeMapping.put("float", "Float");
typeMapping.put("double", "Float");
typeMapping.put("number", "Float");
typeMapping.put("date", "Date");
typeMapping.put("DateTime", "DateTime");
typeMapping.put("array", "Array");
typeMapping.put("List", "Array");
typeMapping.put("map", "Hash");
typeMapping.put("object", "Object");
typeMapping.put("file", "File");
typeMapping.put("binary", "String");
typeMapping.put("ByteArray", "String");
typeMapping.put("UUID", "String");
}
@Override
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "_" + name;
}
@Override
public String getTypeDeclaration(Schema schema) {
if (ModelUtils.isArraySchema(schema)) {
Schema inner = ((ArraySchema) schema).getItems();
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isMapSchema(schema)) {
Schema inner = (Schema) schema.getAdditionalProperties();
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
}
return super.getTypeDeclaration(schema);
}
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
return "'" + escapeText((String) p.getDefault()) + "'";
}
}
return null;
}
@Override
public String toVarName(String name) {
// sanitize name
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// if it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) {
name = name.toLowerCase();
}
// camelize (lower first character) the variable name
// petId => pet_id
name = underscore(name);
// for reserved word or word starting with number, append _
if (isReservedWord(name) || name.matches("^\\d.*")) {
name = escapeReservedWord(name);
}
return name;
}
@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
}
@Override
public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
String newOperationId = underscore("call_" + operationId);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}
return underscore(operationId);
}
@Override
public String escapeQuotationMark(String input) {
// remove ' to avoid code injection
return input.replace("'", "");
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}
}

View File

@ -300,7 +300,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isStringSchema(p)
|| ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)
|| ModelUtils.isFileSchema(p)
|| ModelUtils.isFileSchema(p) || ModelUtils.isUUIDSchema(p)
|| languageSpecificPrimitives.contains(openAPIType)) {
return toModelName(openAPIType);
}

View File

@ -523,25 +523,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
}
}
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
Map<String, Object> allProcessedModels = super.postProcessAllModels(objs);
if (!additionalProperties.containsKey("gsonFactoryMethod")) {
List<Object> allModels = new ArrayList<Object>();
for (String name : allProcessedModels.keySet()) {
Map<String, Object> models = (Map<String, Object>) allProcessedModels.get(name);
try {
allModels.add(((List<Object>) models.get("models")).get(0));
} catch (Exception e) {
e.printStackTrace();
}
}
additionalProperties.put("parent", modelInheritanceSupportInGson(allModels));
}
return allProcessedModels;
}
@Override
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
objs = super.postProcessModelsEnum(objs);
@ -564,34 +545,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
return objs;
}
public static List<Map<String, Object>> modelInheritanceSupportInGson(List<?> allModels) {
Map<CodegenModel, List<CodegenModel>> byParent = new LinkedHashMap<>();
for (Object model : allModels) {
Map entry = (Map) model;
CodegenModel parent = ((CodegenModel)entry.get("model")).parentModel;
if(null!= parent) {
byParent.computeIfAbsent(parent, k -> new LinkedList<>()).add((CodegenModel)entry.get("model"));
}
}
List<Map<String, Object>> parentsList = new ArrayList<>();
for (CodegenModel parentModel : byParent.keySet()) {
List<Map<String, Object>> childrenList = new ArrayList<>();
Map<String, Object> parent = new HashMap<>();
parent.put("classname", parentModel.classname);
List<CodegenModel> childrenModels = byParent.get(parentModel);
for (CodegenModel model : childrenModels) {
Map<String, Object> child = new HashMap<>();
child.put("name", model.name);
child.put("classname", model.classname);
childrenList.add(child);
}
parent.put("children", childrenList);
parent.put("discriminator", parentModel.discriminator);
parentsList.add(parent);
}
return parentsList;
}
public void setUseRxJava(boolean useRxJava) {
this.useRxJava = useRxJava;
doNotUseRx = false;

View File

@ -18,57 +18,28 @@
package org.openapitools.codegen.languages;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import java.io.File;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashSet;
import java.util.regex.Matcher;
import org.apache.commons.lang3.StringUtils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public class PhpClientCodegen extends AbstractPhpCodegen {
@SuppressWarnings("hiding")
private static final Logger LOGGER = LoggerFactory.getLogger(PhpClientCodegen.class);
public static final String VARIABLE_NAMING_CONVENTION = "variableNamingConvention";
public static final String PACKAGE_PATH = "packagePath";
public static final String SRC_BASE_PATH = "srcBasePath";
public static final String COMPOSER_VENDOR_NAME = "composerVendorName";
public static final String COMPOSER_PROJECT_NAME = "composerProjectName";
protected String invokerPackage = "OpenAPI\\Client";
protected String composerVendorName = null;
protected String composerProjectName = null;
protected String packagePath = "OpenAPIClient-php";
protected String artifactVersion = null;
protected String srcBasePath = "lib";
protected String testBasePath = "test";
protected String docsBasePath = "docs";
protected String apiDirName = "Api";
protected String modelDirName = "Model";
protected String variableNamingConvention = "snake_case";
protected String apiDocPath = docsBasePath + "/" + apiDirName;
protected String modelDocPath = docsBasePath + "/" + modelDirName;
public PhpClientCodegen() {
super();
@ -77,144 +48,30 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
// at the moment
importMapping.clear();
setInvokerPackage("OpenAPI\\Client");
setApiPackage(getInvokerPackage() + "\\" + apiDirName);
setModelPackage(getInvokerPackage() + "\\" + modelDirName);
setPackagePath("OpenAPIClient-php");
supportsInheritance = true;
outputFolder = "generated-code" + File.separator + "php";
modelTemplateFiles.put("model.mustache", ".php");
apiTemplateFiles.put("api.mustache", ".php");
setOutputDir("generated-code" + File.separator + "php");
modelTestTemplateFiles.put("model_test.mustache", ".php");
apiTestTemplateFiles.put("api_test.mustache", ".php");
embeddedTemplateDir = templateDir = "php";
apiPackage = invokerPackage + "\\" + apiDirName;
modelPackage = invokerPackage + "\\" + modelDirName;
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
// default HIDE_GENERATION_TIMESTAMP to true
hideGenerationTimestamp = Boolean.TRUE;
setReservedWordsLowerCase(
Arrays.asList(
// local variables used in api methods (endpoints)
"resourcePath", "httpBody", "queryParams", "headerParams",
"formParams", "_header_accept", "_tempBody",
// PHP reserved words
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
);
// ref: http://php.net/manual/en/language.types.intro.php
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList(
"bool",
"boolean",
"int",
"integer",
"double",
"float",
"string",
"object",
"DateTime",
"mixed",
"number",
"void",
"byte")
);
instantiationTypes.put("array", "array");
instantiationTypes.put("map", "map");
// provide primitives to mustache template
List sortedLanguageSpecificPrimitives = new ArrayList(languageSpecificPrimitives);
Collections.sort(sortedLanguageSpecificPrimitives);
String primitives = "'" + StringUtils.join(sortedLanguageSpecificPrimitives, "', '") + "'";
additionalProperties.put("primitives", primitives);
// ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
typeMapping = new HashMap<String, String>();
typeMapping.put("integer", "int");
typeMapping.put("long", "int");
typeMapping.put("number", "float");
typeMapping.put("float", "float");
typeMapping.put("double", "double");
typeMapping.put("string", "string");
typeMapping.put("byte", "int");
typeMapping.put("boolean", "bool");
typeMapping.put("date", "\\DateTime");
typeMapping.put("Date", "\\DateTime");
typeMapping.put("DateTime", "\\DateTime");
typeMapping.put("file", "\\SplFileObject");
typeMapping.put("map", "map");
typeMapping.put("array", "array");
typeMapping.put("list", "array");
typeMapping.put("object", "object");
typeMapping.put("binary", "\\SplFileObject");
typeMapping.put("ByteArray", "string");
typeMapping.put("UUID", "string");
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
cliOptions.add(new CliOption(VARIABLE_NAMING_CONVENTION, "naming convention of variable name, e.g. camelCase.")
.defaultValue("snake_case"));
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, "The main namespace to use for all classes. e.g. Yay\\Pets"));
cliOptions.add(new CliOption(PACKAGE_PATH, "The main package name for classes. e.g. GeneratedPetstore"));
cliOptions.add(new CliOption(SRC_BASE_PATH, "The directory under packagePath to serve as source root."));
cliOptions.add(new CliOption(COMPOSER_VENDOR_NAME, "The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. yaypets. IMPORTANT NOTE (2016/03): composerVendorName will be deprecated and replaced by gitUserId in the next openapi-generator release"));
cliOptions.add(new CliOption(CodegenConstants.GIT_USER_ID, CodegenConstants.GIT_USER_ID_DESC));
cliOptions.add(new CliOption(COMPOSER_PROJECT_NAME, "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client. IMPORTANT NOTE (2016/03): composerProjectName will be deprecated and replaced by gitRepoId in the next openapi-generator release"));
cliOptions.add(new CliOption(CodegenConstants.GIT_REPO_ID, CodegenConstants.GIT_REPO_ID_DESC));
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "The version to use in the composer package version field. e.g. 1.2.3"));
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.ALLOW_UNICODE_IDENTIFIERS_DESC)
.defaultValue(Boolean.TRUE.toString()));
}
public String getPackagePath() {
return packagePath;
}
public String toPackagePath(String packageName, String basePath) {
return (getPackagePath() + File.separatorChar + toSrcPath(packageName, basePath));
}
public String toSrcPath(String packageName, String basePath) {
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (basePath != null && basePath.length() > 0) {
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
}
String regFirstPathSeparator;
if ("/".equals(File.separator)) { // for mac, linux
regFirstPathSeparator = "^/";
} else { // for windows
regFirstPathSeparator = "^\\\\";
}
String regLastPathSeparator;
if ("/".equals(File.separator)) { // for mac, linux
regLastPathSeparator = "/$";
} else { // for windows
regLastPathSeparator = "\\\\$";
}
return (basePath
// Replace period, backslash, forward slash with file separator in package name
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
// Trim prefix file separators from package path
.replaceAll(regFirstPathSeparator, ""))
// Trim trailing file separators from the overall path
.replaceAll(regLastPathSeparator + "$", "");
}
@Override
public String escapeText(String input) {
if (input != null) {
// Trim the string to avoid leading and trailing spaces.
return super.escapeText(input).trim();
}
return input;
}
@Override
public CodegenType getTag() {
return CodegenType.CLIENT;
@ -234,89 +91,18 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(PACKAGE_PATH)) {
this.setPackagePath((String) additionalProperties.get(PACKAGE_PATH));
} else {
additionalProperties.put(PACKAGE_PATH, packagePath);
}
if (additionalProperties.containsKey(SRC_BASE_PATH)) {
this.setSrcBasePath((String) additionalProperties.get(SRC_BASE_PATH));
} else {
additionalProperties.put(SRC_BASE_PATH, srcBasePath);
}
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
// Update the invokerPackage for the default apiPackage and modelPackage
apiPackage = invokerPackage + "\\" + apiDirName;
modelPackage = invokerPackage + "\\" + modelDirName;
} else {
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
}
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
// Update model package to contain the specified model package name and the invoker package
modelPackage = invokerPackage + "\\" + (String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE);
}
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
// Update model package to contain the specified model package name and the invoker package
apiPackage = invokerPackage + "\\" + (String) additionalProperties.get(CodegenConstants.API_PACKAGE);
}
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
if (additionalProperties.containsKey(COMPOSER_PROJECT_NAME)) {
this.setComposerProjectName((String) additionalProperties.get(COMPOSER_PROJECT_NAME));
} else {
additionalProperties.put(COMPOSER_PROJECT_NAME, composerProjectName);
}
if (additionalProperties.containsKey(CodegenConstants.GIT_USER_ID)) {
this.setGitUserId((String) additionalProperties.get(CodegenConstants.GIT_USER_ID));
} else {
additionalProperties.put(CodegenConstants.GIT_USER_ID, gitUserId);
}
if (additionalProperties.containsKey(COMPOSER_VENDOR_NAME)) {
this.setComposerVendorName((String) additionalProperties.get(COMPOSER_VENDOR_NAME));
} else {
additionalProperties.put(COMPOSER_VENDOR_NAME, composerVendorName);
}
if (additionalProperties.containsKey(CodegenConstants.GIT_REPO_ID)) {
this.setGitRepoId((String) additionalProperties.get(CodegenConstants.GIT_REPO_ID));
} else {
additionalProperties.put(CodegenConstants.GIT_REPO_ID, gitRepoId);
}
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
} else {
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
}
if (additionalProperties.containsKey(VARIABLE_NAMING_CONVENTION)) {
this.setParameterNamingConvention((String) additionalProperties.get(VARIABLE_NAMING_CONVENTION));
}
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
// make api and model src path available in mustache template
additionalProperties.put("apiSrcPath", "./" + toSrcPath(apiPackage, srcBasePath));
additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage, srcBasePath));
additionalProperties.put("apiTestPath", "./" + testBasePath + "/" + apiDirName);
additionalProperties.put("modelTestPath", "./" + testBasePath + "/" + modelDirName);
// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
// make test path available in mustache template
additionalProperties.put("testBasePath", testBasePath);
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiException.php"));
supportingFiles.add(new SupportingFile("Configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toPackagePath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
@ -330,124 +116,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("git_push.sh.mustache", getPackagePath(), "git_push.sh"));
}
@Override
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "_" + name;
}
@Override
public String apiFileFolder() {
return (outputFolder + "/" + toPackagePath(apiPackage, srcBasePath));
}
@Override
public String modelFileFolder() {
return (outputFolder + "/" + toPackagePath(modelPackage, srcBasePath));
}
@Override
public String apiTestFileFolder() {
return (outputFolder + "/" + getPackagePath() + "/" + testBasePath + "/" + apiDirName);
}
@Override
public String modelTestFileFolder() {
return (outputFolder + "/" + getPackagePath() + "/" + testBasePath + "/" + modelDirName);
}
@Override
public String apiDocFileFolder() {
return (outputFolder + "/" + getPackagePath() + "/" + apiDocPath);
}
@Override
public String modelDocFileFolder() {
return (outputFolder + "/" + getPackagePath() + "/" + modelDocPath);
}
@Override
public String toModelDocFilename(String name) {
return toModelName(name);
}
@Override
public String toApiDocFilename(String name) {
return toApiName(name);
}
@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getTypeDeclaration(inner) + "[]";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
} else if (StringUtils.isNotBlank(p.get$ref())) {
String type = super.getTypeDeclaration(p);
return (!languageSpecificPrimitives.contains(type))
? "\\" + modelPackage + "\\" + type : type;
}
return super.getTypeDeclaration(p);
}
@Override
public String getTypeDeclaration(String name) {
if (!languageSpecificPrimitives.contains(name)) {
return "\\" + modelPackage + "\\" + name;
}
return super.getTypeDeclaration(name);
}
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
String type = null;
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type)) {
return type;
} else if (instantiationTypes.containsKey(type)) {
return type;
}
} else {
type = openAPIType;
}
if (type == null) {
return null;
}
return toModelName(type);
}
public String getInvokerPackage() {
return invokerPackage;
}
public void setInvokerPackage(String invokerPackage) {
this.invokerPackage = invokerPackage;
}
public void setArtifactVersion(String artifactVersion) {
this.artifactVersion = artifactVersion;
}
public void setPackagePath(String packagePath) {
this.packagePath = packagePath;
}
public void setSrcBasePath(String srcBasePath) {
this.srcBasePath = srcBasePath;
}
public void setParameterNamingConvention(String variableNamingConvention) {
this.variableNamingConvention = variableNamingConvention;
}
public void setComposerVendorName(String composerVendorName) {
this.composerVendorName = composerVendorName;
}
@ -455,291 +123,4 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public void setComposerProjectName(String composerProjectName) {
this.composerProjectName = composerProjectName;
}
@Override
public String toVarName(String name) {
// sanitize name
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if ("camelCase".equals(variableNamingConvention)) {
// return the name in camelCase style
// phone_number => phoneNumber
name = camelize(name, true);
} else { // default to snake case
// return the name in underscore style
// PhoneNumber => phone_number
name = underscore(name);
}
// parameter name starting with number won't compile
// need to escape it by appending _ at the beginning
if (name.matches("^\\d.*")) {
name = "_" + name;
}
return name;
}
@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
}
@Override
public String toModelName(String name) {
// remove [
name = name.replaceAll("\\]", "");
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
name = name.replaceAll("[^\\w\\\\]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// remove dollar sign
name = name.replaceAll("$", "");
// model name cannot use reserved keyword
if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name));
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
}
// model name starts with number
if (name.matches("^\\d.*")) {
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name));
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
}
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
if (!name.matches("^\\\\.*")) {
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}
if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}
}
// camelize the model name
// phone_number => PhoneNumber
return camelize(name);
}
@Override
public String toModelFilename(String name) {
// should be the same as the model name
return toModelName(name);
}
@Override
public String toModelTestFilename(String name) {
// should be the same as the model name
return toModelName(name) + "Test";
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
operationId = "call_" + operationId;
}
return camelize(sanitizeName(operationId), true);
}
/**
* Return the default value of the property
*
* @param p property schema
* @return string presentation of the default value of the property
*/
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isDateSchema(p)) {
// TODO
} else if (ModelUtils.isDateTimeSchema(p)) {
// TODO
} else if (ModelUtils.isNumberSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isIntegerSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
return "'" + p.getDefault() + "'";
}
}
return null;
}
@Override
public void setParameterExampleValue(CodegenParameter p) {
String example;
if (p.defaultValue == null) {
example = p.example;
} else {
example = p.defaultValue;
}
String type = p.baseType;
if (type == null) {
type = p.dataType;
}
if ("String".equalsIgnoreCase(type) || p.isString) {
if (example == null) {
example = "'" + p.paramName + "_example'";
}
example = escapeText(example);
} else if ("Integer".equals(type) || "int".equals(type)) {
if (example == null) {
example = "56";
}
} else if ("Float".equalsIgnoreCase(type) || "Double".equalsIgnoreCase(type)) {
if (example == null) {
example = "3.4";
}
} else if ("BOOLEAN".equalsIgnoreCase(type) || "bool".equalsIgnoreCase(type)) {
if (example == null) {
example = "True";
}
} else if ("\\SplFileObject".equalsIgnoreCase(type) || p.isFile) {
if (example == null) {
example = "/path/to/file.txt";
}
example = "\"" + escapeText(example) + "\"";
} else if ("\\Date".equalsIgnoreCase(type)) {
if (example == null) {
example = "2013-10-20";
}
example = "new \\DateTime(\"" + escapeText(example) + "\")";
} else if ("\\DateTime".equalsIgnoreCase(type)) {
if (example == null) {
example = "2013-10-20T19:20:30+01:00";
}
example = "new \\DateTime(\"" + escapeText(example) + "\")";
} else if ("object".equals(type)) {
example = "new \\stdClass";
} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
example = "new " + getTypeDeclaration(type) + "()";
} else {
LOGGER.warn("Type " + type + " not handled properly in setParameterExampleValue");
}
if (example == null) {
example = "NULL";
} else if (Boolean.TRUE.equals(p.isListContainer)) {
example = "array(" + example + ")";
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
example = "array('key' => " + example + ")";
}
p.example = example;
}
@Override
public String toEnumValue(String value, String datatype) {
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
return value;
} else {
return "\'" + escapeText(value) + "\'";
}
}
@Override
public String toEnumDefaultValue(String value, String datatype) {
return datatype + "_" + value;
}
@Override
public String toEnumVarName(String name, String datatype) {
if (name.length() == 0) {
return "EMPTY";
}
// number
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
String varName = name;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");
return varName;
}
// for symbol, e.g. $, #
if (getSymbolName(name) != null) {
return getSymbolName(name).toUpperCase();
}
// string
String enumName = sanitizeName(underscore(name).toUpperCase());
enumName = enumName.replaceFirst("^_", "");
enumName = enumName.replaceFirst("_$", "");
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
return escapeReservedWord(enumName);
} else {
return enumName;
}
}
@Override
public String toEnumName(CodegenProperty property) {
String enumName = underscore(toModelName(property.name)).toUpperCase();
// remove [] for array or map of enum
enumName = enumName.replace("[]", "");
if (enumName.matches("\\d.*")) { // starts with number
return "_" + enumName;
} else {
return enumName;
}
}
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
// process enum in models
return postProcessModelsEnum(objs);
}
@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation op : operationList) {
// for API test method name
// e.g. public function test{{vendorExtensions.x-testOperationId}}()
op.vendorExtensions.put("x-testOperationId", camelize(op.operationId));
}
return objs;
}
@Override
public String escapeQuotationMark(String input) {
// remove ' to avoid code injection
return input.replace("'", "");
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}
}

View File

@ -53,8 +53,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
modelPackage = invokerPackage + "\\" + modelDirName;
outputFolder = "generated-code" + File.separator + "slim";
// no test files
apiTestTemplateFiles.clear();
modelTestTemplateFiles.put("model_test.mustache", ".php");
// no doc files
modelDocTemplateFiles.clear();
apiDocTemplateFiles.clear();
@ -118,6 +117,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
supportingFiles.add(new SupportingFile(".gitignore", getPackagePath(), ".gitignore"));
supportingFiles.add(new SupportingFile("AbstractApiController.mustache", toSrcPath(invokerPackage, srcBasePath), "AbstractApiController.php"));
supportingFiles.add(new SupportingFile("SlimRouter.mustache", toSrcPath(invokerPackage, srcBasePath), "SlimRouter.php"));
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", getPackagePath(), "phpunit.xml.dist"));
}
@Override

View File

@ -159,6 +159,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(CodegenConstants.SOURCECODEONLY_GENERATION, CodegenConstants.SOURCECODEONLY_GENERATION_DESC)
.defaultValue(Boolean.FALSE.toString()));
supportedLibraries.put("urllib3", "urllib3-based client");
supportedLibraries.put("asyncio", "Asyncio-based client (python 3.5+)");
@ -198,10 +200,22 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
setPackageVersion("1.0.0");
}
Boolean generateSourceCodeOnly = false;
if (additionalProperties.containsKey(CodegenConstants.SOURCECODEONLY_GENERATION)) {
generateSourceCodeOnly = true;
}
additionalProperties.put(CodegenConstants.PROJECT_NAME, projectName);
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
if (generateSourceCodeOnly) {
// tests in <package>/test
testFolder = packageName + File.separatorChar + testFolder;
// api/model docs in <package>/docs
apiDocPath = packageName + File.separatorChar + apiDocPath;
modelDocPath = packageName + File.separatorChar + modelDocPath;
}
// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
@ -210,12 +224,24 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
setPackageUrl((String) additionalProperties.get(PACKAGE_URL));
}
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
String readmePath ="README.md";
String readmeTemplate = "README.mustache";
if (generateSourceCodeOnly) {
readmePath = packageName + "_" + readmePath;
readmeTemplate = "README_onlypackage.mustache";
}
supportingFiles.add(new SupportingFile(readmeTemplate, "", readmePath));
supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini"));
supportingFiles.add(new SupportingFile("test-requirements.mustache", "", "test-requirements.txt"));
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));
if (!generateSourceCodeOnly){
supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini"));
supportingFiles.add(new SupportingFile("test-requirements.mustache", "", "test-requirements.txt"));
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
}
supportingFiles.add(new SupportingFile("configuration.mustache", packageName, "configuration.py"));
supportingFiles.add(new SupportingFile("__init__package.mustache", packageName, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__model.mustache", packageName + File.separatorChar + modelPackage, "__init__.py"));
@ -224,10 +250,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
if (Boolean.FALSE.equals(excludeTests)) {
supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py"));
}
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
supportingFiles.add(new SupportingFile("api_client.mustache", packageName, "api_client.py"));
if ("asyncio".equals(getLibrary())) {

View File

@ -18,14 +18,11 @@
package org.openapitools.codegen.languages;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import java.io.File;
import java.util.Arrays;
@ -37,7 +34,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
public class RubyClientCodegen extends AbstractRubyCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(RubyClientCodegen.class);
public static final String GEM_NAME = "gemName";
public static final String MODULE_NAME = "moduleName";
@ -89,21 +86,13 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
// default HIDE_GENERATION_TIMESTAMP to true
hideGenerationTimestamp = Boolean.TRUE;
setReservedWordsLowerCase(
Arrays.asList(
// local variable names used in API methods (endpoints)
"local_var_path", "query_params", "header_params", "_header_accept", "_header_accept_result",
"_header_content_type", "form_params", "post_body", "auth_names",
// ruby reserved keywords
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
"else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif",
"if", "not", "return", "undef", "yield")
);
// local variable names used in API methods (endpoints)
for (String word : Arrays.asList(
"local_var_path", "query_params", "header_params", "_header_accept", "_header_accept_result",
"_header_content_type", "form_params", "post_body", "auth_names")) {
reservedWords.add(word.toLowerCase());
}
typeMapping.clear();
languageSpecificPrimitives.clear();
// primitives in ruby lang
languageSpecificPrimitives.add("int");
@ -111,37 +100,8 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
languageSpecificPrimitives.add("map");
languageSpecificPrimitives.add("string");
// primitives in the typeMapping
languageSpecificPrimitives.add("String");
languageSpecificPrimitives.add("Integer");
languageSpecificPrimitives.add("Float");
languageSpecificPrimitives.add("Date");
languageSpecificPrimitives.add("DateTime");
languageSpecificPrimitives.add("BOOLEAN");
languageSpecificPrimitives.add("Array");
languageSpecificPrimitives.add("Hash");
languageSpecificPrimitives.add("File");
languageSpecificPrimitives.add("Object");
typeMapping.put("string", "String");
typeMapping.put("char", "String");
typeMapping.put("int", "Integer");
typeMapping.put("integer", "Integer");
typeMapping.put("long", "Integer");
typeMapping.put("short", "Integer");
typeMapping.put("float", "Float");
typeMapping.put("double", "Float");
typeMapping.put("number", "Float");
typeMapping.put("date", "Date");
typeMapping.put("DateTime", "DateTime");
typeMapping.put("boolean", "BOOLEAN");
typeMapping.put("array", "Array");
typeMapping.put("List", "Array");
typeMapping.put("map", "Hash");
typeMapping.put("object", "Object");
typeMapping.put("file", "File");
typeMapping.put("binary", "String");
typeMapping.put("ByteArray", "String");
typeMapping.put("UUID", "String");
// remove modelPackage and apiPackage added by default
Iterator<CliOption> itr = cliOptions.iterator();
@ -308,14 +268,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
return underscore(moduleName.replaceAll("[^\\w]+", ""));
}
@Override
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "_" + name;
}
@Override
public String apiFileFolder() {
return outputFolder + File.separator + libFolder + File.separator + gemName + File.separator + apiPackage.replace("/", File.separator);
@ -346,34 +298,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
}
@Override
public String getTypeDeclaration(Schema schema) {
if (ModelUtils.isArraySchema(schema)) {
Schema inner = ((ArraySchema) schema).getItems();
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isMapSchema(schema)) {
Schema inner = (Schema) schema.getAdditionalProperties();
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
}
return super.getTypeDeclaration(schema);
}
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
return "'" + escapeText((String) p.getDefault()) + "'";
}
}
return null;
}
@Override
public String getSchemaType(Schema schema) {
String openAPIType = super.getSchemaType(schema);
@ -394,33 +318,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
return toModelName(type);
}
@Override
public String toVarName(String name) {
// sanitize name
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// if it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) {
name = name.toLowerCase();
}
// camelize (lower first character) the variable name
// petId => pet_id
name = underscore(name);
// for reserved word or word starting with number, append _
if (isReservedWord(name) || name.matches("^\\d.*")) {
name = escapeReservedWord(name);
}
return name;
}
@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
}
@Override
public String toModelName(String name) {
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
@ -684,16 +581,4 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
//
//return super.shouldOverwrite(filename) && !filename.endsWith("_spec.rb");
}
@Override
public String escapeQuotationMark(String input) {
// remove ' to avoid code injection
return input.replace("'", "");
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}
}

View File

@ -18,30 +18,19 @@
package org.openapitools.codegen.languages;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.core.util.Yaml;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RubyOnRailsServerCodegen extends DefaultCodegen implements CodegenConfig {
public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(RubyOnRailsServerCodegen.class);
private static final SimpleDateFormat MIGRATE_FILE_NAME_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
@ -87,33 +76,14 @@ public class RubyOnRailsServerCodegen extends DefaultCodegen implements CodegenC
embeddedTemplateDir = templateDir = "ruby-on-rails-server";
typeMapping.clear();
languageSpecificPrimitives.clear();
setReservedWordsLowerCase(
Arrays.asList(
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
"else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif",
"if", "not", "return", "undef", "yield")
);
// In order to adapt to DB migrate script, overwrite typeMapping
typeMapping.put("string", "string");
typeMapping.put("char", "string");
typeMapping.put("int", "integer");
typeMapping.put("integer", "integer");
typeMapping.put("long", "integer");
typeMapping.put("short", "integer");
typeMapping.put("float", "float");
typeMapping.put("double", "decimal");
typeMapping.put("number", "float");
typeMapping.put("date", "date");
typeMapping.put("DateTime", "datetime");
typeMapping.put("boolean", "boolean");
typeMapping.put("binary", "string");
typeMapping.put("ByteArray", "string");
typeMapping.put("UUID", "string");
// remove modelPackage and apiPackage added by default
cliOptions.clear();
@ -203,59 +173,11 @@ public class RubyOnRailsServerCodegen extends DefaultCodegen implements CodegenC
return "Generates a Ruby on Rails (v5) server library.";
}
@Override
public String escapeReservedWord(String name) {
if(this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "_" + name;
}
@Override
public String apiFileFolder() {
return outputFolder + File.separator + apiPackage.replace("/", File.separator);
}
@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
}
return super.getTypeDeclaration(p);
}
@Override
public String toDefaultValue(Schema p) {
return "null";
}
@Override
public String toVarName(String name) {
// replace - with _ e.g. created-at => created_at
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// if it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) {
name = name.toLowerCase();
}
// camelize (lower first character) the variable name
// petId => pet_id
name = underscore(name);
// for reserved word or word starting with number, append _
if (isReservedWord(name) || name.matches("^\\d.*")) {
name = escapeReservedWord(name);
}
return name;
}
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
@ -266,12 +188,6 @@ public class RubyOnRailsServerCodegen extends DefaultCodegen implements CodegenC
return "string";
}
@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
}
@Override
public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return
@ -318,32 +234,9 @@ public class RubyOnRailsServerCodegen extends DefaultCodegen implements CodegenC
return camelize(name) + "Controller";
}
@Override
public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
String newOperationId = underscore("call_" + operationId);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}
return underscore(operationId);
}
@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
generateYAMLSpecFile(objs);
return super.postProcessSupportingFileData(objs);
}
@Override
public String escapeQuotationMark(String input) {
// remove ' to avoid code injection
return input.replace("'", "");
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}
}

View File

@ -17,29 +17,18 @@
package org.openapitools.codegen.languages;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.core.util.Yaml;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RubySinatraServerCodegen extends DefaultCodegen implements CodegenConfig {
public class RubySinatraServerCodegen extends AbstractRubyCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(RubySinatraServerCodegen.class);
@ -58,35 +47,6 @@ public class RubySinatraServerCodegen extends DefaultCodegen implements CodegenC
apiTemplateFiles.put("api.mustache", ".rb");
embeddedTemplateDir = templateDir = "ruby-sinatra-server";
typeMapping.clear();
languageSpecificPrimitives.clear();
setReservedWordsLowerCase(
Arrays.asList(
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
"else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif",
"if", "not", "return", "undef", "yield")
);
languageSpecificPrimitives.add("int");
languageSpecificPrimitives.add("array");
languageSpecificPrimitives.add("map");
languageSpecificPrimitives.add("string");
languageSpecificPrimitives.add("DateTime");
typeMapping.put("long", "int");
typeMapping.put("integer", "int");
typeMapping.put("Array", "array");
typeMapping.put("String", "string");
typeMapping.put("List", "array");
typeMapping.put("map", "map");
//TODO binary should be mapped to byte array
// mapped to String as a workaround
typeMapping.put("binary", "string");
typeMapping.put("UUID", "string");
// remove modelPackage and apiPackage added by default
cliOptions.clear();
}
@ -122,32 +82,11 @@ public class RubySinatraServerCodegen extends DefaultCodegen implements CodegenC
return "Generates a Ruby Sinatra server library.";
}
@Override
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "_" + name;
}
@Override
public String apiFileFolder() {
return outputFolder + File.separator + apiPackage.replace("/", File.separator);
}
@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
}
return super.getTypeDeclaration(p);
}
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
@ -166,39 +105,6 @@ public class RubySinatraServerCodegen extends DefaultCodegen implements CodegenC
return type;
}
@Override
public String toDefaultValue(Schema p) {
return "null";
}
@Override
public String toVarName(String name) {
// replace - with _ e.g. created-at => created_at
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// if it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) {
name = name.toLowerCase();
}
// camelize (lower first character) the variable name
// petId => pet_id
name = underscore(name);
// for reserved word or word starting with number, append _
if (isReservedWord(name) || name.matches("^\\d.*")) {
name = escapeReservedWord(name);
}
return name;
}
@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
}
@Override
public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return
@ -243,32 +149,9 @@ public class RubySinatraServerCodegen extends DefaultCodegen implements CodegenC
return camelize(name) + "Api";
}
@Override
public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
String newOperationId = underscore("call_" + operationId);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}
return underscore(operationId);
}
@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
generateYAMLSpecFile(objs);
return super.postProcessSupportingFileData(objs);
}
@Override
public String escapeQuotationMark(String input) {
// remove ' to avoid code injection
return input.replace("'", "");
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}
}

View File

@ -60,21 +60,20 @@ public class JSON {
public static GsonBuilder createGson() {
GsonFireBuilder fireBuilder = new GsonFireBuilder()
{{#parent}}
.registerTypeSelector({{classname}}.class, new TypeSelector() {
{{#models}}{{#model}}{{#discriminator}} .registerTypeSelector({{classname}}.class, new TypeSelector() {
@Override
public Class getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
{{#children}}
classByDiscriminatorValue.put("{{name}}".toUpperCase(), {{classname}}.class);
{{/children}}
{{#mappedModels}}
classByDiscriminatorValue.put("{{mappingName}}".toUpperCase(), {{modelName}}.class);
{{/mappedModels}}
classByDiscriminatorValue.put("{{classname}}".toUpperCase(), {{classname}}.class);
return getClassByDiscriminator(
classByDiscriminatorValue,
getDiscriminatorValue(readElement, "{{{discriminatorName}}}"));
getDiscriminatorValue(readElement, "{{{propertyName}}}"));
}
})
{{/parent}}
{{/discriminator}}{{/model}}{{/models}}
;
GsonBuilder builder = fireBuilder.createGsonBuilder();
{{#disableHtmlEscaping}}

View File

@ -18,7 +18,7 @@
## Requirements
Building the API client library requires:
1. Java {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}+
1. Java {{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}+
2. Maven/Gradle
## Installation

View File

@ -31,6 +31,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -39,6 +44,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -83,6 +89,11 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -91,6 +102,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -84,8 +90,20 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
targetCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
{{/java8}}
{{^java8}}
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -291,7 +291,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
<java.version>{{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<swagger-core-version>1.5.18</swagger-core-version>

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 22
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -84,6 +90,11 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -92,6 +103,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -139,6 +139,11 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
{{#supportJava6}}
<source>1.6</source>
<target>1.6</target>
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
<source>1.8</source>
<target>1.8</target>
@ -147,6 +152,7 @@
<source>1.7</source>
<target>1.7</target>
{{/java8}}
{{/supportJava6}}
</configuration>
</plugin>
<plugin>

View File

@ -709,12 +709,12 @@ public class ApiClient {
Map<String, List<String>> responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return new ApiResponse<>(statusCode, responseHeaders);
return new ApiResponse<{{#supportJava6}}T{{/supportJava6}}>(statusCode, responseHeaders);
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return new ApiResponse<>(statusCode, responseHeaders);
return new ApiResponse<{{#supportJava6}}T{{/supportJava6}}>(statusCode, responseHeaders);
else
return new ApiResponse<>(statusCode, responseHeaders, deserialize(response, returnType));
return new ApiResponse<{{#supportJava6}}T{{/supportJava6}}>(statusCode, responseHeaders, deserialize(response, returnType));
} else {
String message = "error";
String respBody = null;

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -83,6 +89,11 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -91,6 +102,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {
@ -105,17 +117,20 @@ if(hasProperty('target') && target == 'android') {
}
ext {
swagger_annotations_version = "1.5.17"
jackson_version = "2.8.9"
swagger_annotations_version = "1.5.20"
jackson_version = "2.9.6"
{{#supportJava6}}
jersey_version = "2.6"
commons_io_version=2.5
commons_lang3_version=3.6
{{/supportJava6}}
{{^supportJava6}}
jersey_version = "2.25.1"
jersey_version = "2.27"
{{/supportJava6}}
junit_version = "4.12"
{{#threetenbp}}
threetenbp_version = "2.6.4"
{{/threetenbp}}
}
dependencies {
@ -127,17 +142,17 @@ dependencies {
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
{{#joda}}
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version",
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
{{/joda}}
{{#java8}}
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version",
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
{{/java8}}
{{#supportJava6}}
compile "commons-io:commons-io:$commons_io_version"
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
{{/supportJava6}}
{{#threetenbp}}
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$threetenbp_version"
{{/threetenbp}}
{{^java8}}
compile "com.brsanthu:migbase64:2.2"

View File

@ -9,13 +9,13 @@ lazy val root = (project in file(".")).
publishArtifact in (Compile, packageDoc) := false,
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Seq(
"io.swagger" % "swagger-annotations" % "1.5.17",
"io.swagger" % "swagger-annotations" % "1.5.20",
"org.glassfish.jersey.core" % "jersey-client" % {{#supportJava6}}"2.6"{{/supportJava6}}{{^supportJava6}}"2.25.1"{{/supportJava6}},
"org.glassfish.jersey.media" % "jersey-media-multipart" % {{#supportJava6}}"2.6"{{/supportJava6}}{{^supportJava6}}"2.25.1"{{/supportJava6}},
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % {{#supportJava6}}"2.6"{{/supportJava6}}{{^supportJava6}}"2.25.1"{{/supportJava6}},
"com.fasterxml.jackson.core" % "jackson-core" % "{{^threetenbp}}2.8.9{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "{{^threetenbp}}2.8.9{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "{{^threetenbp}}2.8.9{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}" % "compile",
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.9" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.9" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9" % "compile",
{{#joda}}
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.8.9" % "compile",
{{/joda}}

View File

@ -139,6 +139,11 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
{{#supportJava6}}
<source>1.6</source>
<target>1.6</target>
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
<source>1.8</source>
<target>1.8</target>
@ -147,6 +152,7 @@
<source>1.7</source>
<target>1.7</target>
{{/java8}}
{{/supportJava6}}
</configuration>
</plugin>
<plugin>
@ -270,7 +276,7 @@
<dependency>
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
<version>${jackson-version}</version>
<version>${threetenbp-version}</version>
</dependency>
{{/threetenbp}}
{{^java8}}
@ -312,16 +318,19 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.18</swagger-core-version>
<swagger-core-version>1.5.20</swagger-core-version>
{{^supportJava6}}
<jersey-version>2.25.1</jersey-version>
<jersey-version>2.27</jersey-version>
{{/supportJava6}}
{{#supportJava6}}
<jersey-version>2.6</jersey-version>
<commons_io_version>2.5</commons_io_version>
<commons_lang3_version>3.6</commons_lang3_version>
<jersey-version>2.6</jersey-version>
<commons_io_version>2.5</commons_io_version>
<commons_lang3_version>3.6</commons_lang3_version>
{{/supportJava6}}
<jackson-version>{{^threetenbp}}2.7.5{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}</jackson-version>
<jackson-version>2.8.9</jackson-version>
{{#threetenbp}}
<threetenbp-version>2.6.4</threetenbp-version>
{{/threetenbp}}
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.12</junit-version>
</properties>

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -84,8 +90,20 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
targetCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
{{/java8}}
{{^java8}}
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -267,7 +267,7 @@
</dependency>
</dependencies>
<properties>
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
<java.version>{{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.8.0</gson-fire-version>

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 23
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -83,6 +89,11 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -91,6 +102,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -120,6 +120,11 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
{{#supportJava6}}
<source>1.6</source>
<target>1.6</target>
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
<source>1.8</source>
<target>1.8</target>
@ -128,6 +133,7 @@
<source>1.7</source>
<target>1.7</target>
{{/java8}}
{{/supportJava6}}
</configuration>
</plugin>
<plugin>

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 22
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -84,6 +90,11 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -92,6 +103,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -139,6 +139,11 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
{{#supportJava6}}
<source>1.6</source>
<target>1.6</target>
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
<source>1.8</source>
<target>1.8</target>
@ -147,6 +152,7 @@
<source>1.7</source>
<target>1.7</target>
{{/java8}}
{{/supportJava6}}
</configuration>
</plugin>
<plugin>

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly

View File

@ -139,8 +139,20 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</source>
<target>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</target>
{{#supportJava6}}
<source>1.6</source>
<target>1.6</target>
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
<source>1.8</source>
<target>1.8</target>
{{/java8}}
{{^java8}}
<source>1.7</source>
<target>1.7</target>
{{/java8}}
{{/supportJava6}}
</configuration>
</plugin>
<plugin>

View File

@ -57,21 +57,20 @@ public class JSON {
public static GsonBuilder createGson() {
GsonFireBuilder fireBuilder = new GsonFireBuilder()
{{#parent}}
.registerTypeSelector({{classname}}.class, new TypeSelector() {
{{#models}}{{#model}}{{#discriminator}} .registerTypeSelector({{classname}}.class, new TypeSelector() {
@Override
public Class getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
{{#children}}
classByDiscriminatorValue.put("{{name}}".toUpperCase(), {{classname}}.class);
{{/children}}
{{#mappedModels}}
classByDiscriminatorValue.put("{{mappingName}}".toUpperCase(), {{modelName}}.class);
{{/mappedModels}}
classByDiscriminatorValue.put("{{classname}}".toUpperCase(), {{classname}}.class);
return getClassByDiscriminator(
classByDiscriminatorValue,
getDiscriminatorValue(readElement, "{{{discriminatorName}}}"));
getDiscriminatorValue(readElement, "{{{propertyName}}}"));
}
})
{{/parent}}
{{/discriminator}}{{/model}}{{/models}}
;
return fireBuilder.createGsonBuilder();
}

View File

@ -32,6 +32,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -40,6 +45,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -84,8 +90,20 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
targetCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
{{/java8}}
{{^java8}}
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -40,7 +40,7 @@ public class ApiClient {
public ApiClient() {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<>();{{#authMethods}}{{#isBasic}}
authentications = new HashMap<{{#supportJava6}}String, Authentication{{/supportJava6}}>();{{#authMethods}}{{#isBasic}}
// authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
// authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
@ -57,8 +57,8 @@ public class ApiClient {
basePath = basePath + "/";
}
Map<String, String> extraHeaders = new HashMap<>();
List<Pair> extraQueryParams = new ArrayList<>();
Map<String, String> extraHeaders = new HashMap<{{#supportJava6}}String, String{{/supportJava6}}>();
List<Pair> extraQueryParams = new ArrayList<{{#supportJava6}}Pair{{/supportJava6}}>();
for (String authName : authentications.keySet()) {
Authentication auth = authentications.get(authName);

View File

@ -40,7 +40,7 @@ public class ApiClient {
public ApiClient() {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<>();{{#authMethods}}{{#isBasic}}
authentications = new HashMap<{{#supportJava6}}String, Authentication{{/supportJava6}}>();{{#authMethods}}{{#isBasic}}
// authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
// authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
@ -57,8 +57,8 @@ public class ApiClient {
basePath = basePath + "/";
}
Map<String, String> extraHeaders = new HashMap<>();
List<Pair> extraQueryParams = new ArrayList<>();
Map<String, String> extraHeaders = new HashMap<{{#supportJava6}}String, String{{/supportJava6}}>();
List<Pair> extraQueryParams = new ArrayList<{{#supportJava6}}Pair{{/supportJava6}}>();
for (String authName : authentications.keySet()) {
Authentication auth = authentications.get(authName);

View File

@ -327,7 +327,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
<java.version>{{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.8.0</gson-fire-version>

View File

@ -139,6 +139,11 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
{{#supportJava6}}
<source>1.6</source>
<target>1.6</target>
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
<source>1.8</source>
<target>1.8</target>
@ -147,6 +152,7 @@
<source>1.7</source>
<target>1.7</target>
{{/java8}}
{{/supportJava6}}
</configuration>
</plugin>
<plugin>

View File

@ -1,7 +1,8 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true)
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/children}}
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/discriminator.mappedModels}}
}){{/jackson}}

View File

@ -1,7 +1,8 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true)
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/children}}
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/discriminator.mappedModels}}
}){{/jackson}}

View File

@ -1,7 +1,8 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true)
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/children}}
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/discriminator.mappedModels}}
}){{/jackson}}

View File

@ -1,7 +1,8 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true)
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/children}}
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/discriminator.mappedModels}}
}){{/jackson}}

View File

@ -1,7 +1,8 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true)
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/children}}
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/discriminator.mappedModels}}
}){{/jackson}}

View File

@ -56,6 +56,11 @@ android {
{{/androidSdkVersion}}
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -64,6 +69,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly

View File

@ -35,6 +35,11 @@ android {
targetSdkVersion 25
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -43,6 +48,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly

View File

@ -1,7 +1,8 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true)
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/children}}
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
{{/discriminator.mappedModels}}
}){{/jackson}}

View File

@ -0,0 +1,90 @@
<?php
/**
* {{classname}}Test
* PHP version 5
*
* @category Class
* @package {{apiPackage}}
* @author OpenAPI Generator team
* @link https://github.com/openapitools/openapi-generator
*/
/**
{{#appName}}
* {{{appName}}}
*
{{/appName}}
{{#appDescription}}
* {{{appDescription}}}
{{/appDescription}}
{{#version}}
* OpenAPI spec version: {{{version}}}
{{/version}}
{{#infoEmail}}
* Contact: {{{infoEmail}}}
{{/infoEmail}}
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
/**
* NOTE: This class is auto generated by the openapi generator program.
* https://github.com/openapitools/openapi-generator
* Please update the test case below to test the endpoint.
*/
namespace {{apiPackage}};
use {{apiPackage}}\{{classname}};
/**
* {{classname}}Test Class Doc Comment
*
* @category Class
* @description {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}}
* @package {{apiPackage}}
* @author OpenAPI Generator team
* @link https://github.com/openapitools/openapi-generator
* @coversDefaultClass \{{modelPackage}}\{{classname}}
*/
{{#operations}}class {{classname}}Test extends \PHPUnit_Framework_TestCase {
/**
* Setup before running any test cases
*/
public static function setUpBeforeClass() {
}
/**
* Setup before running each test case
*/
public function setUp() {
}
/**
* Clean up after running each test case
*/
public function tearDown() {
}
/**
* Clean up after running all test cases
*/
public static function tearDownAfterClass() {
}
{{#operation}}
/**
* Test case for {{{operationId}}}
*
* {{{summary}}}.
* @covers ::{{{operationId}}}
*/
public function test{{operationIdCamelCase}}() {
}
{{/operation}}
}
{{/operations}}

View File

@ -1,9 +1,24 @@
{
"minimum-stability": "RC",
"require": {
"php": ">=5.5",
"slim/slim": "3.*"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
},
"autoload": {
"psr-4": { "{{escapedInvokerPackage}}\\": "{{srcBasePath}}/" }
},
"autoload-dev": {
"psr-4": { "{{escapedInvokerPackage}}\\": "{{testBasePath}}/" }
},
"scripts": {
"test": [
"@test-apis",
"@test-models"
],
"test-apis": "phpunit --testsuite Apis",
"test-models": "phpunit --testsuite Models"
}
}

View File

@ -0,0 +1,96 @@
<?php
{{#models}}
{{#model}}
/**
* {{classname}}Test
* PHP version 5
*
* @category Class
* @package {{modelPackage}}
* @author OpenAPI Generator team
* @link https://github.com/openapitools/openapi-generator
*/
/**
{{#appName}}
* {{{appName}}}
*
{{/appName}}
{{#appDescription}}
* {{{appDescription}}}
{{/appDescription}}
{{#version}}
* OpenAPI spec version: {{{version}}}
{{/version}}
{{#infoEmail}}
* Contact: {{{infoEmail}}}
{{/infoEmail}}
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
/**
* NOTE: This class is auto generated by the openapi generator program.
* https://github.com/openapitools/openapi-generator
* Please update the test case below to test the model.
*/
namespace {{modelPackage}};
use {{modelPackage}}\{{classname}};
/**
* {{classname}}Test Class Doc Comment
*
* @category Class
* @description {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}}
* @package {{modelPackage}}
* @author OpenAPI Generator team
* @link https://github.com/openapitools/openapi-generator
* @coversDefaultClass \{{modelPackage}}\{{classname}}
*/
class {{classname}}Test extends \PHPUnit_Framework_TestCase {
/**
* Setup before running any test cases
*/
public static function setUpBeforeClass() {
}
/**
* Setup before running each test case
*/
public function setUp() {
}
/**
* Clean up after running each test case
*/
public function tearDown() {
}
/**
* Clean up after running all test cases
*/
public static function tearDownAfterClass() {
}
/**
* Test "{{classname}}"
*/
public function test{{classname}}() {
$test{{classname}} = new {{classname}}();
}
{{#vars}}
/**
* Test attribute "{{name}}"
*/
public function testProperty{{nameInCamelCase}}() {
}
{{/vars}}
}
{{/model}}{{/models}}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
>
<testsuites>
<testsuite name="Apis">
<directory>{{apiTestPath}}</directory>
</testsuite>
<testsuite name="Models">
<directory>{{modelTestPath}}</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">{{apiSrcPath}}</directory>
<directory suffix=".php">{{modelSrcPath}}</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -52,78 +52,4 @@ import {{{packageName}}}
Please follow the [installation procedure](#installation--usage) and then run the following:
```python
from __future__ import print_function
import time
import {{{packageName}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
configuration = {{{packageName}}}.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
configuration = {{{packageName}}}.Configuration()
configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
configuration = {{{packageName}}}.Configuration()
configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}
# create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
try:
{{#summary}} # {{{.}}}
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
pprint(api_response){{/returnType}}
except ApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```
## Documentation for API Endpoints
All URIs are relative to *{{basePath}}*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
## Documentation For Models
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
{{/model}}{{/models}}
## Documentation For Authorization
{{^authMethods}} All endpoints do not require authorization.
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
{{#authMethods}}## {{{name}}}
{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}
{{/authMethods}}
## Author
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
{{/hasMore}}{{/apis}}{{/apiInfo}}
{{> common_README }}

View File

@ -0,0 +1,44 @@
# {{{projectName}}}
{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}
The `{{packageName}}` package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}
## Requirements.
Python 2.7 and 3.4+
## Installation & Usage
This python library package is generated without supporting files like setup.py or requirements files
To be able to use it, you will need these dependencies in your own package that uses this library:
* urllib3 >= 1.15
* six >= 1.10
* certifi
* python-dateutil
{{#asyncio}}
* aiohttp
{{/asyncio}}
{{#tornado}}
* tornado>=4.2,<5
{{/tornado}}
## Getting Started
In your own code, to use this library to connect and interact with {{{projectName}}},
you can run the following:
{{> common_README }}

View File

@ -6,6 +6,8 @@
from __future__ import absolute_import
__version__ = "{{packageVersion}}"
# import apis into sdk package
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classVarName}} import {{classname}}
{{/apis}}{{/apiInfo}}

View File

@ -0,0 +1,75 @@
```python
from __future__ import print_function
import time
import {{{packageName}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
configuration = {{{packageName}}}.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
configuration = {{{packageName}}}.Configuration()
configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
configuration = {{{packageName}}}.Configuration()
configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}
# create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
try:
{{#summary}} # {{{.}}}
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
pprint(api_response){{/returnType}}
except ApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```
## Documentation for API Endpoints
All URIs are relative to *{{basePath}}*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
## Documentation For Models
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
{{/model}}{{/models}}
## Documentation For Authorization
{{^authMethods}} All endpoints do not require authorization.
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
{{#authMethods}}## {{{name}}}
{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}
{{/authMethods}}
## Author
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
{{/hasMore}}{{/apis}}{{/apiInfo}}

View File

@ -7,7 +7,7 @@ MyApp.add_route('{{httpMethod}}', '{{{basePathWithoutHost}}}{{{path}}}', {
"resourcePath" => "/{{{baseName}}}",
"summary" => "{{{summary}}}",
"nickname" => "{{nickname}}",
"responseClass" => "{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}",
"responseClass" => "{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}",
"endpoint" => "{{{path}}}",
"notes" => "{{{notes}}}",
"parameters" => [
@ -15,7 +15,7 @@ MyApp.add_route('{{httpMethod}}', '{{{basePathWithoutHost}}}{{{path}}}', {
{
"name" => "{{paramName}}",
"description" => "{{description}}",
"dataType" => "{{dataType}}",
"dataType" => "{{{dataType}}}",
{{#collectionFormat}}
"collectionFormat" => "{{collectionFormat}}",
{{/collectionFormat}}
@ -32,7 +32,7 @@ MyApp.add_route('{{httpMethod}}', '{{{basePathWithoutHost}}}{{{path}}}', {
{
"name" => "{{paramName}}",
"description" => "{{description}}",
"dataType" => "{{dataType}}",
"dataType" => "{{{dataType}}}",
"paramType" => "path",
},
{{/pathParams}}
@ -40,7 +40,7 @@ MyApp.add_route('{{httpMethod}}', '{{{basePathWithoutHost}}}{{{path}}}', {
{
"name" => "{{paramName}}",
"description" => "{{description}}",
"dataType" => "{{dataType}}",
"dataType" => "{{{dataType}}}",
"paramType" => "header",
},
{{/headerParams}}
@ -48,7 +48,7 @@ MyApp.add_route('{{httpMethod}}', '{{{basePathWithoutHost}}}{{{path}}}', {
{
"name" => "body",
"description" => "{{description}}",
"dataType" => "{{dataType}}",
"dataType" => "{{{dataType}}}",
"paramType" => "body",
}
{{/bodyParams}}

View File

@ -356,6 +356,47 @@ public class DefaultCodegenTest {
Assert.assertEquals(codegenParameter2.example, "An example4 value");
}
@Test
public void testDiscriminator() {
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", null, new ParseOptions()).getOpenAPI();
DefaultCodegen codegen = new DefaultCodegen();
Schema animal = openAPI.getComponents().getSchemas().get("Animal");
CodegenModel animalModel = codegen.fromModel("Animal", animal, openAPI.getComponents().getSchemas());
CodegenDiscriminator discriminator = animalModel.getDiscriminator();
CodegenDiscriminator test = new CodegenDiscriminator();
test.setPropertyName("className");
test.getMappedModels().add(new CodegenDiscriminator.MappedModel("Dog", "Dog"));
test.getMappedModels().add(new CodegenDiscriminator.MappedModel("Cat", "Cat"));
Assert.assertEquals(discriminator, test);
}
@Test
public void testDiscriminatorWithCustomMapping() {
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/allOf.yaml", null, new ParseOptions()).getOpenAPI();
DefaultCodegen codegen = new DefaultCodegen();
String path = "/person/display/{personId}";
Operation operation = openAPI.getPaths().get(path).getGet();
CodegenOperation codegenOperation = codegen.fromOperation(path, "GET", operation, openAPI.getComponents().getSchemas());
verifyPersonDiscriminator(codegenOperation.discriminator);
Schema person = openAPI.getComponents().getSchemas().get("Person");
CodegenModel personModel = codegen.fromModel("Person", person, openAPI.getComponents().getSchemas());
verifyPersonDiscriminator(personModel.discriminator);
}
private void verifyPersonDiscriminator(CodegenDiscriminator discriminator) {
CodegenDiscriminator test = new CodegenDiscriminator();
test.setPropertyName("$_type");
test.setMapping(new HashMap<>());
test.getMapping().put("a", "#/components/schemas/Adult");
test.getMapping().put("c", "#/components/schemas/Child");
test.getMappedModels().add(new CodegenDiscriminator.MappedModel("a", "Adult"));
test.getMappedModels().add(new CodegenDiscriminator.MappedModel("c", "Child"));
Assert.assertEquals(discriminator, test);
}
private CodegenProperty codegenPropertyWithArrayOfIntegerValues() {
CodegenProperty array = new CodegenProperty();
final CodegenProperty items = new CodegenProperty();

View File

@ -64,111 +64,6 @@ import java.util.stream.Collectors;
public class JavaClientCodegenTest {
@Test
public void modelInheritanceSupportInGson() throws Exception {
List<Map<String, Object>> allModels = new ArrayList<>();
CodegenModel parent1 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
parent1.setName("parent1");
parent1.setClassname("test.Parent1");
Map<String, Object> modelMap = new HashMap<>();
modelMap.put("model", parent1);
allModels.add(modelMap);
CodegenModel parent2 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
parent2.setName("parent2");
parent2.setClassname("test.Parent2");
modelMap = new HashMap<>();
modelMap.put("model", parent2);
allModels.add(modelMap);
CodegenModel model1 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
model1.setName("model1");
model1.setClassname("test.Model1");
model1.setParentModel(parent1);
modelMap = new HashMap<>();
modelMap.put("model", model1);
allModels.add(modelMap);
CodegenModel model2 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
model2.setName("model2");
model2.setClassname("test.Model2");
model2.setParentModel(parent1);
modelMap = new HashMap<>();
modelMap.put("model", model2);
allModels.add(modelMap);
CodegenModel model3 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
model3.setName("model3");
model3.setClassname("test.Model3");
model3.setParentModel(parent1);
modelMap = new HashMap<>();
modelMap.put("model", model3);
allModels.add(modelMap);
CodegenModel model4 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
model4.setName("model4");
model4.setClassname("test.Model4");
model4.setParentModel(parent2);
modelMap = new HashMap<>();
modelMap.put("model", model4);
allModels.add(modelMap);
CodegenModel model5 = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
model5.setName("model5");
model5.setClassname("test.Model5");
model5.setParentModel(parent2);
modelMap = new HashMap<>();
modelMap.put("model", model5);
allModels.add(modelMap);
List<Map<String, Object>> parentsList = JavaClientCodegen.modelInheritanceSupportInGson(allModels);
Assert.assertNotNull(parentsList);
Assert.assertEquals(parentsList.size(), 2);
Map<String, Object> parent = parentsList.get(0);
Assert.assertEquals(parent.get("classname"), "test.Parent1");
List<CodegenModel> children = (List<CodegenModel>) parent.get("children");
Assert.assertNotNull(children);
Assert.assertEquals(children.size(), 3);
Map<String, Object> models = (Map<String, Object>) children.get(0);
Assert.assertEquals(models.get("name"), "model1");
Assert.assertEquals(models.get("classname"), "test.Model1");
models = (Map<String, Object>) children.get(1);
Assert.assertEquals(models.get("name"), "model2");
Assert.assertEquals(models.get("classname"), "test.Model2");
models = (Map<String, Object>) children.get(2);
Assert.assertEquals(models.get("name"), "model3");
Assert.assertEquals(models.get("classname"), "test.Model3");
parent = parentsList.get(1);
Assert.assertEquals(parent.get("classname"), "test.Parent2");
children = (List<CodegenModel>) parent.get("children");
Assert.assertNotNull(children);
Assert.assertEquals(children.size(), 2);
models = (Map<String, Object>) children.get(0);
Assert.assertEquals(models.get("name"), "model4");
Assert.assertEquals(models.get("classname"), "test.Model4");
models = (Map<String, Object>) children.get(1);
Assert.assertEquals(models.get("name"), "model5");
Assert.assertEquals(models.get("classname"), "test.Model5");
}
@Test
public void arraysInRequestBody() throws Exception {
final JavaClientCodegen codegen = new JavaClientCodegen();

View File

@ -44,6 +44,7 @@ public class PythonClientOptionsProvider implements OptionsProvider {
.put(CodegenConstants.PACKAGE_VERSION, PACKAGE_VERSION_VALUE)
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "true")
.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "true")
.put(CodegenConstants.SOURCECODEONLY_GENERATION, "false")
.put(CodegenConstants.LIBRARY, "urllib3")
.build();
}

View File

@ -71,10 +71,10 @@ public class AbstractPhpCodegenTest {
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
Assert.assertEquals(codegen.modelPackage(), "PHPmodel");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "PHPmodel");
Assert.assertEquals(codegen.apiPackage(), "PHPapi");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "PHPapi");
Assert.assertEquals(codegen.modelPackage(), "PHPinvoker\\PHPmodel");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "PHPinvoker\\PHPmodel");
Assert.assertEquals(codegen.apiPackage(), "PHPinvoker\\PHPapi");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "PHPinvoker\\PHPapi");
Assert.assertEquals(codegen.getInvokerPackage(), "PHPinvoker");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "PHPinvoker");
}

View File

@ -34,6 +34,11 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 23
}
compileOptions {
{{#supportJava6}}
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -42,6 +47,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
}
// Rename the aar correctly
@ -85,6 +91,11 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
{{#supportJava6}}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
{{/supportJava6}}
{{^supportJava6}}
{{#java8}}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -93,6 +104,7 @@ if(hasProperty('target') && target == 'android') {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{{/java8}}
{{/supportJava6}}
install {
repositories.mavenInstaller {

View File

@ -0,0 +1,61 @@
openapi: 3.0.1
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/person/display/{personId}:
get:
parameters:
- name: personId
in: path
required: true
description: The id of the person to retrieve
schema:
type: string
operationId: list
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Person"
components:
schemas:
Person:
type: object
discriminator:
propertyName: $_type
mapping:
a: '#/components/schemas/Adult'
c: '#/components/schemas/Child'
properties:
$_type:
type: string
lastName:
type: string
firstName:
type: string
Adult:
description: A representation of an adult
allOf:
- $ref: '#/components/schemas/Person'
- type: object
properties:
children:
type: array
items:
$ref: "#/components/schemas/Child"
Child:
description: A representation of a child
allOf:
- $ref: '#/components/schemas/Person'
- type: object
properties:
age:
type: integer
format: int32

View File

@ -1 +1 @@
3.1.0-SNAPSHOT
3.1.1-SNAPSHOT

View File

@ -61,7 +61,7 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi(
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // object |
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE |
try {
$apiInstance->testCodeInjectEndRnNR($unknown_base_type);
@ -74,7 +74,7 @@ try {
## Documentation for API Endpoints
All URIs are relative to *petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*
All URIs are relative to *http://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------

View File

@ -1,6 +1,6 @@
# OpenAPI\Client\FakeApi
All URIs are relative to *petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*
All URIs are relative to *http://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*
Method | HTTP request | Description
------------- | ------------- | -------------
@ -22,7 +22,7 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi(
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // object |
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE |
try {
$apiInstance->testCodeInjectEndRnNR($unknown_base_type);
@ -36,7 +36,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**unknown_base_type** | [**object**](../Model/UNKNOWN_BASE_TYPE.md)| | [optional]
**unknown_base_type** | [**\OpenAPI\Client\Model\UNKNOWN_BASE_TYPE**](../Model/UNKNOWN_BASE_TYPE.md)| | [optional]
### Return type

View File

@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**
@ -92,7 +92,7 @@ class FakeApi
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type unknown_base_type (optional)
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
@ -108,7 +108,7 @@ class FakeApi
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
@ -160,7 +160,7 @@ class FakeApi
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
@ -180,7 +180,7 @@ class FakeApi
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
@ -216,7 +216,7 @@ class FakeApi
/**
* Create request for operation 'testCodeInjectEndRnNR'
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request

View File

@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**

View File

@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**
@ -81,7 +81,7 @@ class Configuration
*
* @var string
*/
protected $host = 'petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r';
protected $host = 'http://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r';
/**
* User agent of the HTTP request, set to "OpenAPI-Generator/{version}/PHP" by default

View File

@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**

View File

@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**

View File

@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**

View File

@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/
/**

View File

@ -26,7 +26,8 @@ import io.swagger.annotations.ApiModelProperty;
/**
* Animal
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),

View File

@ -26,7 +26,8 @@ import io.swagger.annotations.ApiModelProperty;
/**
* Animal
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),

View File

@ -26,7 +26,8 @@ import io.swagger.annotations.ApiModelProperty;
/**
* Animal
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),

View File

@ -12,7 +12,7 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod
## Requirements
Building the API client library requires:
1. Java 1.7+
1. Java 1.6+
2. Maven/Gradle
## Installation
@ -108,6 +108,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite |
*FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number |
*FakeApi* | [**fakeOuterStringSerialize**](docs/FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string |
*FakeApi* | [**testBodyWithFileSchema**](docs/FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema |
*FakeApi* | [**testBodyWithQueryParams**](docs/FakeApi.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params |
*FakeApi* | [**testClientModel**](docs/FakeApi.md#testClientModel) | **PATCH** /fake | To test \&quot;client\&quot; model
*FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
@ -123,6 +124,7 @@ Class | Method | HTTP request | Description
*PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
*PetApi* | [**uploadFileWithRequiredFile**](docs/PetApi.md#uploadFileWithRequiredFile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required)
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID
*StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{order_id} | Find purchase order by ID
@ -154,6 +156,7 @@ Class | Method | HTTP request | Description
- [EnumArrays](docs/EnumArrays.md)
- [EnumClass](docs/EnumClass.md)
- [EnumTest](docs/EnumTest.md)
- [FileSchemaTestClass](docs/FileSchemaTestClass.md)
- [FormatTest](docs/FormatTest.md)
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [MapTest](docs/MapTest.md)
@ -169,6 +172,7 @@ Class | Method | HTTP request | Description
- [Pet](docs/Pet.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [SpecialModelName](docs/SpecialModelName.md)
- [StringBooleanMap](docs/StringBooleanMap.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)

View File

@ -6,7 +6,9 @@ version = '1.0.0'
buildscript {
repositories {
jcenter()
jcenter {
url "http://jcenter.bintray.com/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
@ -15,7 +17,9 @@ buildscript {
}
repositories {
jcenter()
jcenter {
url "http://jcenter.bintray.com/"
}
}
@ -32,8 +36,8 @@ if(hasProperty('target') && target == 'android') {
targetSdkVersion 25
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
// Rename the aar correctly
@ -77,8 +81,8 @@ if(hasProperty('target') && target == 'android') {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
install {
repositories.mavenInstaller {
@ -93,12 +97,13 @@ if(hasProperty('target') && target == 'android') {
}
ext {
swagger_annotations_version = "1.5.17"
jackson_version = "2.8.9"
swagger_annotations_version = "1.5.20"
jackson_version = "2.9.6"
jersey_version = "2.6"
commons_io_version=2.5
commons_lang3_version=3.6
junit_version = "4.12"
threetenbp_version = "2.6.4"
}
dependencies {
@ -111,7 +116,7 @@ dependencies {
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "commons-io:commons-io:$commons_io_version"
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$threetenbp_version"
compile "com.brsanthu:migbase64:2.2"
testCompile "junit:junit:$junit_version"
}

View File

@ -9,13 +9,13 @@ lazy val root = (project in file(".")).
publishArtifact in (Compile, packageDoc) := false,
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Seq(
"io.swagger" % "swagger-annotations" % "1.5.17",
"io.swagger" % "swagger-annotations" % "1.5.20",
"org.glassfish.jersey.core" % "jersey-client" % "2.6",
"org.glassfish.jersey.media" % "jersey-media-multipart" % "2.6",
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "2.6",
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.4" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.4" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.4" % "compile",
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.9" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.9" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9" % "compile",
"com.github.joschi.jackson" % "jackson-datatype-threetenbp" % "2.6.4" % "compile",
"com.brsanthu" % "migbase64" % "2.2",
"org.apache.commons" % "commons-lang3" % "3.6",

View File

@ -139,8 +139,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
@ -239,7 +239,7 @@
<dependency>
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
<version>${jackson-version}</version>
<version>${threetenbp-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
@ -267,11 +267,12 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.18</swagger-core-version>
<jersey-version>2.6</jersey-version>
<commons_io_version>2.5</commons_io_version>
<commons_lang3_version>3.6</commons_lang3_version>
<jackson-version>2.6.4</jackson-version>
<swagger-core-version>1.5.20</swagger-core-version>
<jersey-version>2.6</jersey-version>
<commons_io_version>2.5</commons_io_version>
<commons_lang3_version>3.6</commons_lang3_version>
<jackson-version>2.8.9</jackson-version>
<threetenbp-version>2.6.4</threetenbp-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.12</junit-version>
</properties>

View File

@ -698,12 +698,12 @@ public class ApiClient {
Map<String, List<String>> responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return new ApiResponse<>(statusCode, responseHeaders);
return new ApiResponse<T>(statusCode, responseHeaders);
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return new ApiResponse<>(statusCode, responseHeaders);
return new ApiResponse<T>(statusCode, responseHeaders);
else
return new ApiResponse<>(statusCode, responseHeaders, deserialize(response, returnType));
return new ApiResponse<T>(statusCode, responseHeaders, deserialize(response, returnType));
} else {
String message = "error";
String respBody = null;

View File

@ -25,7 +25,8 @@ import io.swagger.annotations.ApiModelProperty;
/**
* Animal
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),

View File

@ -17,6 +17,7 @@ import org.openapitools.client.ApiException;
import java.math.BigDecimal;
import org.openapitools.client.model.Client;
import java.io.File;
import org.openapitools.client.model.FileSchemaTestClass;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.openapitools.client.model.OuterComposite;
@ -102,6 +103,22 @@ public class FakeApiTest {
// TODO: test validations
}
/**
*
*
* For this test, the body for this request much reference a schema named &#x60;File&#x60;.
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void testBodyWithFileSchemaTest() throws ApiException {
FileSchemaTestClass fileSchemaTestClass = null;
api.testBodyWithFileSchema(fileSchemaTestClass);
// TODO: test validations
}
/**
*
*

View File

@ -167,4 +167,22 @@ public class PetApiTest {
// TODO: test validations
}
/**
* uploads an image (required)
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void uploadFileWithRequiredFileTest() throws ApiException {
Long petId = null;
File requiredFile = null;
String additionalMetadata = null;
ModelApiResponse response = api.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
// TODO: test validations
}
}

View File

@ -93,9 +93,9 @@ if(hasProperty('target') && target == 'android') {
}
ext {
swagger_annotations_version = "1.5.17"
jackson_version = "2.8.9"
jersey_version = "2.25.1"
swagger_annotations_version = "1.5.20"
jackson_version = "2.9.6"
jersey_version = "2.27"
junit_version = "4.12"
}
@ -107,6 +107,6 @@ dependencies {
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version",
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
testCompile "junit:junit:$junit_version"
}

Some files were not shown because too many files have changed in this diff Show More