@Test public void shouldFindNoCyclicReferencesWhenThereAreNone() { final Oas20Document openApiDoc = new Oas20Document(); final Oas20PathItem pathItem = new Oas20PathItem("/api"); final Oas20Operation operation = new Oas20Operation("post"); final Oas20Parameter parameter = new Oas20Parameter(); parameter.$ref = "#/definitions/Request"; operation.parameters = new ArrayList<>(); operation.parameters.add(parameter); Oas20Response response = new Oas20Response("200"); Oas20Schema responseSchema = new Oas20Schema(); responseSchema.$ref = "#/definitions/Response"; 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 requestSchemaDefinition = new Oas20SchemaDefinition("Request"); requestSchemaDefinition.type = "object"; Oas20Schema requestPropertySchema = new Oas20Schema(); requestPropertySchema.type = "integer"; requestPropertySchema.format = "int32"; requestSchemaDefinition.properties = new HashMap<>(); requestSchemaDefinition.properties.put("reqval", requestPropertySchema); openApiDoc.definitions = openApiDoc.createDefinitions(); openApiDoc.definitions.addDefinition("Request", requestSchemaDefinition); Oas20SchemaDefinition responseSchemaDefinition = new Oas20SchemaDefinition("Response"); responseSchemaDefinition.type = "object"; Oas20Schema responsePropertySchema = new Oas20Schema(); responsePropertySchema.type = "integer"; responsePropertySchema.format = "int32"; responseSchemaDefinition.properties = new HashMap<>(); responseSchemaDefinition.properties.put("resval", responsePropertySchema); openApiDoc.definitions.addDefinition("Request", responseSchemaDefinition); assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isFalse(); }
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();   }