本文整理匯總了Java中io.swagger.util.Json類的典型用法代碼示例。如果您正苦於以下問題:Java Json類的具體用法?Java Json怎麽用?Java Json使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Json類屬於io.swagger.util包,在下文中一共展示了Json類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSwaggerJson
import io.swagger.util.Json; //導入依賴的package包/類
public JSONObject getSwaggerJson(String path) throws ServiceApiException {
Swagger swagger = getSwagger(path);
try {
// Re-parse as JsonObject to ensure ordering of definitions and paths.
// TODO: make this optional (see limberest.yaml comments in limberest-demo)
JsonObject swaggerJson = new JsonObject(Json.mapper().writeValueAsString(swagger));
if (swaggerJson.has("definitions"))
swaggerJson.put("definitions", new JsonObject(swaggerJson.getJSONObject("definitions").toString()));
if (swaggerJson.has("paths"))
swaggerJson.put("paths", new JsonObject(swaggerJson.getJSONObject("paths").toString()));
return swaggerJson;
}
catch (JsonProcessingException ex) {
throw new ServiceApiException(ex.getMessage(), ex);
}
}
示例2: testReadJson
import io.swagger.util.Json; //導入依賴的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: testReadPath
import io.swagger.util.Json; //導入依賴的package包/類
public static void testReadPath() throws JsonProcessingException, IOException {
String data = "{"
+ "\"post\": { \"tags\": [\"pet\"], \"summary\": \"add a new pet to the store\", \"description\": \"\", \"operationid\": \"addpet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"405\": { \"description\": \"invalid input\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] },"
+ "\"put\": { \"tags\": [\"pet\"], \"summary\": \"update an existing pet\", \"description\": \"\", \"operationid\": \"updatepet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"400\": { \"description\": \"invalid id supplied\" }, \"404\": { \"description\": \"pet not found\" }, \"405\": { \"description\": \"validation exception\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] }"
+ "}";
ObjectMapper mapper = Json.mapper();
JsonNode pathNode = mapper.readTree(data);
Path path = mapper.convertValue(pathNode, Path.class);
Json.prettyPrint(path);
}
示例4: getDefinationsFromSchemaReference
import io.swagger.util.Json; //導入依賴的package包/類
public HashMap<String, JsonNode> getDefinationsFromSchemaReference(String schemaReference, String schemaName) {
if (schemaDefinationsForReferences == null) {
schemaDefinationsForReferences = new HashMap<>();
}
Model model = swagger.getDefinitions().get(schemaReference);
if(model==null){
System.out.println(schemaReference);
}
if (schemaDefinationsForReferences.containsKey(schemaName)) {
return null;
}
try {
schemaDefinationsForReferences.put(schemaName, jsonMapper.readTree(Json.pretty(model)));
} catch (IOException e) {
e.printStackTrace();
}
getSchemaFromModel(model);
return schemaDefinationsForReferences;
}
示例5: resolveProperty
import io.swagger.util.Json; //導入依賴的package包/類
@Override
public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) {
final JavaType jType = Json.mapper().constructType(type);
if (jType != null) {
final Class<?> cls = jType.getRawClass();
if (cls.equals(ObjectId.class)) {
StringProperty property = new StringProperty();
property.setExample("588f7ee98f138b19220041a7");
return property;
}
}
if (chain.hasNext()) {
return chain.next().resolveProperty(type, context, annotations, chain);
} else {
return null;
}
}
示例6: createIntegration
import io.swagger.util.Json; //導入依賴的package包/類
private void createIntegration(Method method, Map<String, Object> vendorExtensions) {
if (!vendorExtensions.containsKey(EXTENSION_INTEGRATION)) {
return;
}
Map<String, HashMap> integ = Json.mapper().convertValue(
vendorExtensions.get(EXTENSION_INTEGRATION), Map.class );
IntegrationType type = IntegrationType.valueOf(getStringValue(integ.get("type")).toUpperCase());
LOG.info("Creating integration with type " + type);
PutIntegrationInput input = new PutIntegrationInput()
.withType(type)
.withUri(getStringValue(integ.get("uri")))
.withCredentials(getStringValue(integ.get("credentials")))
.withHttpMethod((getStringValue(integ.get("httpMethod"))))
.withRequestParameters(integ.get("requestParameters"))
.withRequestTemplates(integ.get("requestTemplates"))
.withCacheNamespace(getStringValue(integ.get("cacheNamespace")))
.withCacheKeyParameters((List<String>) integ.get("cacheKeyParameters"));
Integration integration = method.putIntegration(input);
createIntegrationResponses(integration, integ);
}
示例7: convertToSwagger
import io.swagger.util.Json; //導入依賴的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);
}
}
示例8: getDefinitions
import io.swagger.util.Json; //導入依賴的package包/類
private static Map<String, io.swagger.models.Model> getDefinitions(RestApi restApi)
throws IOException, JsonParseException, JsonMappingException {
Map<String, io.swagger.models.Model> result = new HashMap<String, io.swagger.models.Model>();
for (Models models = restApi.getModels(); models != null; models = safeGetNext(models)) {
for (Model modelItem : models.getItem()) {
String content = modelItem.getSchema();
io.swagger.models.Model model =
Json.mapper().readValue(content, io.swagger.models.Model.class);
if (model instanceof ModelImpl) {
((ModelImpl) model).setName(modelItem.getName());
}
model.setDescription(modelItem.getDescription());
result.put(modelItem.getName(), model);
}
}
return result;
}
示例9: writeDynamicResource
import io.swagger.util.Json; //導入依賴的package包/類
private byte[] writeDynamicResource(InputStream is) throws IOException {
String str = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
Swagger swagger = new SwaggerParser().parse(str);
// set the resource listing tag
Tag dynamic = new Tag();
dynamic.setName("dynamic");
dynamic.setDescription("Dynamic Cypher resources");
swagger.addTag(dynamic);
// add resources to the path
Map<String,Path> paths = swagger.getPaths();
paths.putAll(configuration.getCypherResources());
Map<String,Path> sorted = new LinkedHashMap<>();
List<String> keys = new ArrayList<>();
keys.addAll(paths.keySet());
Collections.sort(keys);
for (String key : keys) {
sorted.put(key, paths.get(key));
}
swagger.setPaths(sorted);
// return updated swagger JSON
return Json.pretty(swagger).getBytes();
}
示例10: init
import io.swagger.util.Json; //導入依賴的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());
}
示例11: ModelResolverExt
import io.swagger.util.Json; //導入依賴的package包/類
public ModelResolverExt() {
super(Json.mapper());
addPropertyCreator(new BytePropertyCreator());
addPropertyCreator(new ShortPropertyCreator());
addPropertyCreator(new ByteArrayPropertyCreator());
addPropertyCreator(new InputStreamPropertyCreator());
addPropertyCreator(new PartPropertyCreator());
loadPropertyCreators();
}
示例12: assertDescriptorJson
import io.swagger.util.Json; //導入依賴的package包/類
private void assertDescriptorJson(Operation o, Throwable e) {
if (e != null) {
Throwable[] suppressed = e.getSuppressed();
if (suppressed != null && suppressed.length > 0) {
e = suppressed[0];
}
e.printStackTrace();
if (e.getMessage().contains("Unparseable JSON body")) {
// Ignore failure
// Expecting GSON classloading issue to be fixed:
// - https://github.com/google/gson/issues/764
// - https://www.pivotaltracker.com/story/show/120885303
Utils.logWarning("GSON initialization failure: %s", e);
// Stop assertion logic here, test will finish as success
return;
} else {
fail(e.getMessage());
}
}
try {
Swagger swagger = Json.mapper().readValue(o.getBody(String.class), Swagger.class);
assertSwagger(swagger);
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
示例13: testConversions
import io.swagger.util.Json; //導入依賴的package包/類
@Test
public void testConversions() {
final URI uri = URI.create("https://github.com/eclipse/vert.x/blob/a30703379a06502faaae0aeda1eaa9a9b1152004/src/main/java/io/vertx/core/net/impl/SSLHelper.java");
final RequestOptions requestOptions = Conversions.toRequestOptions(uri);
Json.prettyPrint(requestOptions);
}
示例14: testConversionsWithEscapedDataQuery
import io.swagger.util.Json; //導入依賴的package包/類
@Test
public void testConversionsWithEscapedDataQuery() {
final URI uri = URI.create("https://encrypted.google.com/search?q=face+book+%25+prime+%3F&oq=face+book+%25+prime+%3F&gs_l=psy-ab.3..0i13k1l10.12446.12733.0.13108.2.2.0.0.0.0.140.248.0j2.2.0....0...1.1.64.psy-ab..0.2.246....0.QRedmYd5GAY");
final RequestOptions requestOptions = Conversions.toRequestOptions(uri);
Json.prettyPrint(requestOptions);
}
示例15: testConversionsWithQuery
import io.swagger.util.Json; //導入依賴的package包/類
@Test
public void testConversionsWithQuery() {
final URI uri = URI.create("https://news.google.com/news/?ned=ca&hl=en-CA");
final RequestOptions requestOptions = Conversions.toRequestOptions(uri);
Json.prettyPrint(requestOptions);
}