/** * Builds a path operation. * * @param markupDocBuilder the docbuilder do use for output * @param operation the Swagger Operation */ private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, PathOperation operation) { if (operation != null) { pathOperationComponent.apply(markupDocBuilder, PathOperationComponent.parameters(operation)); } }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
/** * Builds a path operation. * * @param markupDocBuilder the docbuilder do use for output * @param operation the Swagger Operation */ private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, PathOperation operation) { if (operation != null) { pathOperationComponent.apply(markupDocBuilder, PathOperationComponent.parameters(operation)); } }
/** * Builds a path operation. * * @param markupDocBuilder the docbuilder do use for output * @param operation the Swagger Operation */ private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, PathOperation operation) { if (operation != null) { pathOperationComponent.apply(markupDocBuilder, PathOperationComponent.parameters(operation)); } }