Issue 5431 Support jaxrs client api interfaces (#6412)

* Adds the ability to create code for an interface-based jaxrs client.

* Adds shell script and sample files for jaxrs-spec-interface

* rebase into adds shell

* Fixes bug in creation of Produces/Consumes in method annotation. Allows for instance "application/json; charset=utf-8"

* Fixes generated pom.xml

* Generate pom.xml by default

* Prettier output from api.mustache

* Fixes bug in mediatype, allowing charset-specification in swagger.yaml.

* Merges generation of interface-based jaxrs client/api into jaxrs-spec.

* Moves jaxrs-spec server interface to match location of jaxrs-spec server

* Makes Generated-annotation in genereated classes slightly prettier.
This commit is contained in:
jarlesat
2017-10-08 09:28:12 +02:00
committed by wing328
parent cdc83ffd16
commit 8a7940f199
58 changed files with 6054 additions and 172 deletions

View File

@@ -15,18 +15,18 @@ import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.SupportingFile;
import io.swagger.codegen.languages.features.BeanValidationFeatures;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.models.properties.Property;
import io.swagger.util.Json;
public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
{
private static final String INTERFACE_ONLY = "interfaceOnly";
public static final String INTERFACE_ONLY = "interfaceOnly";
public static final String GENERATE_POM = "generatePom";
protected boolean interfaceOnly = false;
private boolean interfaceOnly = false;
private boolean generatePom = true;
public JavaJAXRSSpecServerCodegen()
{
@@ -36,7 +36,6 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
outputFolder = "generated-code/JavaJaxRS-Spec";
modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
apiPackage = "io.swagger.api";
modelPackage = "io.swagger.model";
@@ -74,25 +73,30 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
library.setEnum(supportedLibraries);
cliOptions.add(library);
cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files."));
cliOptions.add(CliOption.newBoolean(GENERATE_POM, "Whether to generate pom.xml if the file does not already exist.").defaultValue(String.valueOf(generatePom)));
cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.").defaultValue(String.valueOf(interfaceOnly)));
}
@Override
public void processOpts()
{
if (additionalProperties.containsKey(GENERATE_POM)) {
generatePom = Boolean.valueOf(additionalProperties.get(GENERATE_POM).toString());
}
if (additionalProperties.containsKey(INTERFACE_ONLY)) {
interfaceOnly = Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY).toString());
}
if (interfaceOnly) {
// Change default artifactId if genereating interfaces only, before command line options are applied in base class.
artifactId = "swagger-jaxrs-client";
}
super.processOpts();
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
if (additionalProperties.containsKey(INTERFACE_ONLY)) {
this.setInterfaceOnly(Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY).toString()));
if (!interfaceOnly) {
additionalProperties.remove(INTERFACE_ONLY);
}
if (generatePom) {
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
}
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
if (!interfaceOnly) {
writeOptional(outputFolder, new SupportingFile("RestApplication.mustache",
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java"));
@@ -106,8 +110,6 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
return "jaxrs-spec";
}
public void setInterfaceOnly(boolean interfaceOnly) { this.interfaceOnly = interfaceOnly; }
@Override
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
String basePath = resourcePath;