@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; }
static ObjectSchema convertSalesforceGlobalObjectJsonToSchema(final JsonNode payload) { final Set<Object> allSchemas = new HashSet<>(); for (final JsonNode sobject : payload) { // generate SObject schema from description final ObjectSchema sobjectSchema = new ObjectSchema(); sobjectSchema.setId(JsonUtils.DEFAULT_ID_PREFIX + ":" + sobject.get("name").asText()); sobjectSchema.setTitle(sobject.get("label").asText()); allSchemas.add(sobjectSchema); } final ObjectSchema schema = new ObjectSchema(); schema.setOneOf(allSchemas); return schema; }
@Override public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) throws JsonMappingException { schema.putProperty(name, propertySchema(handler, propertyTypeHint)); }
protected boolean _equals(ObjectSchema that) { return equals(getAdditionalProperties(), that.getAdditionalProperties()) && equals(getDependencies(), that.getDependencies()) && equals(getPatternProperties(), that.getPatternProperties()) && equals(getProperties(), that.getProperties()) && super._equals(that); }
ObjectSchema simpleObjectSchema(final String name, final String label) { final ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setId(JsonUtils.DEFAULT_ID_PREFIX + ":" + name); objectSchema.setTitle(label); return objectSchema; } }
Map<String, String> schemas, ObjectMapper m) throws JsonProcessingException { ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setTitle(name); objectSchema.setDescription(description); if (!isRaw) { if (extendedType != null) { JsonSchema[] extended = new JsonSchema[1]; SimpleTypeSchema typeExtended = new ObjectSchema(); typeExtended.set$ref(extendedType); extended[0] = typeExtended; objectSchema.setExtends(extended); objectSchema.setProperties(new LinkedHashMap<String, JsonSchema>()); for (Property property : properties) { String type = property.getType(); SimpleTypeSchema reference = new ObjectSchema(); reference.set$ref("#/schemas/" + type); array.setItemsSchema(reference); objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); objectSchema.getProperties().put(property.getName(), primitive); } else {
public SalesforceMetadataRetrievalTest() { 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)); }
public ObjectSchema objectSchema() { return new ObjectSchema(); }
public WrapperProcessorTest() { final ObjectSchema parameters = new ObjectSchema(); parameters.putProperty("param1", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); parameters.putProperty("param2", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); schema.putProperty("parameters", parameters); final ObjectSchema body = new ObjectSchema(); body.putProperty("body1", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); body.putProperty("body2", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); schema.putProperty("body", body); }
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("}"); }
schemasToConsider = Collections.singleton(objectSchemaFrom(schema)); } else { schemasToConsider = schema.getOneOf().stream().filter(SalesforceMetadataRetrieval::isObjectSchema)// .map(ObjectSchema.class::cast).collect(Collectors.toSet()); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, .flatMap(s -> s.getProperties().entrySet().stream()).filter(e -> isIdLookup(e.getValue()))// .map(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); .type(inputOutputSchema.getTitle())// .name("Salesforce " + objectName)// .description("Salesforce " + objectName)// .type(inputOutputSchema.getTitle())// .name("Salesforce " + objectName)// .description("Salesforce " + objectName)//
@Test public void shouldAdaptObjectTypesMetadataForProperties() { final ObjectSchema globalObjectsPayload = new ObjectSchema(); final HashSet<Object> oneOf = new HashSet<>(); oneOf.add(simpleObjectSchema("Object1", "Object1 Label")); oneOf.add(simpleObjectSchema("Object2", "Object2 Label")); globalObjectsPayload.setOneOf(oneOf); final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED, MetaDataBuilder.on(CONTEXT).withPayload(globalObjectsPayload).build()); assertThat(metadata.properties).containsKey("sObjectName"); final List<PropertyPair> values = metadata.properties.get("sObjectName"); assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"), new PropertyPair("Object2", "Object2 Label")); }
Map<String, String> schemas, ObjectMapper m) throws JsonProcessingException { ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setTitle(name); objectSchema.setDescription(description); if (!isRaw) { if (extendedType != null) { JsonSchema[] extended = new JsonSchema[1]; SimpleTypeSchema typeExtended = new ObjectSchema(); typeExtended.set$ref(extendedType); extended[0] = typeExtended; objectSchema.setExtends(extended); objectSchema.setProperties(new LinkedHashMap<String, JsonSchema>()); for (Property property : properties) { String type = property.getType(); SimpleTypeSchema reference = new ObjectSchema(); reference.set$ref("#/schemas/" + type); array.setItemsSchema(reference); objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); objectSchema.getProperties().put(property.getName(), primitive); } else {
protected boolean _equals(ObjectSchema that) { return equals(getAdditionalProperties(), that.getAdditionalProperties()) && equals(getDependencies(), that.getDependencies()) && equals(getPatternProperties(), that.getPatternProperties()) && equals(getProperties(), that.getProperties()) && super._equals(that); }
public ObjectSchema objectSchema() { return new ObjectSchema(); }
addressSpacePlan.getMetadata().getName(), addressSpacePlan.getShortDescription(), isFree, true); ObjectSchema bindParameters = new ObjectSchema(); StringSchema sendAddressProperty = new StringSchema(); sendAddressProperty.setDescription("Addresses which the bound application will have permission to send to"); bindParameters.putProperty("sendAddresses", sendAddressProperty); bindParameters.putProperty("receiveAddresses", receiveAddressProperty); InputParameters bindParametersSchema = new InputParameters(bindParameters); ServiceBindingSchema bindSchema = new ServiceBindingSchema(bindParametersSchema); ObjectSchema serviceCreateParameters = new ObjectSchema(); StringSchema instanceNameProperty = new StringSchema(); instanceNameProperty.setDescription("The name of the address space to create"); instanceNameProperty.setMaxLength(64); instanceNameProperty.setPattern("^[a-z][a-z0-9-]{0,63}$"); serviceCreateParameters.putProperty("name", instanceNameProperty); InputParameters createParametersSchema = new InputParameters(serviceCreateParameters); InputParameters updateParametersSchema = null;
Map<String, String> schemas, ObjectMapper m) throws JsonProcessingException { ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setTitle(name); objectSchema.setDescription(description); if (!isRaw) { if (extendedType != null) { JsonSchema[] extended = new JsonSchema[1]; SimpleTypeSchema typeExtended = new ObjectSchema(); typeExtended.set$ref(extendedType); extended[0] = typeExtended; objectSchema.setExtends(extended); objectSchema.setProperties(new LinkedHashMap<String, JsonSchema>()); for (Property property : properties) { String type = property.getType(); SimpleTypeSchema reference = new ObjectSchema(); reference.set$ref("#/schemas/" + type); array.setItemsSchema(reference); objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); objectSchema.getProperties().put(property.getName(), primitive); } else {
@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; }
/** * Create a schema which verifies only that an object is of the given format. * @param format the format to expect * @return the schema verifying the given format */ public static JsonSchema minimalForFormat(JsonFormatTypes format) { if (format != null) { switch (format) { case ARRAY: return new ArraySchema(); case OBJECT: return new ObjectSchema(); case BOOLEAN: return new BooleanSchema(); case INTEGER: return new IntegerSchema(); case NUMBER: return new NumberSchema(); case STRING: return new StringSchema(); case NULL: return new NullSchema(); case ANY: default: } } return new AnySchema(); }
@Override public void property(BeanProperty prop) throws JsonMappingException { schema.putProperty(prop, propertySchema(prop)); }