本文整理汇总了Java中com.fasterxml.jackson.module.jsonSchema.JsonSchema类的典型用法代码示例。如果您正苦于以下问题:Java JsonSchema类的具体用法?Java JsonSchema怎么用?Java JsonSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonSchema类属于com.fasterxml.jackson.module.jsonSchema包,在下文中一共展示了JsonSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SalesforceMetadataAdapterTest
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public SalesforceMetadataAdapterTest() {
final Map<String, JsonSchema> objectProperties = new HashMap<>();
objectProperties.put("simpleProperty", new StringSchema());
objectProperties.put("anotherProperty", new NumberSchema());
final StringSchema uniqueProperty1 = new StringSchema();
uniqueProperty1.setDescription("idLookup,autoNumber");
uniqueProperty1.setTitle("Unique property 1");
final StringSchema uniqueProperty2 = new StringSchema();
uniqueProperty2.setDescription("calculated,idLookup");
uniqueProperty2.setTitle("Unique property 2");
objectProperties.put("uniqueProperty1", uniqueProperty1);
objectProperties.put("uniqueProperty2", uniqueProperty2);
final ObjectSchema objectSchema = new ObjectSchema();
objectSchema.setId("urn:jsonschema:org:apache:camel:component:salesforce:dto:SimpleObject");
objectSchema.setProperties(objectProperties);
payload = new ObjectSchema();
payload.setOneOf(Collections.singleton(objectSchema));
}
示例2: adaptTest
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Test
public void adaptTest() throws IOException {
SqlStoredConnectorMetaDataExtension ext = new SqlStoredConnectorMetaDataExtension();
Map<String,Object> parameters = new HashMap<>();
for (final String name: properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf(".")+1), properties.getProperty(name));
}
Optional<MetaData> metadata = ext.meta(parameters);
SqlStoredMetadataAdapter adapter = new SqlStoredMetadataAdapter();
SyndesisMetadata<JsonSchema> syndesisMetaData = adapter.adapt(parameters, metadata.get());
ObjectMapper mapper = new ObjectMapper();
String expectedListOfProcedures = IOUtils.toString(this.getClass().getResource("/sql/stored_procedure_list.json"), StandardCharsets.UTF_8);
String actualListOfProcedures = (mapper.writerWithDefaultPrettyPrinter().writeValueAsString(syndesisMetaData));
assertEquals(expectedListOfProcedures, actualListOfProcedures);
parameters.put("procedureName", "DEMO_ADD");
SyndesisMetadata<JsonSchema> syndesisMetaData2 = adapter.adapt(parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/demo_add_metadata.json"), StandardCharsets.UTF_8);
String actualMetadata = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata);
}
示例3: getSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private static Optional<JsonSchema> getSchemma(Class<?> clazz) {
ObjectMapper mapper = new ObjectMapper();
Optional<JsonSchema> schema = Optional.empty();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
Optional<Class<?>> realClazz = ReflectionUtils.getGenericClass(clazz);
boolean iterable = Iterable.class.isAssignableFrom(clazz) && realClazz.isPresent();
if (iterable) {
clazz = realClazz.get();
}
try {
mapper.acceptJsonFormatVisitor(clazz, visitor);
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
schema = Optional.ofNullable(schemaGen.generateSchema(clazz));
if (iterable) {
// TODO: decirle que es una collection
}
} catch (JsonMappingException e) {
LOGGER.error("Se produjo un error al crear el JsonSchemma para la clase {}", clazz.getSimpleName(), e);
}
return schema;
}
示例4: getResponseSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private static Optional<JsonSchema> getResponseSchemma(Method m, Class<?> parametrizedClass) {
Optional<JsonSchema> schemma = Optional.empty();
// obtengo el tipo real de retorno por si es generic
Optional<Type> returnType = ReflectionUtils.getRealType(m.getGenericReturnType(), parametrizedClass);
if (returnType.isPresent()) {
// el return type puede ser una colleccion para eso obtengo la clase real del
// parametro a traves de reflection utils
Optional<Class<?>> realClass = ReflectionUtils.getClass(returnType.get());
if (realClass.isPresent()) {
if (Iterable.class.isAssignableFrom(realClass.get())) {
// si es una collection tengo que saber si es generic, para eso le pido la clase
// al return type
if (ParameterizedType.class.isAssignableFrom(returnType.get().getClass()))
returnType = ReflectionUtils.getGenericType((ParameterizedType) returnType.get());
}
schemma = getSchemma(ReflectionUtils.getClass(returnType.orElse(null)).orElse(realClass.get()));
} else {
LOGGER.error("No existe una real class para: {}", returnType);
}
}
return schemma;
}
示例5: getRequestSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private static Optional<JsonSchema> getRequestSchemma(Method m, Class<?> controller) {
List<Parameter> p = ReflectionUtils.getParametersBody(m);
Optional<JsonSchema> schemma = Optional.empty();
if (!p.isEmpty()) {
Optional<Type> t = ReflectionUtils.getRealType(p.get(0).getParameterizedType(), controller);
if (t.isPresent()) {
Optional<Class<?>> c = ReflectionUtils.getClass(t.get());
if (c.isPresent()) {
schemma = getSchemma(c.get());
} else {
schemma = getSchemma(t.getClass());
}
} else {
schemma = getSchemma(ReflectionUtils.getClass(p.get(0).getParameterizedType()));
}
}
return schemma;
}
示例6: getPaths
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public List<String> getPaths(final String kind, final String type, final String specification,
final Optional<byte[]> exemplar) {
final ObjectSchema schema;
try {
schema = MAPPER.readerFor(ObjectSchema.class).readValue(specification);
} catch (final IOException e) {
LOG.warn(
"Unable to parse the given JSON schema, increase log level to DEBUG to see the schema being parsed");
LOG.debug(specification);
return Collections.emptyList();
}
final Map<String, JsonSchema> properties = schema.getProperties();
final List<String> paths = new ArrayList<>();
fetchPaths(null, paths, properties);
return paths;
}
示例7: fetchPaths
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) {
for (final Entry<String, JsonSchema> entry : properties.entrySet()) {
final JsonSchema subschema = entry.getValue();
String path;
final String key = entry.getKey();
if (context == null) {
path = key;
} else {
path = context + "." + key;
}
if (subschema.isValueTypeSchema()) {
paths.add(path);
} else if (subschema.isObjectSchema()) {
fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties());
}
}
}
示例8: adaptForSqlTest
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Test
public void adaptForSqlTest() throws IOException {
SqlConnectorMetaDataExtension ext = new SqlConnectorMetaDataExtension();
Map<String,Object> parameters = new HashMap<>();
for (final String name: properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf(".")+1), properties.getProperty(name));
}
parameters.put("query", "SELECT * FROM NAME WHERE ID=:#id");
Optional<MetaData> metadata = ext.meta(parameters);
SqlMetadataAdapter adapter = new SqlMetadataAdapter();
ObjectMapper mapper = new ObjectMapper();
SyndesisMetadata<JsonSchema> syndesisMetaData2 = adapter.adapt("sql-connector", parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/name_sql_metadata.json"), StandardCharsets.UTF_8);
String actualMetadata = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata);
}
示例9: customizeSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
Optional.ofNullable(property.getAnnotation(Password.class)).ifPresent(annotation -> {
if (annotation.title() != null) {
((StringSchema) jsonschema).setTitle(annotation.title());
}
if (annotation.pattern() != null) {
((StringSchema) jsonschema).setPattern(annotation.pattern());
}
if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
});
}
示例10: customizeSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
TextField annotation = property.getAnnotation(TextField.class);
if (annotation != null) {
if (annotation.title() != null) {
((StringSchema) jsonschema).setTitle(annotation.title());
}
if (annotation.pattern() != null) {
((StringSchema) jsonschema).setPattern(annotation.pattern());
}
if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
}
}
示例11: findRefs
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private void findRefs(JsonSchema schema, Map<String, JsonSchema> refs, Set<String> referenced) {
addRef(schema, refs);
if (schema instanceof ReferenceSchema) {
referenced.add(schema.get$ref());
} else if (schema.isArraySchema()) {
ArraySchema as = schema.asArraySchema();
if (as.getItems() != null) {
if (as.getItems().isSingleItems()) {
findRefs(as.getItems().asSingleItems().getSchema(), refs, referenced);
} else if (as.getItems().isArrayItems()) {
ArrayItems items = as.getItems().asArrayItems();
for (JsonSchema item : items.getJsonSchemas()) {
findRefs(item, refs, referenced);
}
} else {
throw new UnsupportedOperationException(as.getItems().toString());
}
}
} else if (schema.isObjectSchema()) {
ObjectSchema os = schema.asObjectSchema();
for (JsonSchema value : os.getProperties().values()) {
findRefs(value, refs, referenced);
}
}
}
示例12: objectExample
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private void objectExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema,
Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced, String id) {
sb.append("{");
if (referenced.contains(id)) {
shortId(sb, schema);
}
ObjectSchema os = schema.asObjectSchema();
if (os.getProperties().isEmpty()) {
AdditionalProperties additionalProperties = os.getAdditionalProperties();
if (additionalProperties instanceof SchemaAdditionalProperties) {
sb.append("\n").append(indent).append(" ").append("abc").append(": ");
example(sb, maxlength, indent + " ", ((SchemaAdditionalProperties) additionalProperties).getJsonSchema(), refs, followed, referenced);
sb.append(", ...");
}
}
Map<String, JsonSchema> props = new TreeMap<>(os.getProperties());
for (Entry<String, JsonSchema> entry : props.entrySet()) {
sb.append("\n").append(indent).append(" ").append(entry.getKey()).append(": ");
example(sb, maxlength, indent + " ", entry.getValue(), refs, followed, referenced);
sb.append(",");
}
sb.append("\n").append(indent).append("}");
}
示例13: arrayExample
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private void arrayExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema,
Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced) {
sb.append("[\n").append(indent).append(" ");
ArraySchema as = schema.asArraySchema();
if (as.getItems() == null) {
sb.append(" ... ]");
} else if (as.getItems().isSingleItems()) {
example(sb, maxlength, indent + " ", as.getItems().asSingleItems().getSchema(), refs, followed, referenced);
sb.append(",\n").append(indent).append(" ...\n").append(indent).append("]");
} else if (as.getItems().isArrayItems()) {
ArrayItems items = as.getItems().asArrayItems();
for (JsonSchema item : items.getJsonSchemas()) {
sb.append("\n").append(indent);
example(sb, maxlength, indent + " ", item, refs, followed, referenced);
sb.append(",");
}
sb.append("]");
} else {
throw new UnsupportedOperationException(as.getItems().toString());
}
}
示例14: convertClassToJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
/**
* Uses Jackson object mappers to convert an ajaxcommandparameter annotated type into its
* JSONSchema representation.
* If Javadoc is supplied, this will be injected as comments
*
* @param clazz
* The Class to convert
* @param responseDescription
* The javadoc description supplied if available
* @param javaDocStore
* The Entire java doc store available
* @return A string containing the Json Schema
*/
public static String convertClassToJsonSchema(ApiParameterMetadata clazz, String responseDescription,
JavaDocStore javaDocStore) {
if (clazz == null || clazz.equals(Void.class)) {
return "{}";
}
try {
ObjectMapper m = new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
JsonSchema jsonSchema = extractSchemaInternal(clazz.getType(), clazz.getGenericType(), responseDescription,
javaDocStore, m);
return m.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
示例15: getSchemaForHtml
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public Optional<String> getSchemaForHtml(ObjectMapper objectMapper, Class modelClass, Function<String, String> classNameToHyperlink) throws IOException {
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
visitor.setVisitorContext(new VisitorContextWithoutSchemaInlining() {
public String javaTypeToUrn(JavaType jt) {
return jt.toCanonical();
}
});
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(modelClass), visitor);
JsonSchema jsonSchema = visitor.finalSchema();
JsonNode schemaNode = objectMapper.convertValue(jsonSchema, JsonNode.class);
if (schemaNode.equals(objectMapper.readTree("{\"type\":\"any\"}"))) {
return Optional.empty();
}
String result = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(schemaNode);
result = StringEscapeUtils.escapeHtml3(result);
result = activateRefLinks(result, classNameToHyperlink);
return Optional.of(result);
}