com.fibanez.jsonschema.content.generator.ArraySchemaGenerator Maven / Gradle / Ivy
package com.fibanez.jsonschema.content.generator;
import com.fibanez.jsonschema.content.Context;
import com.fibanez.jsonschema.content.generator.util.RandomUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.everit.json.schema.ArraySchema;
import org.everit.json.schema.Schema;
import org.everit.json.schema.StringSchema;
import org.json.JSONArray;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.fibanez.jsonschema.content.generator.util.RandomUtils.between;
import static org.apache.commons.lang3.Validate.isTrue;
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public final class ArraySchemaGenerator implements SchemaGenerator {
private static final String DRAFT_201909_PREFIX_ITEMS = "prefixItems";
@Override
public JSONArray generate(@NonNull ArraySchema schema, @NonNull JsonNode jsonNode) {
int totalItems = getTotalItems(schema);
boolean requireUniqueItems = schema.needsUniqueItems();
List itemSchema = schema.getItemSchemas();
if (itemSchema != null && !itemSchema.isEmpty()) {
return generateFromItemSchemas(itemSchema, jsonNode, totalItems, requireUniqueItems);
}
Schema allItemSchema = schema.getAllItemSchema();
if (Objects.nonNull(allItemSchema)) {
return generateFromAllItemsSchema(allItemSchema, jsonNode, totalItems, requireUniqueItems);
} else {
Schema stringSchema = StringSchema.builder().build();
return generateFromAllItemsSchema(stringSchema, jsonNode, totalItems, requireUniqueItems);
}
// TODO
// Map unprocessedProperties = schema.getUnprocessedProperties();
// return new JSONArray();
}
private JSONArray generateFromAllItemsSchema(Schema allItemSchema, JsonNode jsonNode, int totalItems, boolean requireUniqueItems) {
Collector
© 2015 - 2025 Weber Informatics LLC | Privacy Policy