### Question:
SerializerUtils { public static String toYamlString(OpenAPI openAPI) { if (openAPI == null) { return null; } SimpleModule module = createModule(); try { ObjectMapper yamlMapper = Yaml.mapper().copy(); if (minimizeYamlQuotes) { ((YAMLFactory) yamlMapper.getFactory()).enable(YAMLGenerator.Feature.MINIMIZE_QUOTES); } else { ((YAMLFactory) yamlMapper.getFactory()).disable(YAMLGenerator.Feature.MINIMIZE_QUOTES); } return yamlMapper.registerModule(module) .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) .writeValueAsString(openAPI) .replace("\r\n", "\n"); } catch (JsonProcessingException e) { LOGGER.warn("Can not create yaml content", e); } return null; }  static String toYamlString(OpenAPI openAPI); static String toJsonString(OpenAPI openAPI);  }### Answer:
@Test public void testToYamlStringCompleteExample() throws Exception { OpenAPI openAPI = createCompleteExample(); String content = SerializerUtils.toYamlString(openAPI); String expected = "openapi: 3.0.1\n" + "info:\n" + " description: Some description\n" + " title: Some title\n" + "externalDocs:\n" + " description: a-description\n" + " url: http: "servers:\n" + "- description: first server\n" + " url: http: "- description: second server\n" + " url: http: "security:\n" + "- some_auth:\n" + " - write\n" + " - read\n" + "tags:\n" + "- description: some 1 description\n" + " name: tag1\n" + "- description: some 2 description\n" + " name: tag2\n" + "- description: some 3 description\n" + " name: tag3\n" + "paths:\n" + " /ping/pong:\n" + " get:\n" + " description: Some description\n" + " operationId: pingOp\n" + " responses:\n" + " \"200\":\n" + " description: Ok\n" + "components:\n" + " schemas:\n" + " SomeObject:\n" + " description: An Obj\n" + " properties:\n" + " id:\n" + " type: string\n" + " type: object\n" + "x-custom: value1\n" + "x-other: value2\n"; assertEquals(content, expected); }
@Test public void testToYamlStringMinimalExample() throws Exception { OpenAPI openAPI = createMinimalExample(); String content = SerializerUtils.toYamlString(openAPI); String expected = "openapi: 3.0.1\n" + "info:\n" + " title: Some title\n" + "servers:\n" + "- url: http: "paths:\n" + " /ping/pong:\n" + " get:\n" + " description: Some description\n" + " operationId: pingOp\n" + " responses:\n" + " \"200\":\n" + " description: Ok\n"; assertEquals(content, expected); }