@Test public void shouldFetchPathsWithNestedArraySchema() throws IOException { final ObjectSchema schema = mapper.readValue(getSchemaWithNestedArray(), ObjectSchema.class); final List<String> paths = new ArrayList<>(); JsonSchemaInspector.fetchPaths(null, paths, schema.getProperties()); assertThat(paths).hasSize(4); assertThat(paths).containsAll(Arrays.asList("Id", "PhoneNumbers.size()", "PhoneNumbers[].Name", "PhoneNumbers[].Number")); }
static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Map.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, subschema.asObjectSchema().getProperties()); } else if (subschema.isArraySchema()) { COLLECTION_PATHS.stream().map(p -> path + "." + p).forEach(paths::add); ObjectSchema itemSchema = getItemSchema(subschema.asArraySchema()); if (itemSchema != null) { fetchPaths(path + ARRAY_CONTEXT, paths, itemSchema.getProperties()); } } } }
JsonSchemaInspector implements Inspector { static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Map.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, subschema.asObjectSchema().getProperties()); } else if (subschema.isArraySchema()) { COLLECTION_PATHS.stream().map(p -> path + "." + p).forEach(paths::add); ObjectSchema itemSchema = getItemSchema(subschema.asArraySchema()); if (itemSchema != null) { fetchPaths(path + ARRAY_CONTEXT, paths, itemSchema.getProperties()); } } } } }
JsonSchemaInspector implements Inspector { static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Map.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, subschema.asObjectSchema().getProperties()); } else if (subschema.isArraySchema()) { COLLECTION_PATHS.stream().map(p -> path + "." + p).forEach(paths::add); ObjectSchema itemSchema = getItemSchema(subschema.asArraySchema()); if (itemSchema != null) { fetchPaths(path + ARRAY_CONTEXT, paths, itemSchema.getProperties()); } } } }  }
JsonSchemaInspector implements Inspector { static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Map.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, subschema.asObjectSchema().getProperties()); } else if (subschema.isArraySchema()) { COLLECTION_PATHS.stream().map(p -> path + "." + p).forEach(paths::add); ObjectSchema itemSchema = getItemSchema(subschema.asArraySchema()); if (itemSchema != null) { fetchPaths(path + ARRAY_CONTEXT, paths, itemSchema.getProperties()); } } } }  @Override List<String> getPaths(final String kind, final String type, final String specification,
        final Optional<byte[]> exemplar); @Override boolean supports(final String kind, final String type, final String specification,
        final Optional<byte[]> exemplar); }
JsonSchemaInspector implements Inspector { static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Map.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, subschema.asObjectSchema().getProperties()); } else if (subschema.isArraySchema()) { COLLECTION_PATHS.stream().map(p -> path + "." + p).forEach(paths::add); ObjectSchema itemSchema = getItemSchema(subschema.asArraySchema()); if (itemSchema != null) { fetchPaths(path + ARRAY_CONTEXT, paths, itemSchema.getProperties()); } } } }  @Override List<String> getPaths(final String kind, final String type, final String specification,
        final Optional<byte[]> exemplar); @Override boolean supports(final String kind, final String type, final String specification,
        final Optional<byte[]> exemplar);  }