public JsonSchema build() { final JsonSchema jsonSchema = new JsonSchema(); jsonSchema.setId(id); jsonSchema.setTitle(title); jsonSchema.setDescription(description); jsonSchema.setSchema(schema); jsonSchema.setRef(ref); jsonSchema.setType(type); jsonSchema.setMinItems(minItems); jsonSchema.setMaxItems(maxItems); jsonSchema.setMinLength(minLength); jsonSchema.setMaxLength(maxLength); jsonSchema.setMinimum(minimum); jsonSchema.setMaximum(maximum); jsonSchema.setUniqueItems(uniqueItems); jsonSchema.setPattern(pattern); jsonSchema.setDefaultValue(defaultValue); jsonSchema.setRequired(required); jsonSchema.setProperties(properties); jsonSchema.setEnumValues(enumValues); jsonSchema.setItems(items); return jsonSchema; } }
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenCompose(context -> { final UiSchema schema = newUiSchema(context); schema.setWidget("datalist"); schema.setTitleMap(emptyList()); final JsonSchema jsonSchema = findJsonSchema(context); if (jsonSchema != null) { if (jsonSchema.getType() == null) { jsonSchema.setType("string"); } // avoid to validate against the enum since we don't udpate it at suggestion time jsonSchema.setEnumValues(null); } return CompletableFuture.completedFuture(context); }); } }
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenCompose(context -> { jsonSchema.setType(context.getProperty().getType().toLowerCase(ROOT)); final String prefix = context.getProperty().getPath() + "[]"; final List<SimplePropertyDefinition> arrayElements = final JsonSchema items = new JsonSchema(); items.setType("object"); items.setProperties(new HashMap<>()); jsonSchema.setItems(items); return CompletableFuture .allOf(arrayElements } else if (!arrayElements.isEmpty()) { // primitive final String type = arrayElements.get(0).getType(); final JsonSchema item = new JsonSchema(); item.setTitle(jsonSchema.getTitle()); item.setType("enum".equalsIgnoreCase(type) ? "string" : type.toLowerCase(ROOT)); jsonSchema.setItems(item);
ui.setUiSchema(new ArrayList<>()); ui.setProperties(new HashMap<>()); ui.setJsonSchema(new JsonSchema()); ui.getJsonSchema().setTitle(displayName.get()); ui.getJsonSchema().setType("object"); ui .getJsonSchema() .setRequired(props .stream() .filter(isRootProperty)
ofNullable(validation.getMin()).ifPresent(m -> jsonSchema.setMinimum(m.doubleValue())); ofNullable(validation.getMax()).ifPresent(m -> jsonSchema.setMaximum(m.doubleValue())); ofNullable(validation.getMinItems()).ifPresent(jsonSchema::setMinItems); ofNullable(validation.getMaxItems()).ifPresent(jsonSchema::setMaxItems); if (rootJsonSchema.getProperties() == null) { rootJsonSchema.setProperties(new HashMap<>()); rootJsonSchema.getProperties().put(context.getProperty().getName(), jsonSchema); final String order = context.getProperty().getMetadata().get("ui::optionsorder::value"); if (order != null) { jsonSchema.setProperties(new TreeMap<>(new Comparator<String>() { jsonSchema.setProperties(new HashMap<>());
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenCompose(context -> { final JsonSchema jsonSchema = new JsonSchema(); jsonSchema.setTitle(context.getProperty().getDisplayName()); final String type = context.getProperty().getType(); switch (type.toLowerCase(ROOT)) { return CompletableFuture.completedFuture(context); jsonSchema.setType(type.toLowerCase(ROOT)); of(context .findDirectChild(properties)
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenApply(context -> { jsonSchema.setType("string"); if (context.getProperty().getValidation() == null || context.getProperty().getValidation().getEnumValues() == null) { jsonSchema.setEnumValues(emptyList()); } else { jsonSchema.setEnumValues(context.getProperty().getValidation().getEnumValues()); } return context; }); } }
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenCompose(context -> { final UiSchema schema = newUiSchema(context); setupUiSchema(context, schema); final JsonSchema jsonSchema = findJsonSchema(context); if (jsonSchema == null) { // unexpected return CompletableFuture.completedFuture(context); } if (jsonSchema.getType() == null) { jsonSchema.setType("string"); } return fillProposalsAndReturn(context, schema, jsonSchema); }); }
@CacheResult(cacheName = "org.talend.sdk.component.proxy.validation.jsonschema") public CompletionStage<JsonSchemaValidator> getValidator(final RequestContext context, final String formId) { return configurations.getDetails(context.language(), formId, context::findPlaceholder).thenCompose(config -> { final JsonSchema jsonSchema = new JsonSchema(); final JsonSchemaConverter converter = new JsonSchemaConverter(jsonb, jsonSchema, config.getProperties()); return CompletableFuture .allOf(config .getProperties() .stream() .filter(Objects::nonNull) .filter(p -> p.getName().equals(p.getPath())) .map(it -> new PropertyContext<>(it, context, LIGHT_CONTEXT_CONFIGURATION)) .map(CompletionStages::toStage) .map(converter::convert) .toArray(CompletableFuture[]::new)) .thenApply(r -> jsonSchema); }).thenApply(schema -> jsonb.fromJson(jsonb.toJson(schema), JsonObject.class)).thenApply(factory::newInstance); } }
return nameValue; }).collect(toList())); jsonSchema.setEnumValues(context.getProperty().getValidation().getEnumValues()); } else { final String actionName = context.getProperty().getMetadata().get("action::dynamic_values"); return pairs.thenApply(namedValues -> { schema.setTitleMap(namedValues); jsonSchema.setEnumValues(namedValues.stream().map(UiSchema.NameValue::getValue).collect(toList())); return context; });
if (jsonSchema.getType() == null) { jsonSchema.setType("string"); return pairs.thenApply(namedValues -> { schema.setTitleMap(namedValues); jsonSchema.setEnumValues(namedValues.stream().map(UiSchema.NameValue::getValue).collect(toList())); return context; });