chanjarster commented on a change in pull request #38: SCB-1547 add 
oas-generator to generate openapi v3
URL: https://github.com/apache/servicecomb-toolkit/pull/38#discussion_r344434485
 
 

 ##########
 File path: 
oas-generator/oas-generator-core/src/main/java/org/apache/servicecomb/toolkit/generator/OasContext.java
 ##########
 @@ -0,0 +1,151 @@
+/*
+ * 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.generator;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import 
org.apache.servicecomb.toolkit.generator.parser.api.OpenApiAnnotationParser;
+
+import io.swagger.v3.oas.models.Components;
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.PathItem;
+import io.swagger.v3.oas.models.PathItem.HttpMethod;
+import io.swagger.v3.oas.models.Paths;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.servers.Server;
+
+public class OasContext {
+
+  private OpenAPI openAPI;
+
+  private String basePath;
+
+  private Class<?> cls;
+
+  private List<OperationContext> operationList = new ArrayList<>();
+
+  private OpenApiAnnotationParser parser;
+
+  public OasContext(OpenApiAnnotationParser parser) {
+    this(new OpenAPI(), parser);
+  }
+
+  public OasContext(OpenAPI openAPI, OpenApiAnnotationParser parser) {
+    this.openAPI = openAPI;
+    this.parser = parser;
+  }
+
+  public OpenAPI toOpenAPI() {
+    ensurePaths();
+    for (OperationContext operationCtx : operationList) {
+      if (!operationCtx.hasOperation()) {
+        continue;
+      }
+
+      if (openAPI.getPaths() == null) {
+        openAPI.setPaths(new Paths());
+      }
+
+      PathItem pathItem = openAPI.getPaths().get(operationCtx.getPath());
+      if (pathItem == null) {
+        pathItem = new PathItem();
+        openAPI.path(operationCtx.getPath(), pathItem);
+      }
+      pathItem.operation(HttpMethod.valueOf(operationCtx.getHttpMethod()), 
operationCtx.toOperation());
+    }
+
+    // 如果没有restful资源则返回null
 
 Review comment:
   Chinese comment, translate to english will be better

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to