public OpenAPI toOpenAPI()

in oas-generator/oas-generator-core/src/main/java/org/apache/servicecomb/toolkit/generator/context/OasContext.java [67:99]


  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());
    }

    // return null if there is no restful resource
    if (openAPI.getPaths() == null || openAPI.getPaths().size() == 0) {
      return null;
    }

    openAPI.info(new Info().title("gen").version("1.0.0"));

    correctBasepath();
    correctComponents();

    openAPI.servers(Collections.singletonList(new Server().url(basePath)));
    schemaCtxList.forEach(schemaCtx -> openAPI.schema(schemaCtx.getSchema().getName(), schemaCtx.getSchema()));
    return openAPI;
  }