本文整理汇总了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();
}
示例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);
}
}
示例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));
}
}
示例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();
}
示例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();
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}