本文整理了Java中io.swagger.v3.core.util.Json.mapper()
方法的一些代码示例,展示了Json.mapper()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.mapper()
方法的具体详情如下:
包路径:io.swagger.v3.core.util.Json
类名称:Json
方法名:mapper
暂无
代码示例来源:origin: swagger-api/swagger-core
default OpenAPIConfiguration deserializeConfig(String path, String configAsString) {
try {
if (path.toLowerCase().endsWith("json")) {
return Json.mapper().readValue(configAsString, SwaggerConfiguration.class);
} else { // assume yaml
return Yaml.mapper().readValue(configAsString, SwaggerConfiguration.class);
}
} catch (Exception e) {
LOGGER.error("exception reading config: " + e.getMessage(), e);
return null;
}
}
代码示例来源: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
public ModelConverters() {
converters = new CopyOnWriteArrayList<>();
converters.add(new ModelResolver(Json.mapper()));
}
代码示例来源:origin: swagger-api/swagger-core
public static ObjectWriter pretty() {
return mapper().writer(new DefaultPrettyPrinter());
}
代码示例来源:origin: swagger-api/swagger-core
protected Object resolveExample(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) {
if (schema != null) {
if (!schema.example().isEmpty()) {
try {
return Json.mapper().readTree(schema.example());
} catch (IOException e) {
return schema.example();
}
}
}
return null;
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should read the uber api")
public void readUberApi() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "uber.json");
final OpenAPI swagger = Json.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
}
代码示例来源:origin: swagger-api/swagger-core
private OpenAPI getOpenAPI(String path) throws IOException {
final String json = ResourceUtils.loadClassResource(getClass(), path);
return Json.mapper().readValue(json, OpenAPI.class);
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testIssue2064Neg() throws Exception {
String json =
"{\n" +
" \"type\": \"string\",\n" +
" \"uniqueItems\": false\n" +
"}";
final Schema model = Json.mapper().readValue(json, Schema.class);
assertFalse(model.getUniqueItems());
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testIssue2064() throws Exception {
String json =
"{\n" +
" \"type\": \"string\",\n" +
" \"uniqueItems\": true\n" +
"}";
final Schema model = Json.mapper().readValue(json, Schema.class);
assertTrue(model.getUniqueItems());
}
代码示例来源:origin: swagger-api/swagger-core
public static <T> T deserializeJsonFileFromClasspath(String path, Class<T> type) {
return deserializeFileFromClasspath(path, type, Json.mapper());
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testIssue1852() throws Exception {
String json = "{\n" +
" \"type\": \"integer\",\n" +
" \"minimum\": 10,\n" +
" \"maximum\": 20,\n" +
" \"default\": 15\n" +
"}";
final Schema model = Json.mapper().readValue(json, Schema.class);
assertEquals(model.getMinimum().intValue(), 10);
assertEquals(model.getMaximum().intValue(), 20);
assertEquals(model.getDefault(), 15);
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void prettyPrintTest() throws IOException {
final String json = ResourceUtils.loadClassResource(getClass(), "uber.json");
final OpenAPI swagger = Json.mapper().readValue(json, OpenAPI.class);
final String outputStream = OutputReplacer.OUT.run(new OutputReplacer.Function() {
@Override
public void run() {
Json.prettyPrint(swagger);
}
});
SerializationMatchers.assertEqualsToJson(swagger, outputStream);
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testExtension() throws Exception {
OpenAPI swagger = new OpenAPI();
swagger.addExtension("x-foo-bar", "foo bar");
swagger.setInfo(new Info());
swagger.getInfo().addExtension("x-foo-bar", "foo bar");
String swaggerJson = Json.mapper().writeValueAsString(swagger);
assertFalse(swaggerJson.contains("extensions"));
OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
assertEquals(rebuilt.getExtensions().values().iterator().next(), "foo bar");
assertEquals(rebuilt.getInfo().getExtensions().values().iterator().next(), "foo bar");
}
代码示例来源: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(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
MapSchema mp = (MapSchema) responseSchema;
assertTrue(mp.getExtensions().size() > 0);
assertNotNull(mp.getExtensions().get("x-foo"));
assertEquals(mp.getExtensions().get("x-foo"), "vendor x");
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof MapSchema);
MapSchema mp = (MapSchema) responseSchema;
assertTrue(mp.getAdditionalProperties() instanceof IntegerSchema);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should deserialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(jsonAdditionalPropertiesBoolean, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof ObjectSchema);
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testSerializeASpecWithPathReferences() throws Exception {
OpenAPI swagger = new OpenAPI()
.addServersItem(new Server().url("http://petstore.swagger.io"));
PathItem expectedPath = new PathItem().$ref("http://my.company.com/paths/health.json");
swagger.path("/health", expectedPath);
String swaggerJson = Json.mapper().writeValueAsString(swagger);
OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
final PathItem path = rebuilt.getPaths().get("/health");
assertEquals(path, expectedPath);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should clone everything from JSON without models")
public void cloneWithoutModels() throws IOException {
final String json = ResourceUtils.loadClassResource(getClass(), RESOURCE_PATH_WITHOUT_MODELS);
final OpenAPI openAPI = Json.mapper().readValue(json, OpenAPI.class);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null);
SerializationMatchers.assertEqualsToJson(filtered, json);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should not create an xml object for $ref")
public void shouldNotCreateXmlObjectForRef() throws IOException {
final Schema model = new Schema().$ref("Monster");
model.setDescription("oops");
model.setExternalDocs(new ExternalDocumentation()
.description("external docs")
.url("http://swagger.io"));
assertEquals(Json.mapper().writeValueAsString(model), "{\"$ref\":\"#/components/schemas/Monster\"}");
}
内容来源于网络,如有侵权,请联系作者删除!