本文整理了Java中io.swagger.v3.core.util.Json.pretty()
方法的一些代码示例,展示了Json.pretty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.pretty()
方法的具体详情如下:
包路径:io.swagger.v3.core.util.Json
类名称:Json
方法名:pretty
暂无
代码示例来源:origin: swagger-api/swagger-core
public static String pretty(Object o) {
try {
return pretty().writeValueAsString(o);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
代码示例来源:origin: swagger-api/swagger-core
public static void prettyPrint(Object o) {
try {
System.out.println(pretty().writeValueAsString(o).replace("\r", ""));
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: swagger-api/swagger-core
public static OpenAPIConfiguration deepCopy(OpenAPIConfiguration config) {
if (config == null) {
return null;
}
try {
return Json.mapper().readValue(Json.pretty(config), SwaggerConfiguration.class);
} catch (Exception e) {
LOGGER.error("Exception cloning config: " + e.getMessage(), e);
return config;
}
}
代码示例来源:origin: swagger-api/swagger-core
@Override
public void run() {
try {
Thread[] thds = new Thread[tg.activeCount()];
tg.enumerate(thds);
for (Thread t : thds) {
if (t != null) {
t.join(10000);
}
}
} catch (Exception e) {
e.printStackTrace();
}
for (OpenAPI filtered : filteredMap.values()) {
assertEquals(Json.pretty(openAPI), Json.pretty(filtered));
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Override
public void run() {
Json.pretty(new ThrowHelper());
}
});
代码示例来源:origin: swagger-api/swagger-core
resp.setContentType(APPLICATION_JSON);
PrintWriter pw = resp.getWriter();
pw.write(pretty ? Json.pretty(oas) : Json.mapper().writeValueAsString(oas));
pw.close();
代码示例来源:origin: swagger-api/swagger-core
if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) {
if (prettyPrint) {
out.write(Json.pretty().writeValueAsBytes(data));
} else {
out.write(Json.mapper().writeValueAsBytes(data));
headers.add("Content-Type", "application/json");
if (prettyPrint) {
out.write(Json.pretty().writeValueAsBytes(data));
} else {
out.write(Json.mapper().writeValueAsBytes(data));
代码示例来源:origin: swagger-api/swagger-core
Schema clonedModel = Json.mapper().readValue(Json.pretty(definition), Schema.class);
if (clonedModel.getProperties() != null) {
clonedModel.getProperties().clear();
代码示例来源:origin: swagger-api/swagger-core
private void handleUnwrapped(List<Schema> props, Schema innerModel, String prefix, String suffix) {
if (StringUtils.isBlank(suffix) && StringUtils.isBlank(prefix)) {
if (innerModel.getProperties() != null) {
props.addAll(innerModel.getProperties().values());
}
} else {
if (prefix == null) {
prefix = "";
}
if (suffix == null) {
suffix = "";
}
if (innerModel.getProperties() != null) {
for (Schema prop : (Collection<Schema>) innerModel.getProperties().values()) {
try {
Schema clonedProp = Json.mapper().readValue(Json.pretty(prop), Schema.class);
clonedProp.setName(prefix + prop.getName() + suffix);
props.add(clonedProp);
} catch (IOException e) {
LOGGER.error("Exception cloning property", e);
return;
}
}
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should clone everything")
public void cloneEverything() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null);
assertEquals(Json.pretty(filtered), Json.pretty(openAPI));
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should scan a model with numbers")
public void scanModelWithNumbers() throws IOException {
final Map<String, Schema> models = readAll(ModelWithNumbers.class);
assertEquals(models.size(), 1);
final Schema model = models.get("ModelWithNumbers");
// Check if we get required properties after building models from classes.
checkModel(model);
// Check if we get required properties after deserialization from JSON
checkModel(Json.mapper().readValue(Json.pretty(model), Schema.class));
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testByteProperty() {
Schema model = new Schema()
.addProperties("byteProperty", new ByteArraySchema());
assertEquals(Json.pretty(model), "{" + NEWLINE +
" \"properties\" : {" + NEWLINE +
" \"byteProperty\" : {" + NEWLINE +
" \"type\" : \"string\"," + NEWLINE +
" \"format\" : \"byte\"" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testFormatOfDecimal() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithDecimalFields.class);
assertEquals(models.size(), 1);
String json = Json.pretty(models);
assertEquals(normalizeLineEnds(json),
"{\n" +
" \"ModelWithDecimalFields\" : {\n" +
" \"type\" : \"object\",\n" +
" \"properties\" : {\n" +
" \"id\" : {\n" +
" \"minimum\" : 3.3,\n" +
" \"exclusiveMinimum\" : false,\n" +
" \"type\" : \"number\",\n" +
" \"format\" : \"double\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testFormatOfInteger() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithIntegerFields.class);
assertEquals(models.size(), 1);
String json = Json.pretty(models);
assertEquals(normalizeLineEnds(json),
"{\n" +
" \"ModelWithIntegerFields\" : {\n" +
" \"type\" : \"object\",\n" +
" \"properties\" : {\n" +
" \"id\" : {\n" +
" \"minimum\" : 3,\n" +
" \"type\" : \"integer\",\n" +
" \"format\" : \"int32\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testFormatOfBigDecimal() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithoutScientificFields.class);
assertEquals(models.size(), 1);
String json = Json.pretty(models);
assertEquals(normalizeLineEnds(json),
"{\n" +
" \"ModelWithoutScientificFields\" : {\n" +
" \"type\" : \"object\",\n" +
" \"properties\" : {\n" +
" \"id\" : {\n" +
" \"maximum\" : 9999999999999999.99,\n" +
" \"exclusiveMaximum\" : false,\n" +
" \"minimum\" : -9999999999999999.99,\n" +
" \"exclusiveMinimum\" : false,\n" +
" \"type\" : \"number\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
} else {
return Response.status(Response.Status.OK)
.entity(pretty ? Json.pretty(oas) : Json.mapper().writeValueAsString(oas))
.type(MediaType.APPLICATION_JSON_TYPE)
.build();
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testByteArray() {
Schema model = new Schema()
.addProperties("byteArray", new ArraySchema().items(new BinarySchema()));
assertEquals(Json.pretty(model), "{" + NEWLINE +
" \"properties\" : {" + NEWLINE +
" \"byteArray\" : {" + NEWLINE +
" \"type\" : \"array\"," + NEWLINE +
" \"items\" : {" + NEWLINE +
" \"type\" : \"string\"," + NEWLINE +
" \"format\" : \"binary\"" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testReadOnlyByteArray() {
Schema model = new Schema()
.addProperties("byteArray",
new ArraySchema().items(new BinarySchema()).readOnly(true));
assertEquals(Json.pretty(model), "{" + NEWLINE +
" \"properties\" : {" + NEWLINE +
" \"byteArray\" : {" + NEWLINE +
" \"type\" : \"array\"," + NEWLINE +
" \"readOnly\" : true," + NEWLINE +
" \"items\" : {" + NEWLINE +
" \"type\" : \"string\"," + NEWLINE +
" \"format\" : \"binary\"" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should serialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesSerialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
Schema schema = new ObjectSchema().additionalProperties(true);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" +
" \"type\" : \"object\",\n" +
" \"additionalProperties\" : true\n" +
"}");
schema = new ObjectSchema().additionalProperties(responseSchema);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" +
" \"type\" : \"object\",\n" +
" \"additionalProperties\" : {\n" +
" \"type\" : \"object\",\n" +
" \"additionalProperties\" : {\n" +
" \"type\" : \"integer\",\n" +
" \"format\" : \"int32\"\n" +
" },\n" +
" \"x-foo\" : \"vendor x\"\n" +
" }\n" +
"}");
}
代码示例来源:origin: swagger-api/swagger-core
assertEquals(Json.pretty(rebuilt), Json.pretty(swagger));
内容来源于网络,如有侵权,请联系作者删除!