(schemas []*Schema, schemaList []string, schema *Schema, visitedSchema map[string]state)
| 175 | ) |
| 176 | |
| 177 | func visitSchema(schemas []*Schema, schemaList []string, schema *Schema, visitedSchema map[string]state) ([]string, error) { |
| 178 | if visitedSchema[schema.ID] == temporaryVisited { |
| 179 | return nil, fmt.Errorf("Schemas aren't DAG. We can't reorder automatically") |
| 180 | } |
| 181 | if visitedSchema[schema.ID] == visited { |
| 182 | return schemaList, nil |
| 183 | } |
| 184 | visitedSchema[schema.ID] = temporaryVisited |
| 185 | relatedSchemas := schema.relatedSchemas() |
| 186 | var err error |
| 187 | for _, relatedSchemaID := range relatedSchemas { |
| 188 | for _, candidate := range schemas { |
| 189 | if candidate.ID == relatedSchemaID { |
| 190 | schemaList, err = visitSchema(schemas, schemaList, candidate, visitedSchema) |
| 191 | if err != nil { |
| 192 | return nil, err |
| 193 | } |
| 194 | break |
| 195 | } |
| 196 | } |
| 197 | if err != nil { |
| 198 | return nil, err |
| 199 | } |
| 200 | } |
| 201 | visitedSchema[schema.ID] = visited |
| 202 | schemaList = append(schemaList, schema.ID) |
| 203 | return schemaList, nil |
| 204 | } |
| 205 | |
| 206 | func reorderSchemas(schemas []*Schema) ([]string, error) { |
| 207 | var err error |
no test coverage detected