cd.connect.openapi.Jersey2V3ApiGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-openapi-jersey2 Show documentation
Show all versions of connect-openapi-jersey2 Show documentation
jersey2 generator from openapi 3.x spec files. Changing to openapitools dependencies.
package cd.connect.openapi;
import io.swagger.v3.oas.models.Operation;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.languages.AbstractJavaJAXRSServerCodegen;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.openapitools.codegen.utils.StringUtils.camelize;
public class Jersey2V3ApiGenerator extends AbstractJavaJAXRSServerCodegen implements CodegenConfig {
private static final String LIBRARY_NAME = "jersey2-api";
private static final String JERSEY2_TEMPLATE_FOLDER = "jersey2-v3template";
private static final String SERVICE_ADDRESS = "serviceAddress";
private static final String SERVICE_NAME = "serviceName";
private static final String SERVICE_PORT = "servicePort";
public Jersey2V3ApiGenerator() {
super();
library = LIBRARY_NAME;
dateLibrary = "java8";
supportedLibraries.clear();
supportedLibraries.put(LIBRARY_NAME, LIBRARY_NAME);
// tell the model about extra mustache files to generate
// if we are using Kubernetes, we should get a service url. We separate these because the serviceName
// is used for the Spring configuration class
// this should appear in your config as:
//
// ... etc
//
cliOptions.add(new CliOption(SERVICE_NAME, "Name of service to use for @enable"));
cliOptions.add(new CliOption(SERVICE_ADDRESS, "Name of service to use for @enable"));
cliOptions.add(new CliOption(SERVICE_PORT, "Port of service to use for @enable"));
cliOptions.add(new CliOption("suppressIgnoreUnknown", "Don't add the ignore unknown to the generated models"));
// override the location
embeddedTemplateDir = templateDir = JERSEY2_TEMPLATE_FOLDER;
}
// @Override
// public List getLanguageArguments() {
// List args = super.getLanguageArguments() == null ? new ArrayList<>() : new ArrayList<>(super.getLanguageArguments());
// CodegenArgument e = new CodegenArgument();
// e.setOption(CodegenConstants.API_TESTS_OPTION);
// e.setValue("false");
// args.add(e);
// return args;
// }
public String getName() {
return LIBRARY_NAME;
}
public String getHelp() {
return "jersey2 api generator. generates all classes and interfaces with jax-rs annotations with jersey2 extensions as necessary";
}
// stoplight has a tendency to insert rubbish in the oas.json file
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
if("null".equals(property.example)) {
property.example = null;
}
}
/**
* This gets called once we have been passed the configuration read in by the plugin.
*/
@Override
public void processOpts() {
super.processOpts();
apiTemplateFiles.remove("api.mustache");
// no documentation, we're british
modelDocTemplateFiles.clear();
apiDocTemplateFiles.clear();
modelTemplateFiles.put("model.mustache", ".java");
if (additionalProperties.get("client") != null) {
apiTemplateFiles.put("Impl.mustache", ".java");
apiTemplateFiles.put("ClientService.mustache", ".java");
}
if (additionalProperties.get("server") != null) {
apiTemplateFiles.put("Service.mustache", ".java");
}
if (additionalProperties.get("server-security") != null) {
apiTemplateFiles.put("SecurityService.mustache", ".java");
}
// apiTemplateFiles.put("Configuration.mustache", ".java");
// this is the name of the library and the date package we use
apiTestTemplateFiles.clear();
if (additionalProperties.get(SERVICE_NAME) != null) {
String serviceName = additionalProperties.get(SERVICE_NAME).toString();
if (additionalProperties.get(SERVICE_ADDRESS) != null) {
addJersey2Client(serviceName, additionalProperties.get(SERVICE_ADDRESS).toString());
} else if (additionalProperties.get(SERVICE_PORT) != null) {
addJersey2Client(serviceName, String.format("%s-service:%s", serviceName, additionalProperties.get(SERVICE_PORT).toString()));
}
}
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER) ) {
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
}
}
@Override
public Map postProcessOperationsWithModels(Map objs, List