@Test public void testYAMLSerialization() throws IOException { OpenAPI openAPI = ParserTest.parse(helper, "/openapi-greeting.yml", OpenAPISupport.OpenAPIMediaType.YAML); Writer writer = new StringWriter(); Serializer.serialize(helper.types(), implsToTypes, openAPI, OpenApiSerializer.Format.YAML, writer); try (Reader reader = new StringReader(writer.toString())) { openAPI = OpenAPIParser.parse(helper.types(), reader, OpenAPISupport.OpenAPIMediaType.JSON); } Object candidateMap = openAPI.getExtensions() .get("x-my-personal-map"); assertThat(candidateMap, is(instanceOf(Map.class))); Map<?, ?> map = (Map) candidateMap; Object candidateOwnerMap = map.get("owner"); assertThat(candidateOwnerMap, is(instanceOf(Map.class))); Map<?, ?> ownerMap = (Map) candidateOwnerMap; assertThat(ownerMap.get("last"), is("Myself")); List<String> required = openAPI.getPaths().getPathItem("/greet/greeting") .getPUT() .getRequestBody() .getContent() .getMediaType("application/json") .getSchema() .getRequired(); assertThat(required, hasItem("greeting")); }
static void serialize(Map<Class<?>, ExpandedTypeDescription> types, Map<Class<?>, ExpandedTypeDescription> implsToTypes, OpenAPI openAPI, OpenApiSerializer.Format fmt, Writer writer) { if (fmt == OpenApiSerializer.Format.JSON) { serialize(types, implsToTypes, openAPI, writer, JSON_DUMPER_OPTIONS, DumperOptions.ScalarStyle.DOUBLE_QUOTED); } else { serialize(types, implsToTypes, openAPI, writer, YAML_DUMPER_OPTIONS, DumperOptions.ScalarStyle.PLAIN); } }
Serializer { static void serialize(Map<Class<?>, ExpandedTypeDescription> types, Map<Class<?>, ExpandedTypeDescription> implsToTypes, OpenAPI openAPI, OpenApiSerializer.Format fmt, Writer writer) { if (fmt == OpenApiSerializer.Format.JSON) { serialize(types, implsToTypes, openAPI, writer, JSON_DUMPER_OPTIONS, DumperOptions.ScalarStyle.DOUBLE_QUOTED); } else { serialize(types, implsToTypes, openAPI, writer, YAML_DUMPER_OPTIONS, DumperOptions.ScalarStyle.PLAIN); } } }
Serializer { static void serialize(Map<Class<?>, ExpandedTypeDescription> types, Map<Class<?>, ExpandedTypeDescription> implsToTypes, OpenAPI openAPI, OpenApiSerializer.Format fmt, Writer writer) { if (fmt == OpenApiSerializer.Format.JSON) { serialize(types, implsToTypes, openAPI, writer, JSON_DUMPER_OPTIONS, DumperOptions.ScalarStyle.DOUBLE_QUOTED); } else { serialize(types, implsToTypes, openAPI, writer, YAML_DUMPER_OPTIONS, DumperOptions.ScalarStyle.PLAIN); } } private  Serializer(); }
Serializer { static void serialize(Map<Class<?>, ExpandedTypeDescription> types, Map<Class<?>, ExpandedTypeDescription> implsToTypes, OpenAPI openAPI, OpenApiSerializer.Format fmt, Writer writer) { if (fmt == OpenApiSerializer.Format.JSON) { serialize(types, implsToTypes, openAPI, writer, JSON_DUMPER_OPTIONS, DumperOptions.ScalarStyle.DOUBLE_QUOTED); } else { serialize(types, implsToTypes, openAPI, writer, YAML_DUMPER_OPTIONS, DumperOptions.ScalarStyle.PLAIN); } } private  Serializer();  }
Serializer { static void serialize(Map<Class<?>, ExpandedTypeDescription> types, Map<Class<?>, ExpandedTypeDescription> implsToTypes, OpenAPI openAPI, OpenApiSerializer.Format fmt, Writer writer) { if (fmt == OpenApiSerializer.Format.JSON) { serialize(types, implsToTypes, openAPI, writer, JSON_DUMPER_OPTIONS, DumperOptions.ScalarStyle.DOUBLE_QUOTED); } else { serialize(types, implsToTypes, openAPI, writer, YAML_DUMPER_OPTIONS, DumperOptions.ScalarStyle.PLAIN); } } private  Serializer();   }