List getTypes()

in graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/json/JSONTypeFactory.java [51:103]


    List<JSONType> getTypes(Map<String, Object> schemaTree) {
        if (schemaTree.containsKey("anyOf")) {
            List<JSONType> result = new ArrayList<>();
            List<Map<String, Object>> anyOf = (List<Map<String, Object>>) schemaTree.get("anyOf");
            for (Map<String, Object> any : anyOf) {
                result.addAll(getTypes(any));
            }
            return result;
        }
        if (schemaTree.containsKey("$ref")) {
            String schemaId = (String) schemaTree.get("$ref");
            JsonSchemaWrapper refSchema = schemaService.getSchema(schemaId);
            if (refSchema != null) {
                schemaTree = GraphQLSchemaProvider.buildJSONSchema(refSchema, schemaService).getSchemaTree();
            } else {
                System.err.println("Couldn't find schema for ref " + schemaId);
            }
        }
        if (schemaTree.containsKey("enum")) {
            List<JSONType> result = new ArrayList<>();
            result.add(new JSONEnumType(schemaTree, this));
            return result;
        }
        Object typeObject = schemaTree.get("type");
        if (typeObject == null) {
            return new ArrayList<>();
        }
        List<String> types = null;
        if (typeObject instanceof String) {
            types = new ArrayList<>();
            types.add((String) typeObject);
        } else {
            types = (List<String>) typeObject;
        }
        List<JSONType> resultJsonTypes = new ArrayList<>();
        for (String type : types) {
            if (type == null) {
                continue;
            }
            if (!jsonTypes.containsKey(type)) {
                continue;
            }
            Class<? extends JSONType> typeClass = jsonTypes.get(type);
            Constructor<? extends JSONType> constructor;
            try {
                constructor = typeClass.getConstructor(Map.class, JSONTypeFactory.class);
                resultJsonTypes.add(constructor.newInstance(schemaTree, this));
            } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
                LOGGER.error("Error while building object type", e);
            }
        }
        return resultJsonTypes;
    }