- assertTrue(required.isArray());
- final var actualContainerArray = StreamSupport.stream(required.spliterator(), false)
- .map(JsonNode::textValue)
- .collect(Collectors.toSet());
- assertEquals(expected, actualContainerArray);
+ assertEquals(expected, required);
+ }
+
+ private static Set<String> extractSchemaRefFromPath(final Path path) {
+ if (path == null) {
+ return Set.of();
+ }
+ final var references = new HashSet<String>();
+ final var get = path.get();
+ if (get != null) {
+ references.addAll(schemaRefFromContent(get.responses().get("200").content()));
+ }
+ final var post = path.post();
+ if (post != null) {
+ references.addAll(schemaRefFromContent(post.requestBody().content()));
+ }
+ final var put = path.put();
+ if (put != null) {
+ references.addAll(schemaRefFromContent(put.requestBody().content()));
+ }
+ final var patch = path.patch();
+ if (patch != null) {
+ references.addAll(schemaRefFromContent(patch.requestBody().content()));
+ }
+ return references;
+ }
+
+ /**
+ * The schema node does not have 1 specific structure and the "$ref" child is not always the first child after
+ * schema. Possible schema structures include:
+ * <ul>
+ * <li>schema/$ref/{reference}</li>
+ * <li>schema/properties/{nodeName}/$ref/{reference}</li>
+ * <li>schema/properties/{nodeName}/items/$ref/{reference}</li>
+ * </ul>
+ * @param content the element identified with key "content"
+ * @return the set of referenced schemas
+ */
+ private static Set<String> schemaRefFromContent(final Map<String, MediaTypeObject> content) {
+ final HashSet<String> refs = new HashSet<>();
+ content.values().forEach(mediaType -> {
+ final var schema = mediaType.schema();
+ final var props = mediaType.schema().properties();
+ final String ref;
+ if (props == null) {
+ // either there is no node with the key "properties", try to find immediate child of schema
+ ref = schema.ref();
+ } else if (props.values().iterator().next().items() == null) {
+ // or the "properties" is defined and under that we didn't find the "items" node
+ // try to get "$ref" as immediate child under properties
+ ref = props.values().iterator().next().ref();
+ } else {
+ // or the "items" node is defined, in which case we try to get the "$ref" from this node
+ ref = props.values().iterator().next().items().ref();
+ }
+
+ if (ref != null) {
+ refs.add(ref.replaceFirst(COMPONENTS_PREFIX, ""));
+ }
+ });
+ return refs;