gpt4 book ai didi

io.swagger.util.Yaml类的使用及代码示例

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

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

Yaml介绍

暂无

代码示例

代码示例来源: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: kongchen/swagger-maven-plugin

public void toSwaggerDocuments(String uiDocBasePath, String outputFormats, String fileName, String encoding) throws GenerateException {
  mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
  mapper = mapper.copy();
    mapper.addMixInAnnotations(Property.class, PropertyExampleMixIn.class);
          break;
        case yaml:
          FileUtils.write(new File(dir, fileName + ".yaml"), Yaml.pretty().writeValueAsString(swagger), encoding);
          break;

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

final ObjectWriter mapper = Json.pretty();
String content = mapper.writeValueAsString(swagger);
final ObjectMapper tempMapper = new ObjectMapper();
final ObjectNode jsonSchemasDefinitionsNode = this.jsonSchemaGenerator.generateDefinitionsNode(model, templateParam);
JsonNode _readTree = tempMapper.readTree(content);
final JsonNode swaggerNode = ((ObjectNode) _readTree).set("definitions", jsonSchemasDefinitionsNode);
Object _xifexpression = null;
boolean _equals = Objects.equal(_string, format);
if (_equals) {
 final ObjectMapper swaggerYamlMapper = Yaml.mapper();
 Object _get_1 = null;
 if (templateParam!=null) {
  opts.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
  final org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(opts);
  return yaml.dump(new ObjectMapper().<Object>convertValue(swaggerNode, Object.class));
 return swaggerYamlMapper.writeValueAsString(swaggerNode);

代码示例来源: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: 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: io.swagger/swagger-parser

public static <T> T deserialize(Object contents, String fileOrHost, Class<T> expectedType) {
  T result;
  boolean isJson = false;
  if(contents instanceof String && isJson((String)contents)) {
    isJson = true;
  }
  try {
    if (contents instanceof String) {
      if (isJson) {
        result = Json.mapper().readValue((String) contents, expectedType);
      } else {
        result = Yaml.mapper().readValue((String) contents, expectedType);
      }
    } else {
      result = Json.mapper().convertValue(contents, expectedType);
    }
  } catch (Exception e) {
    throw new RuntimeException("An exception was thrown while trying to deserialize the contents of " + fileOrHost + " into type " + expectedType, e);
  }
  return result;
}

代码示例来源: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: swagger-api/swagger-inflector

if ("json".equalsIgnoreCase(item)) {
  getObjectMapper().registerModule(simpleModule);
  register(JacksonJsonProvider.class);
  register(JsonExampleProvider.class);
  if(!getObjectMapper().isEnabled(SerializationFeature.INDENT_OUTPUT))
} else if ("yaml".equalsIgnoreCase(item)) {
  Yaml.mapper().registerModule(simpleModule);
  register(YamlExampleProvider.class);
  enableProcessor(JacksonProcessor.class, JacksonProcessor.APPLICATION_YAML_TYPE);

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

router.get(options.path + "/swagger.json", options.path + "/swagger.yml", req -> {
  Map<String, Object> hash = conf.getConfig("swagger").root().unwrapped();
  Swagger base = Json.mapper().convertValue(hash, Swagger.class);
  Swagger swagger = new SwaggerBuilder(options.tagger)
    .build(base, provider.apply(req.require(M)));
   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: 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: io.swagger/swagger-jaxrs

out.write(Json.pretty().writeValueAsBytes(data));
} else {
  out.write(Json.mapper().writeValueAsBytes(data));
headers.add("Content-Type", "application/yaml");
if (prettyPrint) {
  out.write(Yaml.pretty().writeValueAsBytes(data));
} else {
  out.write(Yaml.mapper().writeValueAsBytes(data));
  out.write(Json.pretty().writeValueAsBytes(data));
} else {
  out.write(Json.mapper().writeValueAsBytes(data));

代码示例来源:origin: apache/cxf

writer = new BufferedWriter(new FileWriter(outputFile));
if ("json".equals(this.payload)) {
  ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter());
  writer.write(jsonWriter.writeValueAsString(swagger));
} else if ("yaml".equals(this.payload)) {
  writer.write(Yaml.pretty().writeValueAsString(swagger));

代码示例来源: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: blox/blox

@TaskAction
public void generateSpec() throws IOException, GenerateException {
 ClassLoader loader = projectClassLoader();
 Set<Class<?>> classes = new HashSet<>();
 for (String pkg : apiPackages) {
  Reflections reflections =
    new Reflections(
      new ConfigurationBuilder()
        .addClassLoaders(loader)
        .addUrls(ClasspathHelper.forPackage(pkg, loader))
        .setExpandSuperTypes(false)
        .filterInputsBy(new FilterBuilder().includePackage(pkg)));
  Set<Class<?>> springMVCClasses =
    reflections.getTypesAnnotatedWith(
      org.springframework.web.bind.annotation.RestController.class);
  classes.addAll(springMVCClasses);
 }
 SpringMvcApiReader reader = new SpringMvcApiReader(new Swagger(), log);
 Swagger swagger = reader.read(classes);
 for (SwaggerFilter filter : filters) {
  filter.apply(swagger);
 }
 Yaml.pretty().writeValue(swaggerFile, swagger);
}

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

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

代码示例来源: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: 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: io.swagger/swagger-inflector

if ("json".equalsIgnoreCase(item)) {
  getObjectMapper().registerModule(simpleModule);
  register(JacksonJsonProvider.class);
  register(JsonExampleProvider.class);
  if(!getObjectMapper().isEnabled(SerializationFeature.INDENT_OUTPUT))
} else if ("yaml".equalsIgnoreCase(item)) {
  Yaml.mapper().registerModule(simpleModule);
  register(YamlExampleProvider.class);
  enableProcessor(JacksonProcessor.class, JacksonProcessor.APPLICATION_YAML_TYPE);

代码示例来源:origin: org.jooby/jooby-apitool

router.get(options.path + "/swagger.json", options.path + "/swagger.yml", req -> {
  Map<String, Object> hash = conf.getConfig("swagger").root().unwrapped();
  Swagger base = Json.mapper().convertValue(hash, Swagger.class);
  Swagger swagger = new SwaggerBuilder(options.tagger)
    .build(base, provider.apply(req.require(M)));
   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: org.jooby/jooby-swagger

/**
 * Publish application routes as Swagger spec.
 *
 * @param app An application.
 */
public void install(final Jooby app) {
 requireNonNull(app, "Application is required.");
 ObjectMapper mapper = Json.mapper();
 ObjectWriter yaml = Yaml.pretty();
 app.use(new SwaggerModule(mapper));
 app.get(path + "/swagger.json", path + "/:tag/swagger.json", req -> {
  SwaggerBuilder sb = req.require(SwaggerBuilder.class);
  Swagger swagger = sb.build(req.param("tag").toOptional(), predicate, tag, Swagger.class);
  byte[] json = mapper.writer().withDefaultPrettyPrinter().writeValueAsBytes(swagger);
  return Results.json(json);
 }).name("swagger(json)");
 app.get(path + "/swagger.yml", path + "/:tag/swagger.yml", req -> {
  SwaggerBuilder sb = req.require(SwaggerBuilder.class);
  Swagger swagger = sb.build(req.param("tag").toOptional(), predicate, tag, SwaggerYml.class);
  byte[] yml = yaml.writeValueAsBytes(swagger);
  return Results.ok(yml).type("application/yaml");
 }).name("swagger(yml)");
 if (ui) {
  app.assets(path + "/ui/**",
    "/META-INF/resources/webjars/swagger-ui/" + wjversion(app.getClass()) + "/{0}");
  app.get(path, path + "/:tag", new SwaggerHandler(path))
    .name("swagger(html)")
    .produces(MediaType.html);
 }
}

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