मैं मौजूदा जेएक्स-आरएस जनरेटर के आधार पर एक कस्टम स्वैगर कोड जेनरेटर बनाने की कोशिश कर रहा हूं। मैंने स्वैगर-कोडेजन गिटहब पेज पर दिशानिर्देशों का पालन किया और जावा -जर मॉड्यूल/swagger-codegen-cli/target/swagger-codegen-cli.jar मेटा-आउटपुट/myLibrary -n ABCCodegen -p कमांड का उपयोग कर मॉड्यूल जेनरेट किया com.abc.codegen। मैंने टेम्पलेट्स बनाए हैं जिन्हें मुझे एबीसीसीडीजेनजेनरेटर.जेवा फ़ाइल की आवश्यकता होगी और अपडेट किया जाएगा।मैं अपने कस्टम जनरेटर के बारे में swagger-codgen कैसे कहूं?
जब मैं कोड चलाने की कोशिश करता हूं तो मैं समस्याओं में भाग ले रहा हूं। आदेश जावा-सीपी swagger-codegen-cli.jar: ABCCodegen-swagger-codegen-1.0.0.jar io.swagger.codegen.Codegen -l ABCCodegen -o ./test मुझे त्रुटि देता है या नहीं मिल सका मुख्य वर्ग io.swagger.codegen.Codegen। स्वैगर Google समूह पर पोस्ट देखने के बाद, मैंने जावा-सीपी ABCCodegen-swagger-codegen-1.0.0.jar -jar swagger-codegen-cli.jar langs कमांड चलाने का प्रयास किया। हालांकि, मेरी कस्टम मॉड्यूल, एबीसी, सूची में दिखाई नहीं दे रहा है। क्या मेरे जेनरेटर के बारे में कोडजन को बताने के लिए जावा क्लास में प्रोग्रामेटिक रूप से कुछ करने की ज़रूरत है?
package com.abc.codegen;
import io.swagger.codegen.*;
import io.swagger.models.Operation;
import io.swagger.codegen.languages.*;
import java.util.*;
import java.io.File;
public class AbcCodegenGenerator extends AbstractJavaJAXRSServerCodegen {
public AbcCodegenGenerator(){
super();
sourceFolder = "src/main/java";
invokerPackage = "io.swagger.api";
artifactId = "com.abc";
outputFolder = "generated-code/ABCCodegen";
modelTemplateFiles.put("model.mustache", ".java");
//Classes for the API
apiTemplateFiles.put("api.mustache", ".java");
apiTemplateFiles.put("apiService.mustache", ".java");
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
apiPackage = "io.swagger.api";
additionalProperties.put("title", title);
//The location templates will be read from
templateDir = "src/main/resources/ABCCodegen";
//Adds ABCCodegen to the CliOptions list??
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setDefault(DEFAULT_LIBRARY);
Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
supportedLibraries.put(DEFAULT_LIBRARY, "abc");
library.setEnum(supportedLibraries);
cliOptions.add(library);
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
cliOptions.add(new CliOption("title", "a title describing the application"));
}
@Override
public String getName()
{
return "abc";
}
@Override
public String getHelp()
{
return "Generates a ABC Server application based on Jersey framework.";
}
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
if("null".equals(property.example)) {
property.example = null;
}
}
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
}
supportingFiles.clear();
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("ApiException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java"));
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiOriginFilter.java"));
supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java"));
supportingFiles.add(new SupportingFile("NotFoundException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java"));
supportingFiles.add(new SupportingFile("jacksonJsonProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JacksonJsonProvider.java"));
supportingFiles.add(new SupportingFile("BadRequestException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "BadRequestException.java"));
supportingFiles.add(new SupportingFile("JavaRestResourceUtil.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JavaRestResourceUtil.java"));
writeOptional(outputFolder, new SupportingFile("bootstrap.mustache", (implFolder + '/' + apiPackage).replace(".", "/"), "Bootstrap.java"));
writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml"));
writeOptional(outputFolder, new SupportingFile("index.mustache", ("src/main/webapp"), "index.html"));
writeOptional(outputFolder, new SupportingFile("log4j.mustache", ("conf"), "log4j.properties"));
writeOptional(outputFolder, new SupportingFile("logback.mustache", ("src/main/resources"), "logback.xml"));
if (additionalProperties.containsKey("dateLibrary")) {
setDateLibrary(additionalProperties.get("dateLibrary").toString());
additionalProperties.put(dateLibrary, "true");
}
if ("joda".equals(dateLibrary)) {
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
} else if ("java8".equals(dateLibrary)) {
supportingFiles.add(new SupportingFile("LocalDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateTimeProvider.java"));
supportingFiles.add(new SupportingFile("LocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java"));
}
}
@Override
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
String basePath = resourcePath;
if (basePath.startsWith("/")) {
basePath = basePath.substring(1);
}
int pos = basePath.indexOf("/");
if (pos > 0) {
basePath = basePath.substring(0, pos);
}
if (basePath == "") {
basePath = "default";
} else {
if (co.path.startsWith("/" + basePath)) {
co.path = co.path.substring(("/" + basePath).length());
}
co.subresourceOperation = !co.path.isEmpty();
}
List<CodegenOperation> opList = operations.get(basePath);
if (opList == null) {
opList = new ArrayList<CodegenOperation>();
operations.put(basePath, opList);
}
opList.add(co);
co.baseName = basePath;
}
public void hideGenerationTimestamp(boolean hideGenerationTimestamp) {
this.hideGenerationTimestamp = hideGenerationTimestamp;
}
}
किसी भी मदद के लिए अग्रिम धन्यवाद:
यहाँ मेरी कक्षा AbcCodegenGenerator.java है!
जेनिफर
मैं तुम्हें सुझाव है https://github.com/swagger-api/swagger-codegen/issues के माध्यम से टिकट खोलने के लिए ताकि swagger codegen समुदाय आपके लिए मदद कर सके। –