You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2019/06/21 07:09:27 UTC
[servicecomb-toolkit] 11/49: Optimize mustache template of code
generation
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git
commit 0f8159efe63b67ef5703e1f06ca4a2e02ce94c17
Author: MabinGo <bi...@huawei.com>
AuthorDate: Thu May 23 21:11:46 2019 +0800
Optimize mustache template of code generation
Signed-off-by: MabinGo <bi...@huawei.com>
---
.../codegen/GetGenericClassTypeLambda.java} | 70 +++---
.../toolkit/codegen/ServiceCombCodegen.java | 254 +++++++++++++++++++++
.../codegen/ServiceCombProviderCodegen.java | 151 ------------
.../services/io.swagger.codegen.CodegenConfig | 2 +-
.../README.mustache | 0
.../ServiceComb/consumer/Application.mustache | 28 +++
.../ServiceComb/consumer/apiConsumer.mustache | 65 ++++++
.../consumer/bodyParamsConsumer.mustache | 1 +
.../consumer/formParamsConsumer.mustache | 2 +
.../consumer/headerParamsConsumer.mustache | 1 +
.../consumer}/microservice.mustache | 17 +-
.../consumer/pathParamsConsumer.mustache | 1 +
.../resources/ServiceComb/consumer/pom.mustache | 91 ++++++++
.../consumer/queryParamsConsumer.mustache | 1 +
.../enumClass.mustache | 0
.../enumOuterClass.mustache | 0
.../libraries/SpringMVC/Application.mustache | 0
.../libraries/SpringMVC/api.mustache | 4 +-
.../libraries/SpringMVC/api_test.mustache | 8 +-
.../libraries/SpringMVC/bodyParams.mustache | 0
.../libraries/SpringMVC/formParams.mustache | 0
.../libraries/SpringMVC/headerParams.mustache | 0
.../libraries/SpringMVC/pathParams.mustache | 0
.../libraries/SpringMVC/pom.mustache | 29 ++-
.../libraries/SpringMVC/queryParams.mustache | 0
.../log4j2.mustache | 0
.../model}/model.mustache | 0
.../main/resources/ServiceComb/model/pom.mustache | 41 ++++
.../pojo.mustache | 2 +-
.../resources/ServiceComb/project/pom.mustache | 63 +++++
.../provider}/microservice.mustache | 9 +-
.../returnTypes.mustache | 0
.../generatedAnnotation.mustache | 1 -
.../typeInfoAnnotation.mustache | 7 -
.../ServiceCombProvider/xmlAnnotation.mustache | 6 -
.../servicecomb/toolkit/codegen/GeneratorTest.java | 20 +-
...odegenTest.java => ServiceCombCodegenTest.java} | 6 +-
.../servicecomb/toolkit/cli/CodeGenerate.java | 2 +-
.../apache/servicecomb/toolkit/cli/CliTest.java | 6 +-
39 files changed, 632 insertions(+), 256 deletions(-)
diff --git a/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegenTest.java b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/GetGenericClassTypeLambda.java
similarity index 60%
copy from code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegenTest.java
copy to code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/GetGenericClassTypeLambda.java
index 72cd210..73cdb04 100755
--- a/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegenTest.java
+++ b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/GetGenericClassTypeLambda.java
@@ -1,33 +1,37 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.servicecomb.toolkit.codegen;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.codegen.CodegenConfig;
-import io.swagger.codegen.CodegenConfigLoader;
-
-public class ServiceCombProviderCodegenTest {
-
- @Test
- public void loadImpl() {
- CodegenConfig codegenConfig = CodegenConfigLoader.forName("ServiceCombProvider");
- Assert.assertEquals(ServiceCombProviderCodegen.class, codegenConfig.getClass());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicecomb.toolkit.codegen;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import com.samskivert.mustache.Mustache;
+import com.samskivert.mustache.Template;
+
+
+public class GetGenericClassTypeLambda implements Mustache.Lambda {
+ @Override
+ public void execute(Template.Fragment fragment, Writer writer) throws IOException {
+ String text = fragment.execute();
+ if (text.contains("<")) {
+ String className = text.substring(0, text.indexOf("<"));
+ text = "(Class<" + text + ">)(Class)" + className;
+ }
+ writer.write(text);
+ }
+}
diff --git a/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java
new file mode 100755
index 0000000..c0ded7c
--- /dev/null
+++ b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicecomb.toolkit.codegen;
+
+import java.io.File;
+import java.util.Map;
+
+import io.swagger.codegen.CliOption;
+import io.swagger.codegen.CodegenConfig;
+import io.swagger.codegen.CodegenConstants;
+import io.swagger.codegen.CodegenModel;
+import io.swagger.codegen.CodegenProperty;
+import io.swagger.codegen.CodegenType;
+import io.swagger.codegen.SupportingFile;
+import io.swagger.codegen.languages.AbstractJavaCodegen;
+import io.swagger.codegen.languages.SpringCodegen;
+import io.swagger.codegen.mustache.CamelCaseLambda;
+
+public class ServiceCombCodegen extends AbstractJavaCodegen implements CodegenConfig {
+
+ private static final String DEFAULT_LIBRARY = "SpringMVC";
+
+
+ private String mainClassPackage;
+
+ private String providerProject = "provider";
+
+ private String consumerProject = "consumer";
+
+ private String modelProject = "model";
+
+ private String applicationId = "defaultApp";
+
+ private String microserviceName = "defaultService";
+
+ private String consumerTemplateFolder = "consumer";
+
+ private String providerTemplateFolder = "provider";
+
+ private String modelTemplateFolder = "model";
+
+ private String apiConsumerTemplate = consumerTemplateFolder + "/apiConsumer.mustache";
+
+ private String modelConsumerTemplate = consumerTemplateFolder + "/model.mustache";
+
+
+ private int modelSwitch = 1;
+
+
+ @Override
+ public CodegenType getTag() {
+ return CodegenType.SERVER;
+ }
+
+ @Override
+ public String getName() {
+ return "ServiceComb";
+ }
+
+ @Override
+ public String getHelp() {
+ return "Generates a ServiceComb server library.";
+ }
+
+ public ServiceCombCodegen() {
+ super();
+
+ outputFolder = "generated-code/ServiceComb";
+
+ modelDocTemplateFiles.remove("model_doc.mustache");
+ apiDocTemplateFiles.remove("api_doc.mustache");
+ apiTestTemplateFiles.remove("api_test.mustache");
+
+ embeddedTemplateDir = templateDir = "ServiceComb";
+ modelTemplateFiles.put(modelTemplateFolder + "/model.mustache", ".java");
+ modelTemplateFiles.remove("model.mustache");
+
+ groupId = "org.apache.servicecomb";
+ artifactId = "example";
+
+ apiPackage = groupId + ".example.controller";
+ modelPackage = groupId + ".example.model";
+ mainClassPackage = groupId + ".example";
+
+ supportedLibraries.put(DEFAULT_LIBRARY, "ServiceComb Server application using the springboot programming model.");
+
+ setLibrary(DEFAULT_LIBRARY);
+
+ CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
+ library.setDefault(DEFAULT_LIBRARY);
+ library.setEnum(supportedLibraries);
+ library.setDefault(DEFAULT_LIBRARY);
+ cliOptions.add(library);
+ }
+
+ @Override
+ public String modelFileFolder() {
+ return outputFolder + "/" + modelProject + "/" + sourceFolder + "/" + modelPackage().replace('.', '/');
+ }
+
+ @Override
+ public String apiFileFolder() {
+ return outputFolder + "/" + providerProject + "/" + sourceFolder + "/" + apiPackage().replace('.', '/');
+ }
+
+ @Override
+ public String apiFilename(String templateName, String tag) {
+ if (apiConsumerTemplate.equals(templateName)) {
+ String suffix = apiTemplateFiles().get(templateName);
+ return apiConsumerFolder() + File.separator + toApiFilename(tag) + suffix;
+ }
+ return super.apiFilename(templateName, tag);
+ }
+
+ private String apiConsumerFolder() {
+ return outputFolder + "/" + consumerProject + "/" + sourceFolder + "/" + apiPackage().replace('.', '/');
+ }
+
+ @Override
+ public void processOpts() {
+
+ super.processOpts();
+
+ importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
+ additionalProperties.put("dateLibrary", "java8");
+ additionalProperties.put("mainClassPackage", mainClassPackage);
+ additionalProperties.put("camelcase", new CamelCaseLambda());
+ additionalProperties.put("getGenericClassType", new GetGenericClassTypeLambda());
+ additionalProperties.put("applicationId", applicationId);
+ additionalProperties.put("microserviceName", microserviceName);
+
+ processParentProjectOpts();
+ processProviderProjectOpts();
+ processConsumerOpts();
+ processModelProjectOpts();
+ }
+
+ @Override
+ public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
+ super.postProcessModelProperty(model, property);
+ model.imports.remove("ApiModelProperty");
+ model.imports.remove("ApiModel");
+ }
+
+ private void processModelProjectOpts() {
+ supportingFiles.add(new SupportingFile("model/pom.mustache",
+ modelProject,
+ "pom.xml")
+ );
+ }
+
+ private void processParentProjectOpts() {
+
+ supportingFiles.add(new SupportingFile("project/pom.mustache",
+ "",
+ "pom.xml")
+ );
+ }
+
+ private void processProviderProjectOpts() {
+ supportingFiles.add(new SupportingFile("pom.mustache",
+ providerProject,
+ "pom.xml")
+ );
+
+ supportingFiles.add(new SupportingFile("README.mustache",
+ providerProject,
+ "README.md")
+ );
+
+ supportingFiles.add(new SupportingFile("Application.mustache",
+ mainClassFolder(providerProject),
+ "Application.java")
+ );
+
+ supportingFiles.add(new SupportingFile("log4j2.mustache",
+ resourcesFolder(providerProject),
+ "log4j2.xml")
+ );
+ supportingFiles.add(new SupportingFile(providerTemplateFolder + "/microservice.mustache",
+ resourcesFolder(providerProject),
+ "microservice.yaml")
+ );
+ apiTemplateFiles.put(apiConsumerTemplate, "Consumer.java");
+ }
+
+ private void processConsumerOpts() {
+
+ supportingFiles.add(new SupportingFile(consumerTemplateFolder + "/pom.mustache",
+ consumerProject,
+ "pom.xml")
+ );
+
+ supportingFiles.add(new SupportingFile(consumerTemplateFolder + "/Application.mustache",
+ mainClassFolder(consumerProject),
+ "Application.java")
+ );
+
+ supportingFiles.add(new SupportingFile(consumerTemplateFolder + "/microservice.mustache",
+ resourcesFolder(consumerProject),
+ "microservice.yaml")
+ );
+ }
+
+ @Override
+ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
+ objs = super.postProcessModelsEnum(objs);
+ SpringCodegen springCodegen = new SpringCodegen();
+ return springCodegen.postProcessModelsEnum(objs);
+ }
+
+ @Override
+ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
+ SpringCodegen springCodegen = new SpringCodegen();
+ return springCodegen.postProcessOperations(objs);
+ }
+
+ @Override
+ public String toApiName(String name) {
+ if (name.length() == 0) {
+ return "DefaultController";
+ }
+
+ String apiName = (String) additionalProperties.get("apiName");
+ if (apiName != null) {
+ return apiName;
+ }
+
+ return initialCaps(name) + "Controller";
+ }
+
+ private String mainClassFolder(String projectPath) {
+ return projectPath + File.separator + sourceFolder + File.separator + mainClassPackage.replace(".", File.separator);
+ }
+
+ private String resourcesFolder(String projectPath) {
+ return projectPath + File.separator + projectFolder + File.separator + "resources";
+ }
+}
\ No newline at end of file
diff --git a/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegen.java b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegen.java
deleted file mode 100755
index 4a39fc0..0000000
--- a/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegen.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.servicecomb.toolkit.codegen;
-
-import java.io.File;
-import java.util.Map;
-
-import io.swagger.codegen.CliOption;
-import io.swagger.codegen.CodegenConfig;
-import io.swagger.codegen.CodegenConstants;
-import io.swagger.codegen.CodegenType;
-import io.swagger.codegen.SupportingFile;
-import io.swagger.codegen.languages.AbstractJavaCodegen;
-import io.swagger.codegen.languages.SpringCodegen;
-import io.swagger.codegen.mustache.CamelCaseLambda;
-
-public class ServiceCombProviderCodegen extends AbstractJavaCodegen implements CodegenConfig {
-
- private static final String DEFAULT_LIBRARY = "SpringMVC";
-
- private String resourcesFolder = projectFolder + File.separator + "resources";
-
- private String mainClassPackage;
-
-
- @Override
- public CodegenType getTag() {
- return CodegenType.SERVER;
- }
-
- @Override
- public String getName() {
- return "ServiceCombProvider";
- }
-
- @Override
- public String getHelp() {
- return "Generates a ServiceComb server library.";
- }
-
- public ServiceCombProviderCodegen() {
- super();
-
- outputFolder = "generated-code/ServiceCombProvider";
-
- modelDocTemplateFiles.remove("model_doc.mustache");
- apiDocTemplateFiles.remove("api_doc.mustache");
- apiTestTemplateFiles.remove("api_test.mustache");
-
- embeddedTemplateDir = templateDir = "ServiceCombProvider";
-
- groupId = "org.apache.servicecomb";
- artifactId = "example";
-
- apiPackage = groupId + ".example.controller";
- modelPackage = groupId + ".example.model";
- mainClassPackage = groupId + ".example";
-
- supportedLibraries.put(DEFAULT_LIBRARY, "ServiceComb Server application using the springboot programming model.");
-
- setLibrary(DEFAULT_LIBRARY);
-
- CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
- library.setDefault(DEFAULT_LIBRARY);
- library.setEnum(supportedLibraries);
- library.setDefault(DEFAULT_LIBRARY);
- cliOptions.add(library);
- }
-
- @Override
- public void processOpts() {
-
- super.processOpts();
-
- importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
- additionalProperties.put("dateLibrary", "java8");
- additionalProperties.put("jackson", "true");
- additionalProperties.put("mainClassPackage", mainClassPackage);
- additionalProperties.put("camelcase", new CamelCaseLambda());
-
- supportingFiles.add(new SupportingFile("pom.mustache",
- "",
- "pom.xml")
- );
- supportingFiles.add(new SupportingFile("README.mustache",
- "",
- "README.md")
- );
-
-
- supportingFiles.add(new SupportingFile("Application.mustache",
- mainClassFolder(),
- "Application.java")
- );
-
- supportingFiles.add(new SupportingFile("log4j2.mustache",
- resourcesFolder,
- "log4j2.xml")
- );
- supportingFiles.add(new SupportingFile("microservice.mustache",
- resourcesFolder,
- "microservice.yaml")
- );
- }
-
- @Override
- public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
- objs = super.postProcessModelsEnum(objs);
- SpringCodegen springCodegen = new SpringCodegen();
- return springCodegen.postProcessModelsEnum(objs);
- }
-
- @Override
- public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
- SpringCodegen springCodegen = new SpringCodegen();
- return springCodegen.postProcessOperations(objs);
- }
-
- @Override
- public String toApiName(String name) {
- if (name.length() == 0) {
- return "DefaultController";
- }
-
- String apiName = (String) additionalProperties.get("apiName");
- if (apiName != null) {
- return apiName;
- }
-
- return initialCaps(name) + "Controller";
- }
-
- private String mainClassFolder() {
- return sourceFolder + File.separator + mainClassPackage.replace(".", File.separator);
- }
-}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/code-generator/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig
index 9e194db..75798aa 100755
--- a/code-generator/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig
+++ b/code-generator/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.servicecomb.toolkit.codegen.ServiceCombProviderCodegen
+org.apache.servicecomb.toolkit.codegen.ServiceCombCodegen
diff --git a/code-generator/src/main/resources/ServiceCombProvider/README.mustache b/code-generator/src/main/resources/ServiceComb/README.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/README.mustache
rename to code-generator/src/main/resources/ServiceComb/README.mustache
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache b/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache
new file mode 100755
index 0000000..2ee4969
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache
@@ -0,0 +1,28 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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 {{mainClassPackage}};
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ System.setProperty("local.registry.file", "notExistJustForceLocal");
+ BeanUtils.init();
+ }
+}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache
new file mode 100755
index 0000000..109d0f9
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache
@@ -0,0 +1,65 @@
+package {{apiPackage}};
+
+import {{modelPackage}}.*;
+
+{{#imports}}import {{import}};
+{{/imports}}
+
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.util.MultiValueMap;
+import org.springframework.http.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import static org.springframework.http.MediaType.*;
+
+{{#operations}}
+public class {{classname}}Consumer {
+ {{#operation}}
+
+ public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>consumer/queryParamsConsumer}}{{>consumer/pathParamsConsumer}}{{>consumer/headerParamsConsumer}}{{>consumer/bodyParamsConsumer}}{{>consumer/formParamsConsumer}}{{#hasMore}},
+ {{/hasMore}}{{/allParams}}) {
+
+ Map<String, Object> params = new HashMap<>();
+ HttpEntity httpEntity = null;
+ HttpHeaders headers = new HttpHeaders();
+ {{#allParams}}
+ {{#isPathParam}} params.put("{{paramName}}",{{paramName}}); {{/isPathParam}}
+ {{#isQueryParam}} params.put("{{paramName}}",{{paramName}}); {{/isQueryParam}}
+ {{#isHeaderParam}}
+ headers.add("{{paramName}}",{{paramName}});
+ {{/isHeaderParam}}
+ {{#isFormParam}}
+ {{#notFile}}
+ httpEntity = new HttpEntity<{{{dataType}}}>({{paramName}}, headers);
+ {{/notFile}}
+ {{#isFile}}
+ httpEntity = new HttpEntity<MultipartFile>({{paramName}}, headers);
+ {{/isFile}}
+ {{/isFormParam}}
+ {{#isBodyParam}}
+ httpEntity = new HttpEntity<{{{dataType}}}>({{paramName}}, headers);
+ {{/isBodyParam}}
+
+ {{/allParams}}
+ RestTemplate restTemplate = RestTemplateBuilder.create();
+
+ ResponseEntity<{{>returnTypes}}> result = restTemplate.exchange("cse://{{microserviceName}}/{{path}}",HttpMethod.{{httpMethod}},httpEntity,{{#getGenericClassType}}{{>returnTypes}}{{/getGenericClassType}}.class,params);
+
+ // do something
+ return result;
+ }
+
+ {{/operation}}
+ }
+{{/operations}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/bodyParamsConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/bodyParamsConsumer.mustache
new file mode 100755
index 0000000..bb1d6ff
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/bodyParamsConsumer.mustache
@@ -0,0 +1 @@
+{{#isBodyParam}} {{{dataType}}} {{paramName}}{{/isBodyParam}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache
new file mode 100755
index 0000000..6f911b1
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache
@@ -0,0 +1,2 @@
+{{#isFormParam}}{{#notFile}}
+ {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/headerParamsConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/headerParamsConsumer.mustache
new file mode 100755
index 0000000..edeeb85
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/headerParamsConsumer.mustache
@@ -0,0 +1 @@
+{{#isHeaderParam}} {{{dataType}}} {{paramName}}{{/isHeaderParam}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceCombProvider/microservice.mustache b/code-generator/src/main/resources/ServiceComb/consumer/microservice.mustache
similarity index 73%
copy from code-generator/src/main/resources/ServiceCombProvider/microservice.mustache
copy to code-generator/src/main/resources/ServiceComb/consumer/microservice.mustache
index 67ad88a..72d38b6 100755
--- a/code-generator/src/main/resources/ServiceCombProvider/microservice.mustache
+++ b/code-generator/src/main/resources/ServiceComb/consumer/microservice.mustache
@@ -15,29 +15,18 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-#More details can be found :
-# 1.http://servicecomb.apache.org/users/service-definition/
-# 2.http://servicecomb.apache.org/users/service-configurations/
-# 3.http://servicecomb.apache.org/users/communicate-protocol/
-
#Indicates an application name
-APPLICATION_ID: business
+APPLICATION_ID: {{applicationId}}
service_description:
#Indicates a microservice name
#The microservice name should be unique within an application.
#The name can contain digits, uppercase and lowercase letters, hyphens(-), underscores(_), and periods(.); and can neither start nor end with punctuations.
#The naming rule is as follows: ^[a-zA-Z0-9]+$|^[a-zA-Z0-9][a-zA-Z0-9_-.]*[a-zA-Z0-9]$.
- name: business-service
+ name: {{microserviceName}}-consumer
#Indicates a service version
version: 1.0.0
servicecomb:
service:
#Specifies the service center IP address.
registry:
- address: http://127.0.0.1:30100
- #Specifies the rest transport listening IP address.
- rest:
- address: 0.0.0.0:8080
- #Specifies the highway transport listening IP address.
- highway:
- address: 0.0.0.0:7070
\ No newline at end of file
+ address: http://127.0.0.1:30100
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/pathParamsConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/pathParamsConsumer.mustache
new file mode 100755
index 0000000..9a0630b
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/pathParamsConsumer.mustache
@@ -0,0 +1 @@
+{{#isPathParam}} {{{dataType}}} {{paramName}}{{/isPathParam}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache b/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache
new file mode 100755
index 0000000..32991a8
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache
@@ -0,0 +1,91 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>{{groupId}}</groupId>
+ <artifactId>consumer</artifactId>
+ <packaging>jar</packaging>
+ <name>{{artifactId}}</name>
+ <version>{{artifactVersion}}</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <java-chassis.version>1.2.0</java-chassis.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>${java-chassis.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>{{groupId}}</groupId>
+ <artifactId>model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>handler-bizkeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>handler-loadbalance</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>transport-highway</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>transport-rest-vertx</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>handler-flowcontrol-qps</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>provider-pojo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>provider-springmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/queryParamsConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/queryParamsConsumer.mustache
new file mode 100755
index 0000000..ff79730
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/queryParamsConsumer.mustache
@@ -0,0 +1 @@
+{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceCombProvider/enumClass.mustache b/code-generator/src/main/resources/ServiceComb/enumClass.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/enumClass.mustache
rename to code-generator/src/main/resources/ServiceComb/enumClass.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/enumOuterClass.mustache b/code-generator/src/main/resources/ServiceComb/enumOuterClass.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/enumOuterClass.mustache
rename to code-generator/src/main/resources/ServiceComb/enumOuterClass.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/Application.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/Application.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/Application.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/Application.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/api.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache
similarity index 96%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/api.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache
index d303827..5ef2b31 100755
--- a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/api.mustache
+++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache
@@ -22,7 +22,7 @@ import static org.springframework.http.MediaType.*;
@RestSchema(schemaId = "{{#camelcase}}{{classname}}{{/camelcase}}")
@RequestMapping(value = "/", produces = {APPLICATION_JSON_VALUE})
-{{>generatedAnnotation}}
+
{{#operations}}
public class {{classname}} {
{{#operation}}
@@ -33,7 +33,7 @@ public class {{classname}} {
method = RequestMethod.{{httpMethod}})
public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
{{/hasMore}}{{/allParams}}) {
- // do some magic!
+ // do something
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
}
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/api_test.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api_test.mustache
similarity index 92%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/api_test.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api_test.mustache
index 1633203..8d2d3a2 100755
--- a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/api_test.mustache
+++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api_test.mustache
@@ -72,14 +72,14 @@ public class {{classname}}ContractTest {
}
private void doTest(String path, String json) throws IOException {
- ConsumerClient consumerClient = new ConsumerClient(mockTestProvider.getUrl());
- consumerClient.options("/second");
+ Consumer consumer = new Consumer(mockTestProvider.getUrl());
+ consumer.options("/second");
try {
- consumerClient.getAsMap(path, "");
+ consumer.getAsMap(path, "");
} catch (IOException e) {
}
try {
- new ConsumerClient(mockTestProvider2.getUrl()).putAsMap("/", json);
+ new Consumer(mockTestProvider2.getUrl()).putAsMap("/", json);
} catch (IOException e) {
}
}
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/bodyParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/bodyParams.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/bodyParams.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/bodyParams.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/formParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/formParams.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/formParams.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/formParams.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/headerParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/headerParams.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/headerParams.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/headerParams.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/pathParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pathParams.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/pathParams.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pathParams.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/pom.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache
similarity index 82%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/pom.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache
index c119ee1..c0a4aad 100755
--- a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/pom.mustache
+++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache
@@ -1,29 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <artifactId>{{artifactId}}</artifactId>
+ <groupId>{{groupId}}</groupId>
+ <version>{{artifactVersion}}</version>
+ </parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>{{groupId}}</groupId>
- <artifactId>{{artifactId}}</artifactId>
+ <artifactId>provider</artifactId>
<packaging>jar</packaging>
<name>{{artifactId}}</name>
- <version>{{artifactVersion}}</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-chassis.version>1.2.0</java-chassis.version>
</properties>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>java-chassis-dependencies</artifactId>
- <version>${java-chassis.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<dependencies>
+
+ <dependency>
+ <groupId>{{groupId}}</groupId>
+ <artifactId>model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>transport-rest-vertx</artifactId>
diff --git a/code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/queryParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/queryParams.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/libraries/SpringMVC/queryParams.mustache
rename to code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/queryParams.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/log4j2.mustache b/code-generator/src/main/resources/ServiceComb/log4j2.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/log4j2.mustache
rename to code-generator/src/main/resources/ServiceComb/log4j2.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/model.mustache b/code-generator/src/main/resources/ServiceComb/model/model.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/model.mustache
rename to code-generator/src/main/resources/ServiceComb/model/model.mustache
diff --git a/code-generator/src/main/resources/ServiceComb/model/pom.mustache b/code-generator/src/main/resources/ServiceComb/model/pom.mustache
new file mode 100755
index 0000000..d52c176
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/model/pom.mustache
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <artifactId>{{artifactId}}</artifactId>
+ <groupId>{{groupId}}</groupId>
+ <version>{{artifactVersion}}</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>model</artifactId>
+ <packaging>jar</packaging>
+ <name>{{artifactId}}</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <java-chassis.version>1.2.0</java-chassis.version>
+ </properties>
+
+ <dependencies>
+ {{^isPOJO}}
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ {{/isPOJO}}
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceCombProvider/pojo.mustache b/code-generator/src/main/resources/ServiceComb/pojo.mustache
similarity index 94%
rename from code-generator/src/main/resources/ServiceCombProvider/pojo.mustache
rename to code-generator/src/main/resources/ServiceComb/pojo.mustache
index 5c3f7f3..ee0aca9 100755
--- a/code-generator/src/main/resources/ServiceCombProvider/pojo.mustache
+++ b/code-generator/src/main/resources/ServiceComb/pojo.mustache
@@ -2,7 +2,7 @@
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
*/
{{#useBeanValidation}}@Validated{{/useBeanValidation}}
-{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
+{{#discriminator}}{{/discriminator}}
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
{{#serializableModel}}
private static final long serialVersionUID = 1L;
diff --git a/code-generator/src/main/resources/ServiceComb/project/pom.mustache b/code-generator/src/main/resources/ServiceComb/project/pom.mustache
new file mode 100755
index 0000000..bca8ce9
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/project/pom.mustache
@@ -0,0 +1,63 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>{{groupId}}</groupId>
+ <artifactId>{{artifactId}}</artifactId>
+ <packaging>pom</packaging>
+ <name>{{artifactId}}</name>
+ <version>{{artifactVersion}}</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <java-chassis.version>1.2.0</java-chassis.version>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <java.version>1.8</java.version>
+ </properties>
+
+ <modules>
+ <module>provider</module>
+ <module>consumer</module>
+ <module>model</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>${java-chassis.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hibernate.validator</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.13</version>
+ <configuration>
+ <excludes>
+ <exclude>.travis.yml</exclude>
+ <exclude>**/*.md</exclude>
+ <exclude>**/target/*</exclude>
+ <!-- Skip the ssl configuration files -->
+ <exculde>**/resources/ssl/**</exculde>
+ <!-- Skip the protobuf files -->
+ <exclude>**/*.proto</exclude>
+ <!-- Skip the idl files -->
+ <exclude>**/*.idl</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceCombProvider/microservice.mustache b/code-generator/src/main/resources/ServiceComb/provider/microservice.mustache
similarity index 83%
rename from code-generator/src/main/resources/ServiceCombProvider/microservice.mustache
rename to code-generator/src/main/resources/ServiceComb/provider/microservice.mustache
index 67ad88a..fba2e77 100755
--- a/code-generator/src/main/resources/ServiceCombProvider/microservice.mustache
+++ b/code-generator/src/main/resources/ServiceComb/provider/microservice.mustache
@@ -15,19 +15,14 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-#More details can be found :
-# 1.http://servicecomb.apache.org/users/service-definition/
-# 2.http://servicecomb.apache.org/users/service-configurations/
-# 3.http://servicecomb.apache.org/users/communicate-protocol/
-
#Indicates an application name
-APPLICATION_ID: business
+APPLICATION_ID: {{applicationId}}
service_description:
#Indicates a microservice name
#The microservice name should be unique within an application.
#The name can contain digits, uppercase and lowercase letters, hyphens(-), underscores(_), and periods(.); and can neither start nor end with punctuations.
#The naming rule is as follows: ^[a-zA-Z0-9]+$|^[a-zA-Z0-9][a-zA-Z0-9_-.]*[a-zA-Z0-9]$.
- name: business-service
+ name: {{microserviceName}}
#Indicates a service version
version: 1.0.0
servicecomb:
diff --git a/code-generator/src/main/resources/ServiceCombProvider/returnTypes.mustache b/code-generator/src/main/resources/ServiceComb/returnTypes.mustache
similarity index 100%
rename from code-generator/src/main/resources/ServiceCombProvider/returnTypes.mustache
rename to code-generator/src/main/resources/ServiceComb/returnTypes.mustache
diff --git a/code-generator/src/main/resources/ServiceCombProvider/generatedAnnotation.mustache b/code-generator/src/main/resources/ServiceCombProvider/generatedAnnotation.mustache
deleted file mode 100755
index 49110fc..0000000
--- a/code-generator/src/main/resources/ServiceCombProvider/generatedAnnotation.mustache
+++ /dev/null
@@ -1 +0,0 @@
-@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceCombProvider/typeInfoAnnotation.mustache b/code-generator/src/main/resources/ServiceCombProvider/typeInfoAnnotation.mustache
deleted file mode 100755
index 09be1ca..0000000
--- a/code-generator/src/main/resources/ServiceCombProvider/typeInfoAnnotation.mustache
+++ /dev/null
@@ -1,7 +0,0 @@
-{{#jackson}}
-@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", 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}}
-}){{/jackson}}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceCombProvider/xmlAnnotation.mustache b/code-generator/src/main/resources/ServiceCombProvider/xmlAnnotation.mustache
deleted file mode 100755
index 03586da..0000000
--- a/code-generator/src/main/resources/ServiceCombProvider/xmlAnnotation.mustache
+++ /dev/null
@@ -1,6 +0,0 @@
-{{#withXml}}
-{{#jackson}}
-@JacksonXmlRootElement({{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#xmlName}}{{xmlName}}{{/xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}")
-{{/jackson}}
-@XmlRootElement({{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}name = "{{#xmlName}}{{xmlName}}{{/xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}")
-@XmlAccessorType(XmlAccessType.FIELD){{/withXml}}
\ No newline at end of file
diff --git a/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java b/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java
index e94cea4..e011c7b 100755
--- a/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java
+++ b/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java
@@ -35,14 +35,20 @@ import io.swagger.codegen.config.CodegenConfigurator;
public class GeneratorTest {
@Test
- public void generateCode() throws IOException, URISyntaxException {
+ public void generateProgrammingModels() throws IOException, URISyntaxException {
+
+ generateCode("SpringMVC");
+ }
+
+ private void generateCode(String programmingModel) throws IOException, URISyntaxException {
Path tempDir = Files.createTempDirectory(null);
Path specFilePath = Paths.get(GeneratorTest.class.getClassLoader().getResource("swagger.yaml").toURI());
CodegenConfigurator configurator = new CodegenConfigurator();
- configurator.setLang("ServiceCombProvider");
- configurator.setOutputDir(tempDir.toFile().getCanonicalPath() + "/ServiceCombProvider");
+ configurator.setLang("ServiceComb");
+ configurator.setLibrary(programmingModel);
+ configurator.setOutputDir(tempDir.toFile().getCanonicalPath() + "/ServiceComb");
configurator.setInputSpec(specFilePath.toFile().getCanonicalPath());
DefaultCodeGenerator codeGenerator = new DefaultCodeGenerator();
List<File> generatedFiles = codeGenerator.opts(configurator).generate();
@@ -50,11 +56,11 @@ public class GeneratorTest {
Object internalGenerator = ReflectUtils.getProperty(codeGenerator, "generator");
Assert.assertEquals(DefaultGenerator.class, internalGenerator.getClass());
Object swaggerCodegenConfig = ReflectUtils.getProperty(internalGenerator, "config");
- Assert.assertEquals(ServiceCombProviderCodegen.class, swaggerCodegenConfig.getClass());
- Assert.assertEquals("ServiceCombProvider", ((ServiceCombProviderCodegen) swaggerCodegenConfig).getName());
- Assert.assertEquals(CodegenType.SERVER, ((ServiceCombProviderCodegen) swaggerCodegenConfig).getTag());
+ Assert.assertEquals(ServiceCombCodegen.class, swaggerCodegenConfig.getClass());
+ Assert.assertEquals("ServiceComb", ((ServiceCombCodegen) swaggerCodegenConfig).getName());
+ Assert.assertEquals(CodegenType.SERVER, ((ServiceCombCodegen) swaggerCodegenConfig).getTag());
- Assert.assertEquals(14, generatedFiles.size());
+ Assert.assertTrue(0 < generatedFiles.size());
tempDir.toFile().deleteOnExit();
}
}
diff --git a/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegenTest.java b/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegenTest.java
similarity index 87%
rename from code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegenTest.java
rename to code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegenTest.java
index 72cd210..5846136 100755
--- a/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombProviderCodegenTest.java
+++ b/code-generator/src/test/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegenTest.java
@@ -23,11 +23,11 @@ import org.junit.Test;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConfigLoader;
-public class ServiceCombProviderCodegenTest {
+public class ServiceCombCodegenTest {
@Test
public void loadImpl() {
- CodegenConfig codegenConfig = CodegenConfigLoader.forName("ServiceCombProvider");
- Assert.assertEquals(ServiceCombProviderCodegen.class, codegenConfig.getClass());
+ CodegenConfig codegenConfig = CodegenConfigLoader.forName("ServiceComb");
+ Assert.assertEquals(ServiceCombCodegen.class, codegenConfig.getClass());
}
}
diff --git a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java
index c9bb03b..2e5da64 100755
--- a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java
+++ b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java
@@ -44,7 +44,7 @@ public class CodeGenerate implements Runnable {
@Option(name = {"-m", "--microservice-framework"}, title = "language",
description = "microservice-framework")
- private String framework = "ServiceCombProvider";
+ private String framework = "ServiceComb";
@Option(name = {"-i", "--input"}, title = "OpenAPI specification file", required = true,
description = "location of the OpenAPI specification file, as URL or file (required)")
diff --git a/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java b/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java
index c49b5d3..35885ad 100755
--- a/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java
+++ b/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java
@@ -40,7 +40,7 @@ public class CliTest {
String[] args = new String[] {
"generate",
"-m",
- "ServiceCombProvider",
+ "ServiceComb",
"-i",
Paths.get("./src/test/resources/swagger.yaml").toFile().getCanonicalPath(),
"-o",
@@ -91,13 +91,13 @@ public class CliTest {
public void generateCodeFromMultiContract() throws IOException {
Path tempDir = Files.createTempDirectory(null);
- Path tempFile = Paths.get(tempDir.toFile().getCanonicalPath() + "/ServiceCombProvider");
+ Path tempFile = Paths.get(tempDir.toFile().getCanonicalPath() + "/ServiceComb");
String[] args = new String[] {
"generate",
"-i",
Paths.get("./src/test/resources/contracts").toFile().getCanonicalPath(),
"--artifact-id",
- "ServiceCombProvider",
+ "ServiceComb",
"--group-id",
"org.apache.servicecomb.demo",
"--artifact-version",