当前位置: 首页>>代码示例>>Java>>正文


Java Yaml类代码示例

本文整理汇总了Java中io.swagger.util.Yaml的典型用法代码示例。如果您正苦于以下问题:Java Yaml类的具体用法?Java Yaml怎么用?Java Yaml使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Yaml类属于io.swagger.util包,在下文中一共展示了Yaml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getListingYaml

import io.swagger.util.Yaml; //导入依赖的package包/类
@GET
@Produces("application/yaml")
@Path("/swagger.yaml")
@ApiOperation(value = "The swagger definition in YAML", hidden = true)
public Response getListingYaml(
        @Context Application app,
        //@Context ServletConfig sc,
        @Context HttpHeaders headers,
        @Context UriInfo uriInfo) {
    try {
        String yaml = Yaml.mapper().writeValueAsString(getSwaggerWithClasses());
        String[] parts = yaml.split("\n");
        StringBuilder b = new StringBuilder();
        for (String part : parts) {
            int pos = part.indexOf("!<");
            int endPos = part.indexOf(">");
            b.append(part);
            b.append("\n");
        }
        return Response.ok().entity(b.toString()).type("application/yaml").build();
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return Response.status(404).build();
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:26,代码来源:BaseSwaggerRestProvider.java

示例2: testReadJson

import io.swagger.util.Yaml; //导入依赖的package包/类
public static void testReadJson() {
	Swagger swagger = read("http://petstore.swagger.io/v2/swagger.json");
	if (swagger != null) {
		Json.prettyPrint(swagger);
		Yaml.prettyPrint(swagger);
	}		
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:8,代码来源:SwaggerUtils.java

示例3: validateSwaggerSpec

import io.swagger.util.Yaml; //导入依赖的package包/类
/**
 * Validates the input Swagger JsonNode against Swagger Specification schema.
 *
 * @throws OpenApiConversionException
 */
private static void validateSwaggerSpec(JsonNode swaggerJsonNode)
    throws OpenApiConversionException {
  ProcessingReport report = null;
  try {
    URL url = Resources.getResource(SCHEMA_RESOURCE_PATH);
    String swaggerSchema = Resources.toString(url, StandardCharsets.UTF_8);
    JsonNode schemaNode = Yaml.mapper().readTree(swaggerSchema);
    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(schemaNode);
    report = schema.validate(swaggerJsonNode);
  } catch (Exception ex) {
    throw new OpenApiConversionException("Unable to parse the content. " + ex.getMessage(), ex);
  }
  if (!report.isSuccess()) {
    String message = "";
    Iterator itr = report.iterator();
    if (itr.hasNext()) {
      message += ((ProcessingMessage) itr.next()).toString();
    }
    while(itr.hasNext())
    {
      message += "," + ((ProcessingMessage) itr.next()).toString();
    }
    throw new OpenApiConversionException(
        String.format("Invalid OpenAPI file. Please fix the schema errors:\n%s", message));
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:32,代码来源:MultiOpenApiParser.java

示例4: getYamlFileContentAsJson

import io.swagger.util.Yaml; //导入依赖的package包/类
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();
}
 
开发者ID:zalando-stups,项目名称:swagger-codegen-tooling,代码行数:18,代码来源:YamlToJson.java

示例5: yamlParse

import io.swagger.util.Yaml; //导入依赖的package包/类
/**
 * Same code as in the parser itself to find out what is wrong with the swagger.yaml file.
 */
@Test
public void yamlParse() throws JsonProcessingException, IOException {
    JsonNode rootNode = null;
    ObjectMapper objectMapper = Yaml.mapper();
    rootNode = objectMapper.readTree(getClass().getResourceAsStream("/swagger.yaml"));

    JsonNode swaggerNode = rootNode.get("swagger");
    if (swaggerNode == null) {

        throw new NullPointerException("You failed!");
    }

    swagger = objectMapper.convertValue(rootNode, Swagger.class);
    Assertions.assertThat(swagger).isNotNull();
}
 
开发者ID:zalando-stups,项目名称:swagger-codegen-tooling,代码行数:19,代码来源:ParserTest.java

示例6: convertToSwagger

import io.swagger.util.Yaml; //导入依赖的package包/类
private static Swagger convertToSwagger(String data) throws IOException {
    ObjectMapper mapper;
    if(data.trim().startsWith("{")){
        mapper = Json.mapper();
    }
    else {
        mapper = Yaml.mapper();
    }
    JsonNode rootNode = mapper.readTree(data);
    // must have swagger node set
    JsonNode swaggerNode = rootNode.get("swagger");
    if(swaggerNode == null){
        throw new IllegalArgumentException("Swagger String has an invalid format.");
    }else{
        return mapper.convertValue(rootNode, Swagger.class);
    }
}
 
开发者ID:RobWin,项目名称:assertj-swagger,代码行数:18,代码来源:Swagger20Parser.java

示例7: init

import io.swagger.util.Yaml; //导入依赖的package包/类
@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);

    final BeanConfig beanConfig = loadConfig(new File("logs/swagger.properties"));
    beanConfig.setVersion("v1");
    beanConfig.setSchemes(new String[]{"http"});
    beanConfig.setBasePath("/render-ws");
    beanConfig.setResourcePackage("org.janelia.render.service");
    beanConfig.setScan(true);
    beanConfig.setPrettyPrint(true);

    // Needed to register these modules to get Swagger to use JAXB annotations
    // (see https://github.com/swagger-api/swagger-core/issues/960 for explanation)
    Json.mapper().registerModule(new JaxbAnnotationModule());
    Yaml.mapper().registerModule(new JaxbAnnotationModule());
}
 
开发者ID:saalfeldlab,项目名称:render,代码行数:18,代码来源:SwaggerBootstrapServlet.java

示例8: parse

import io.swagger.util.Yaml; //导入依赖的package包/类
public static Swagger parse(String content) {
  try {
    return Yaml.mapper().readValue(content, Swagger.class);
  } catch (Exception e) {
    return new Swagger();
    //            throw new Error(e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:9,代码来源:UnitTestSwaggerUtils.java

示例9: swaggerToString

import io.swagger.util.Yaml; //导入依赖的package包/类
public static String swaggerToString(Swagger swagger) {
  try {
    return Yaml.mapper().writeValueAsString(swagger);
  } catch (Throwable e) {
    throw new ServiceCombException("Convert swagger to string failed, ", e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:SwaggerUtils.java

示例10: assertDescriptorYaml

import io.swagger.util.Yaml; //导入依赖的package包/类
private void assertDescriptorYaml(Operation o) {
    try {
        Swagger swagger = Yaml.mapper().readValue(o.getBody(String.class), Swagger.class);
        assertSwagger(swagger);
    } catch (IOException ioe) {
        fail(ioe.getMessage());
    }
}
 
开发者ID:vmware,项目名称:xenon-utils,代码行数:9,代码来源:TestSwaggerDescriptorService.java

示例11: testReadYaml

import io.swagger.util.Yaml; //导入依赖的package包/类
public static void testReadYaml() {
	Swagger swagger = read("http://petstore.swagger.io/v2/swagger.yaml");
	if (swagger != null) {
		Json.prettyPrint(swagger);
		Yaml.prettyPrint(swagger);
	}		
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:8,代码来源:SwaggerUtils.java

示例12: generate

import io.swagger.util.Yaml; //导入依赖的package包/类
@Override
public Swagger generate(List<ParsedPath> parsedPaths, RoundDescriptor roundDescriptor) {
    Swagger swagger = delegate.generate(parsedPaths, roundDescriptor);
    if (roundDescriptor.isLast()) {
        FileObject yaml = fileManager.createResource("api.yaml");
        SwaggerUtils.write(Yaml.pretty(), yaml, swagger);
        FileObject json = fileManager.createResource("api.json");
        SwaggerUtils.write(Json.pretty(), json, swagger);
    }
    return swagger;
}
 
开发者ID:Cosium,项目名称:openapi-annotation-processor,代码行数:12,代码来源:WriterSpecificationGenerator.java

示例13: apiDocsDefault

import io.swagger.util.Yaml; //导入依赖的package包/类
@RequestMapping(method = GET, path = "/api", produces = APPLICATION_JSON_VALUE)
public String apiDocsDefault(final HttpServletRequest request,
                      @RequestParam(required = false) final String format) throws JsonProcessingException {
    final String connectionName = "h2";
    final Swagger swaggerDescription = getSwaggerDescription(request, connectionName);
    if (format != null && format.equals("yaml")) {
        return Yaml.pretty().writeValueAsString(swaggerDescription);
    } else {
        return Json.pretty().writeValueAsString(swaggerDescription);
    }
}
 
开发者ID:sql-boot,项目名称:sql-boot,代码行数:12,代码来源:ApiController.java

示例14: apiDocs

import io.swagger.util.Yaml; //导入依赖的package包/类
@RequestMapping(method = GET, path = "/api/{connectionName}", produces = APPLICATION_JSON_VALUE)
public String apiDocs(final HttpServletRequest request,
    @PathVariable String connectionName,
    @RequestParam(required = false) final String format) throws JsonProcessingException {
    final Swagger swaggerDescription = getSwaggerDescription(request, connectionName);
    if (format != null && format.equals("yaml")) {
        return Yaml.pretty().writeValueAsString(swaggerDescription);
    } else {
        return Json.pretty().writeValueAsString(swaggerDescription);
    }
}
 
开发者ID:sql-boot,项目名称:sql-boot,代码行数:12,代码来源:ApiController.java

示例15: transform

import io.swagger.util.Yaml; //导入依赖的package包/类
@Test
public void transform() throws JsonProcessingException, IOException {
    String data = getResourceContent("/kio-api.yaml");
    ObjectMapper yamlMapper = Yaml.mapper();
    JsonNode rootNode = yamlMapper.readTree(data);

    // must have swagger node set
    JsonNode swaggerNode = rootNode.get("swagger");

    String rootNodeString = rootNode.toString();
    System.out.println(rootNodeString);
}
 
开发者ID:zalando-stups,项目名称:swagger-codegen-tooling,代码行数:13,代码来源:YamlToJsonTest.java


注:本文中的io.swagger.util.Yaml类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。