io.swagger.models.Swagger.getPaths()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.8k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中io.swagger.models.Swagger.getPaths()方法的一些代码示例,展示了Swagger.getPaths()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Swagger.getPaths()方法的具体详情如下:
包路径:io.swagger.models.Swagger
类名称:Swagger
方法名:getPaths

Swagger.getPaths介绍

暂无

代码示例

代码示例来源:origin: blox/blox

@Override
 public void apply(Swagger swagger) {
  if (swagger.getDefinitions() != null) {
   swagger.setDefinitions(new TreeMap<>(swagger.getDefinitions()));
  }

  if (swagger.getPaths() != null) {
   swagger.setPaths(new TreeMap<>(swagger.getPaths()));
  }
 }
}

代码示例来源:origin: blox/blox

@Override
public void apply(Swagger swagger) {
 Map<String, Object> extensions = defaultExtensions();
 for (Path path : swagger.getPaths().values()) {
  for (Operation operation : path.getOperations()) {
   operation.setVendorExtension("x-amazon-apigateway-integration", extensions);
  }
 }
}

代码示例来源:origin: blox/blox

@Override
 public void apply(Swagger swagger) {
  ApiKeyAuthDefinition authorization = new ApiKeyAuthDefinition("Authorization", In.HEADER);
  authorization.setVendorExtension("x-amazon-apigateway-authtype", authType);
  swagger.securityDefinition(SECURITY_SCHEME_NAME, authorization);

  for (Path path : swagger.getPaths().values()) {
   for (Operation operation : path.getOperations()) {
    operation.addSecurity(SECURITY_SCHEME_NAME, Collections.emptyList());
   }
  }
 }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

private MarkupDocBuilder applyPathsDocument() {
  return pathsDocument.apply(
      context.createMarkupDocBuilder(),
      PathsDocument.parameters(context.getSwagger().getPaths()));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

public void apply(Swagger swagger) {
    swagger.setHost("newHostName"); //<1>
    swagger.basePath("newBasePath");

    Map<String, Path> paths = swagger.getPaths(); //<2>
    paths.remove("/remove");
    swagger.setPaths(paths);
  }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

Swagger swagger = context.getSwagger();
io.swagger.models.Path path = swagger.getPaths().get("/LaunchCommand");
List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", path);

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
  public void testResponsesComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(ResponsesComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSwagger();

    io.swagger.models.Path path = swagger.getPaths().get("/pets/findByStatus");
    List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets/findByStatus", path);

    Swagger2MarkupConverter.Context context = converter.getContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    //When
    markupDocBuilder = new ResponseComponent(context, new DefinitionDocumentResolverFromOperation(context))
        .apply(markupDocBuilder, ResponseComponent.parameters(pathOperations.get(0), 3, new ArrayList<>()));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

  }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
  public void testParameterTableComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(ParameterTableComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSwagger();

    io.swagger.models.Path path = swagger.getPaths().get("/pets");
    List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets", path);

    Swagger2MarkupConverter.Context context = converter.getContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    //When
    markupDocBuilder = new ParameterTableComponent(context, new DefinitionDocumentResolverFromOperation(context))
        .apply(markupDocBuilder, ParameterTableComponent.parameters(pathOperations.get(0), new ArrayList<>(), 3));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

  }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testInlineSchema() throws URISyntaxException {
  String COMPONENT_NAME = "path_operation_inline_schema";
  Path outputDirectory = getOutputFile(COMPONENT_NAME);
  FileUtils.deleteQuietly(outputDirectory.toFile());
  //Given
  Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI());
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
  Swagger swagger = converter.getContext().getSwagger();
  io.swagger.models.Path path = swagger.getPaths().get("/LaunchCommand");
  List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", path);
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  //When
  markupDocBuilder = new PathOperationComponent(context,
      new DefinitionDocumentResolverFromOperation(context),
      new SecurityDocumentResolver(context)).
      apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
  markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
  //Then
  Path expectedFile = getExpectedFile(COMPONENT_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testWithPathParamExample() throws URISyntaxException {
  String COMPONENT_NAME = "path_operation_with_path_param_example";
  Path outputDirectory = getOutputFile(COMPONENT_NAME);
  FileUtils.deleteQuietly(outputDirectory.toFile());
  Map<String, String> configMap = new HashMap<>();
  configMap.put("swagger2markup.generatedExamplesEnabled", "true");  // enable example
  //Given
  Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
  Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
  Swagger swagger = converter.getContext().getSwagger();
  io.swagger.models.Path path = swagger.getPaths().get("/pets/{petId}");
  List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets/{petId}", path);
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  //When
  markupDocBuilder = new PathOperationComponent(context,
      new DefinitionDocumentResolverFromOperation(context),
      new SecurityDocumentResolver(context)).
      apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
  markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
  //Then
  Path expectedFile = getExpectedFile(COMPONENT_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testWithQueryParamExample() throws URISyntaxException {
  String COMPONENT_NAME = "path_operation_with_query_param_example";
  Path outputDirectory = getOutputFile(COMPONENT_NAME);
  FileUtils.deleteQuietly(outputDirectory.toFile());
  Map<String, String> configMap = new HashMap<>();
  configMap.put("swagger2markup.generatedExamplesEnabled", "true");  // enable example
  //Given
  Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
  Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
  Swagger swagger = converter.getContext().getSwagger();
  io.swagger.models.Path path = swagger.getPaths().get("/pets/findByTags");
  List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets/findByTags", path);
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  //When
  markupDocBuilder = new PathOperationComponent(context,
      new DefinitionDocumentResolverFromOperation(context),
      new SecurityDocumentResolver(context)).
      apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
  markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
  //Then
  Path expectedFile = getExpectedFile(COMPONENT_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testWithBodyParamExample() throws URISyntaxException {
  String COMPONENT_NAME = "path_operation_with_body_param_example";
  Path outputDirectory = getOutputFile(COMPONENT_NAME);
  FileUtils.deleteQuietly(outputDirectory.toFile());
  Map<String, String> configMap = new HashMap<>();
  configMap.put("swagger2markup.generatedExamplesEnabled", "true");  // enable example
  //Given
  Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore_body_examples.yaml").toURI());
  Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
  Swagger swagger = converter.getContext().getSwagger();
  io.swagger.models.Path path = swagger.getPaths().get("/users");
  List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/users", path);
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  //When
  markupDocBuilder = new PathOperationComponent(context,
      new DefinitionDocumentResolverFromOperation(context),
      new SecurityDocumentResolver(context)).
      apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
  markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
  //Then
  Path expectedFile = getExpectedFile(COMPONENT_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testPathOperationComponent() throws URISyntaxException {
  String COMPONENT_NAME = "path_operation";
  Path outputDirectory = getOutputFile(COMPONENT_NAME);
  FileUtils.deleteQuietly(outputDirectory.toFile());
  //Given
  Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
  Swagger swagger = converter.getContext().getSwagger();
  io.swagger.models.Path path = swagger.getPaths().get("/pets");
  List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets", path);
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  //When
  markupDocBuilder = new PathOperationComponent(context,
      new DefinitionDocumentResolverFromOperation(context),
      new SecurityDocumentResolver(context)).
      apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
  markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
  //Then
  Path expectedFile = getExpectedFile(COMPONENT_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
  public void testBodyParameterComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withFlatBody().build();
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config).build();
    Swagger swagger = converter.getContext().getSwagger();

    io.swagger.models.Path path = swagger.getPaths().get("/pets");
    List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets", path);

    Swagger2MarkupConverter.Context context = converter.getContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    //When
    markupDocBuilder = new BodyParameterComponent(converter.getContext(),
        new DefinitionDocumentResolverFromOperation(context))
        .apply(markupDocBuilder, BodyParameterComponent.parameters(pathOperations.get(0), new ArrayList<>()));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

  }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
  public void testSecuritySchemeComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(SecuritySchemeComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSwagger();

    List<PathOperation> pathOperations = PathUtils.toPathOperationsList(swagger.getPaths(), "",
        converter.getContext().getConfig().getOperationOrdering());

    Swagger2MarkupConverter.Context context = converter.getContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    //When
    markupDocBuilder = new SecuritySchemeComponent(context, new SecurityDocumentResolver(context))
        .apply(markupDocBuilder, SecuritySchemeComponent.parameters(pathOperations.get(0), 3));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

  }
}

代码示例来源:origin: apache/servicecomb-java-chassis

public static void correctResponses(Swagger swagger) {
  if (swagger.getPaths() == null) {
   return;
  }

  for (Path path : swagger.getPaths().values()) {
   for (Operation operation : path.getOperations()) {
    correctResponses(operation);
   }
  }
 }
}

代码示例来源:origin: kongchen/swagger-maven-plugin

protected Swagger removeBasePathFromEndpoints(Swagger swagger, boolean removeBasePathFromEndpoints) {
  Swagger result = swagger;
  if (!removeBasePathFromEndpoints) {
    return result;
  }
  String basePath = swagger.getBasePath();
  if (isEmpty(basePath)) {
    return result;
  }
  Map<String, Path> oldPathMap = result.getPaths();
  Map<String, Path> newPathMap = new HashMap<String, Path>();
  for (Map.Entry<String, Path> entry: oldPathMap.entrySet()) {
    newPathMap.put(entry.getKey().replace(basePath, ""), entry.getValue());
  }
  result.setPaths(newPathMap);
  return result;
}

代码示例来源:origin: apache/servicecomb-java-chassis

public List<Parameter> findSwaggerParameter(String methodName) {
 for (Path path : swagger.getPaths().values()) {
  for (Operation operation : path.getOperations()) {
   if (methodName.equals(operation.getOperationId())) {
    return operation.getParameters();
   }
  }
 }
 throw new Error("method not found, name=" + methodName);
}

代码示例来源:origin: apache/servicecomb-java-chassis

private void convertOperations() {
 Map<String, Path> paths = swagger.getPaths();
 if (paths == null || paths.isEmpty()) {
  return;
 }
 appendLine(serviceBuilder, "service MainService {");
 for (Path path : paths.values()) {
  for (Operation operation : path.getOperationMap().values()) {
   convertOperation(operation);
  }
 }
 serviceBuilder.setLength(serviceBuilder.length() - 1);
 appendLine(serviceBuilder, "}");
}

代码示例来源:origin: apache/servicecomb-java-chassis

protected void convertResponses() {
 if (swagger.getPaths() == null) {
  return;
 }
 for (Path path : swagger.getPaths().values()) {
  for (Operation operation : path.getOperations()) {
   for (Response response : operation.getResponses().values()) {
    convert(response.getSchema());
    Map<String, Property> headers = response.getHeaders();
    if (headers == null) {
     continue;
    }
    for (Property header : headers.values()) {
     convert(header);
    }
   }
  }
 }
}

相关文章