/** * 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); } }
public String displayDefaultValue(MarkupDocBuilder docBuilder) { return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse(""); }
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");
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()));
.text(COLON).literalText(Json.pretty(o)));
/** * @param swagger Swagger-Core swagger POJO * @return Pretty printed 'Swagger' document in JSON. */ public static String getDocument(Swagger swagger) { return Json.pretty(swagger); } }
private String createJSON() { return Json.pretty(swagger); }
/** * 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); } }
/** * 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; }
/** * 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; }
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; }
private JsonNode readSchema(@Nonnull final Object schema) throws IOException { final JsonNode schemaObject = Json.mapper().readTree(Json.pretty(schema)); setupSchemaDefinitionRefs(schemaObject); return schemaObject; }
public String displayDefaultValue(MarkupDocBuilder docBuilder) { return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse(""); }
public String displayDefaultValue(final MarkupDocBuilder markupDocBuilder) { return getDefaultValue().map(value -> literalText(markupDocBuilder, Json.pretty(value))).orElse(""); }
public String displayDefaultValue(MarkupDocBuilder docBuilder) { return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse(""); }
/** * 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); } }
@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); } }
@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); } }
@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(); } }
@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); }