@Test public void shouldFindTwoStepCyclicReferencesInResponses() { final Oas20Document openApiDoc = new Oas20Document(); final Oas20PathItem pathItem = new Oas20PathItem("/api"); final Oas20Operation operation = new Oas20Operation("post"); Oas20Response response = new Oas20Response("200"); Oas20Schema responseSchema = new Oas20Schema(); responseSchema.$ref = "#/definitions/A"; response.schema = responseSchema; operation.responses = operation.createResponses(); operation.responses.addResponse("200", response); pathItem.post = operation; openApiDoc.paths = openApiDoc.createPaths(); openApiDoc.paths.addPathItem("/api", pathItem); Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A"); schemaDefinitionA.type = "object"; Oas20Schema propertySchemaA = new Oas20Schema(); propertySchemaA.$ref = "#/definitions/B"; schemaDefinitionA.properties = new HashMap<>(); schemaDefinitionA.properties.put("b", propertySchemaA); openApiDoc.definitions = openApiDoc.createDefinitions(); openApiDoc.definitions.addDefinition("A", schemaDefinitionA); Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B"); schemaDefinitionB.type = "object"; Oas20Schema propertySchemaB = new Oas20Schema(); propertySchemaB.$ref = "#/definitions/A"; schemaDefinitionB.properties = new HashMap<>(); schemaDefinitionB.properties.put("a", propertySchemaB); openApiDoc.definitions.addDefinition("B", schemaDefinitionB); assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue(); }
static boolean hasCyclicReferences(final Map<String, ? extends OasSchema> schemaDefinitions) { if (schemaDefinitions.isEmpty()) { return false; } final Map<String, Set<String>> references = collectReferences(schemaDefinitions); return isCyclic(references); }
CyclicValidationCheck { static boolean hasCyclicReferences(final Map<String, ? extends OasSchema> schemaDefinitions) { if (schemaDefinitions.isEmpty()) { return false; } final Map<String, Set<String>> references = collectReferences(schemaDefinitions); return isCyclic(references); } }
CyclicValidationCheck { static boolean hasCyclicReferences(final Map<String, ? extends OasSchema> schemaDefinitions) { if (schemaDefinitions.isEmpty()) { return false; } final Map<String, Set<String>> references = collectReferences(schemaDefinitions); return isCyclic(references); } private  CyclicValidationCheck(); }
CyclicValidationCheck { static boolean hasCyclicReferences(final Map<String, ? extends OasSchema> schemaDefinitions) { if (schemaDefinitions.isEmpty()) { return false; } final Map<String, Set<String>> references = collectReferences(schemaDefinitions); return isCyclic(references); } private  CyclicValidationCheck();  }
CyclicValidationCheck { static boolean hasCyclicReferences(final Map<String, ? extends OasSchema> schemaDefinitions) { if (schemaDefinitions.isEmpty()) { return false; } final Map<String, Set<String>> references = collectReferences(schemaDefinitions); return isCyclic(references); } private  CyclicValidationCheck();   }