return Results.json(Json.mapper().writer().writeValueAsBytes(swagger)); return Results.ok(Yaml.mapper().writer().writeValueAsBytes(swagger)).type("text/yml"); }); } else { return Results.json(Json.mapper().writer().writeValueAsBytes(swagger)); return Results.ok(Yaml.mapper().writer().writeValueAsBytes(swagger)).type("text/yml"); });
private static Swagger internalParseSwagger(String swaggerContent) throws JsonParseException, JsonMappingException, IOException { Swagger swagger = Yaml.mapper().readValue(swaggerContent, Swagger.class); correctResponses(swagger); return swagger; }
public static String swaggerToString(Swagger swagger) { try { return Yaml.mapper().writeValueAsString(swagger); } catch (Throwable e) { throw new ServiceCombException("Convert swagger to string failed, ", e); } }
public static Swagger parse(String content) { try { return Yaml.mapper().readValue(content, Swagger.class); } catch (Exception e) { return new Swagger(); // throw new Error(e); } }
public OpenApiNormalizer of(Swagger spec) throws JsonProcessingException { this.spec = Yaml.mapper().writeValueAsString(spec); return this; }
@Override public byte[] writeMessageBody(Object t) { try { return Yaml.mapper().writeValueAsBytes(t); } catch (JsonProcessingException ex) { LogUtils.error(ex.getMessage(), ex); } return null; }
private static Swagger internalParseSwagger(String swaggerContent) throws JsonParseException, JsonMappingException, IOException { Swagger swagger = Yaml.mapper().readValue(swaggerContent, Swagger.class); correctResponses(swagger); return swagger; }
/** * Creates a Swagger schema validator based on the given YAML-based Swagger spec. * * @param swaggerSpec the Swagger spec (in YAML format) * @return a validator for that spec * @throws IOException if the Swagger spec is not a valid YAML object */ public static SwaggerValidator forYamlSchema(Reader swaggerSpec) throws IOException { return new SwaggerValidator(Yaml.mapper().readTree(swaggerSpec)); }
public static Swagger parse(String content) { try { return Yaml.mapper().readValue(content, Swagger.class); } catch (Exception e) { return new Swagger(); // throw new Error(e); } }
public static String swaggerToString(Swagger swagger) { try { return Yaml.mapper().writeValueAsString(swagger); } catch (Throwable e) { throw new ServiceCombException("Convert swagger to string failed, ", e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object readMessageBody(InputStream in, Type type) { try { return Yaml.mapper().readValue(in, (Class) type); } catch (IOException ex) { LogUtils.error(ex.getMessage(), ex); } return null; } }
protected String getYamlFileContentAsJson() throws IOException { String data = ""; if (yamlInputPath.startsWith("http") || yamlInputPath.startsWith("https")) { data = new String(Resources.toByteArray(new URL(yamlInputPath))); } else { data = new String(Files.readAllBytes(java.nio.file.Paths.get(new File(yamlInputPath).toURI()))); } ObjectMapper yamlMapper = Yaml.mapper(); JsonNode rootNode = yamlMapper.readTree(data); // must have swagger node set JsonNode swaggerNode = rootNode.get("swagger"); return rootNode.toString(); }
@Override public void writeTo(Example data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException { if (mediaType.toString().startsWith("application/yaml")) { headers.remove("Content-Type"); headers.add("Content-Type", "application/yaml"); out.write(Yaml.mapper().writeValueAsString(data).getBytes("utf-8")); } } }
@Override public void writeTo(Example data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException { if (mediaType.toString().startsWith("application/yaml")) { headers.remove("Content-Type"); headers.add("Content-Type", "application/yaml"); out.write(Yaml.mapper().writeValueAsString(data).getBytes("utf-8")); } } }
/** * Convert given API definition in YAML format. * @param api The API model to serialize * @param pretty Whether to pretty format the output * @return The API definition as YAML */ static String asYaml(Swagger api, boolean pretty) { try { return pretty ? Yaml.pretty().writeValueAsString(api) : Yaml.mapper().writeValueAsString(api); } catch (Exception e) { throw new ApiConfigurationException(e); } }
@SuppressWarnings("deprecation") public SwaggerService() { mapper = Json.mapper(); writer = mapper.writerWithDefaultPrettyPrinter(); writer = writer.without(SerializationFeature.WRITE_NULL_MAP_VALUES); yamlMapper = Yaml.mapper(); }
@Override protected String getApiOutput(OutputType outputType, Swagger api, boolean pretty) throws Exception { switch (outputType) { case YAML: return pretty ? Yaml.pretty().writeValueAsString(api) : Yaml.mapper().writeValueAsString(api); case JSON: default: return pretty ? Json.pretty(api) : Json.mapper().writeValueAsString(api); } }
public static Configuration read(String configLocation) throws Exception { Configuration config = Yaml.mapper().readValue(new File(configLocation), Configuration.class); if(config != null && config.getExceptionMappers().size() == 0) { config.setExceptionMappers(Configuration.defaultConfiguration().getExceptionMappers()); } String environment = System.getProperty("environment"); if(environment != null) { System.out.println("Overriding environment to " + environment); config.setEnvironment(Environment.valueOf(environment)); } return config; }
public static Configuration read(String configLocation) throws Exception { Configuration config = Yaml.mapper().readValue(new File(configLocation), Configuration.class); if(config != null && config.getExceptionMappers().size() == 0) { config.setExceptionMappers(Configuration.defaultConfiguration().getExceptionMappers()); } String environment = System.getProperty("environment"); if(environment != null) { System.out.println("Overriding environment to " + environment); config.setEnvironment(Environment.valueOf(environment)); } return config; }
@Override public Object process(MediaType mediaType, InputStream entityStream, JavaType javaType) { try { if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) { return Json.mapper().readValue(entityStream, javaType); } if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) { return XML.readValue(entityStream, javaType); } if (APPLICATION_YAML_TYPE.isCompatible(mediaType)) { return Yaml.mapper().readValue(entityStream, javaType); } } catch (IOException e) { LOGGER.error("unable to extract entity from content-type `" + mediaType + "` to " + javaType.toCanonical(), e); } return null; }