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

x33g5p2x  于2022-01-21 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(133)

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

Json.pretty介绍

暂无

代码示例

代码示例来源:origin: Swagger2Markup/swagger2markup

/**
 * Parse a JSON array
 *
 * @param raw Object containing a JSON string
 * @return JsonNode[contentType, example]
 * @throws RuntimeException when the given JSON string cannot be parsed
 */
private JsonNode parseExample(Object raw) throws RuntimeException {
  try {
    JsonFactory factory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(factory);
    return mapper.readTree(Json.pretty(raw));
  } catch (Exception ex) {
    throw new RuntimeException("Failed to read example", ex);
  }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

public String displayDefaultValue(MarkupDocBuilder docBuilder) {
  return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse("");
}

代码示例来源:origin: Swagger2Markup/swagger2markup

String example = Json.pretty(rootNode);
  String example = Json.pretty(field.getValue());
  example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));
  String example = Json.pretty(entry.getValue());
  markupDocBuilder.listingBlock(example, "json");
  break; // No need to print the same example multiple times
    String example = Json.pretty(entryByType.getValue());
    example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));
    String example = Json.pretty(entry.getValue());
    markupDocBuilder.listingBlock(example, "json");
    break; // No need to print the same example multiple times
markupDocBuilder.listingBlock(Json.pretty(value), "json");

代码示例来源:origin: Swagger2Markup/swagger2markup

descriptionContent.newLine(true);
descriptionContent.boldText(labels.getLabel(DEFAULT_COLUMN)).text(COLON).literalText(Json.pretty(optionalDefaultValue.get()));
  descriptionContent.newLine(true);
descriptionContent.boldText(labels.getLabel(PATTERN_COLUMN)).text(COLON).literalText(Json.pretty(optionalPattern.get()));
  descriptionContent.boldText(labels.getLabel(EXAMPLE_COLUMN)).text(COLON).crossReference(optionalExample.get().toString());
} else {
  descriptionContent.boldText(labels.getLabel(EXAMPLE_COLUMN)).text(COLON).literalText(Json.pretty(optionalExample.get()));

代码示例来源:origin: Swagger2Markup/swagger2markup

.text(COLON).literalText(Json.pretty(o)));

代码示例来源:origin: yahoo/elide

/**
   * @param swagger Swagger-Core swagger POJO
   * @return Pretty printed 'Swagger' document in JSON.
   */
  public static String getDocument(Swagger swagger) {
    return Json.pretty(swagger);
  }
}

代码示例来源:origin: openmrs/openmrs-module-webservices.rest

private String createJSON() {
  return Json.pretty(swagger);
}

代码示例来源:origin: io.github.swagger2markup/swagger2markup

/**
 * Parse a JSON array
 *
 * @param raw Object containing a JSON string
 * @return JsonNode[contentType, example]
 * @throws RuntimeException when the given JSON string cannot be parsed
 */
private JsonNode parseExample(Object raw) throws RuntimeException {
  try {
    JsonFactory factory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(factory);
    return mapper.readTree(Json.pretty(raw));
  } catch (Exception ex) {
    throw new RuntimeException("Failed to read example", ex);
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-rest-swagger

/**
 * Generates a Swagger 2.0 JSON specification from the collection of routes.
 *
 * @param routes
 * @return a Swagger 2.0 JSON specification
 */
public String generateJSON(Collection<Route> routes) {
  Swagger swagger = build(routes);
  String json = Json.pretty(swagger);
  return json;
}

代码示例来源:origin: gitblit/fathom

/**
 * Generates a Swagger 2.0 JSON specification from the collection of routes.
 *
 * @param routes
 * @return a Swagger 2.0 JSON specification
 */
public String generateJSON(Collection<Route> routes) {
  Swagger swagger = build(routes);
  String json = Json.pretty(swagger);
  return json;
}

代码示例来源:origin: com.github.phillip-kruger/apiee-core

private String generateJson(int hash,final Set<Class<?>> classes,URL url){
  log.log(Level.FINEST, "Generating {0} response from context", url);
  Swagger swagger = createSwagger(classes,url);
  try {
    String swaggerJson = Json.pretty().writeValueAsString(swagger);
    swaggerMap.put(hash, new CachedDocument(hash,url,swaggerJson));
    return swaggerJson;
  } catch (JsonProcessingException ex) {
    log.log(Level.WARNING, "Could not generate {0} - {1}", new Object[]{url.toString(), ex.getMessage()});
  }
  log.log(Level.WARNING, "Could not generate {0} - null", new Object[]{url.toString()});
  return null;
}

代码示例来源:origin: com.atlassian.oai/swagger-request-validator-core

private JsonNode readSchema(@Nonnull final Object schema) throws IOException {
  final JsonNode schemaObject = Json.mapper().readTree(Json.pretty(schema));
  setupSchemaDefinitionRefs(schemaObject);
  return schemaObject;
}

代码示例来源:origin: io.github.swagger2markup/swagger2markup

public String displayDefaultValue(MarkupDocBuilder docBuilder) {
  return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse("");
}

代码示例来源:origin: org.tomitribe/swagger2markup

public String displayDefaultValue(final MarkupDocBuilder markupDocBuilder) {
  return getDefaultValue().map(value -> literalText(markupDocBuilder, Json.pretty(value))).orElse("");
}

代码示例来源:origin: org.tomitribe/swagger2markup

public String displayDefaultValue(MarkupDocBuilder docBuilder) {
  return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse("");
}

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

/**
 * Convert given API definition in JSON format.
 * @param api The API model to serialize
 * @param pretty Whether to pretty format the output
 * @return The API definition as JSON
 */
static String asJson(Swagger api, boolean pretty) {
  try {
    return pretty ? Json.pretty(api) : Json.mapper().writeValueAsString(api);
  } catch (Exception e) {
    throw new ApiConfigurationException(e);
  }
}

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

@Override
public void filter(ContainerRequestContext reqCtx, ContainerResponseContext respCtx) throws IOException {
  if (Boolean.TRUE == reqCtx.getProperty(OPEN_API_PROPERTY)) {
    final Object entity = respCtx.getEntity();
    // Right before 1.5.18, the entity was always a String but became a model object
    // (io.swagger.models.Swagger) after. For now, let us serialize it to JSON manually.
    String swaggerJson = entity instanceof String ? (String)entity : Json.pretty(entity);
    String openApiJson = SwaggerToOpenApiConversionUtils.getOpenApiFromSwaggerJson(
        createMessageContext(), swaggerJson, openApiConfig);
    respCtx.setEntity(openApiJson);
  }
}

代码示例来源:origin: vmware/admiral

@Override
  public void handleGet(Operation get) {
    this.swagger = SwaggerDocumentationAssembler
        .create()
        .setHost(get.getReferer().getAuthority())
        .setBasePath(SwaggerDocumentation.BASE_PATH)
        .setInfo(this.info)
        .setIncludePackages(this.includePackages)
        .setSchemes(this.schemes)
        .build();

    get.setBody(Json.pretty(swagger)).complete();
  }
}

代码示例来源:origin: openmrs/openmrs-module-webservices.rest

@Test
public void swaggerSerializeTest() {
  final Info info = new Info().version("1.0.0").title("Swagger WebServices REST");
  
  Swagger swagger = new Swagger().info(info).securityDefinition("basicAuth", new BasicAuthDefinition())
      .scheme(Scheme.HTTP).consumes("application/json").produces("application/json");
  
  final Model patientModel = ModelConverters.getInstance().read(Patient.class).get("Patient");
  swagger.addDefinition("Patient", patientModel);
  
  final String swaggerJson = Json.pretty(swagger);
  assertNotNull(swaggerJson);
}

相关文章