gpt4 book ai didi

io.swagger.util.Yaml.mapper()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 00:26:40 30 4
gpt4 key购买 nike

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

Yaml.mapper介绍

暂无

代码示例

代码示例来源:origin: jooby-project/jooby

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");
 });

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

private static Swagger internalParseSwagger(String swaggerContent)
  throws JsonParseException, JsonMappingException, IOException {
 Swagger swagger = Yaml.mapper().readValue(swaggerContent, Swagger.class);
 correctResponses(swagger);
 return swagger;
}

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

public static String swaggerToString(Swagger swagger) {
 try {
  return Yaml.mapper().writeValueAsString(swagger);
 } catch (Throwable e) {
  throw new ServiceCombException("Convert swagger to string failed, ", e);
 }
}

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

public static Swagger parse(String content) {
 try {
  return Yaml.mapper().readValue(content, Swagger.class);
 } catch (Exception e) {
  return new Swagger();
  //            throw new Error(e);
 }
}

代码示例来源:origin: com.reprezen.genflow/genflow-api

public OpenApiNormalizer of(Swagger spec) throws JsonProcessingException {
  this.spec = Yaml.mapper().writeValueAsString(spec);
  return this;
}

代码示例来源:origin: javagossip/dorado

@Override
public byte[] writeMessageBody(Object t) {
  try {
    return Yaml.mapper().writeValueAsBytes(t);
  } catch (JsonProcessingException ex) {
    LogUtils.error(ex.getMessage(), ex);
  }
  return null;
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-core

private static Swagger internalParseSwagger(String swaggerContent)
  throws JsonParseException, JsonMappingException, IOException {
 Swagger swagger = Yaml.mapper().readValue(swaggerContent, Swagger.class);
 correctResponses(swagger);
 return swagger;
}

代码示例来源:origin: com.github.bjansen/swagger-schema-validator

/**
 * 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));
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-core

public static Swagger parse(String content) {
 try {
  return Yaml.mapper().readValue(content, Swagger.class);
 } catch (Exception e) {
  return new Swagger();
  //            throw new Error(e);
 }
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-core

public static String swaggerToString(Swagger swagger) {
 try {
  return Yaml.mapper().writeValueAsString(swagger);
 } catch (Throwable e) {
  throw new ServiceCombException("Convert swagger to string failed, ", e);
 }
}

代码示例来源:origin: javagossip/dorado

@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;
  }
}

代码示例来源:origin: org.zalando.stups/swagger-codegen-common

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();
}

代码示例来源:origin: swagger-api/swagger-inflector

@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"));
   }
  }
}

代码示例来源:origin: io.swagger/swagger-inflector

@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"));
   }
  }
}

代码示例来源:origin: com.holon-platform.jaxrs/holon-jaxrs-swagger-v2

/**
 * 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);
  }
}

代码示例来源:origin: noboomu/proteus

@SuppressWarnings("deprecation")
public SwaggerService()
{
  mapper = Json.mapper();
  writer = mapper.writerWithDefaultPrettyPrinter();
  writer = writer.without(SerializationFeature.WRITE_NULL_MAP_VALUES);
  yamlMapper = Yaml.mapper();
}

代码示例来源:origin: com.holon-platform.jaxrs/holon-jaxrs-swagger-v2

@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);
  }
}

代码示例来源:origin: io.swagger/swagger-inflector

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;
}

代码示例来源:origin: swagger-api/swagger-inflector

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;
}

代码示例来源:origin: swagger-api/swagger-inflector

@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;
}

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com