All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xliic.openapi.bundler.Mapping Maven / Gradle / Ivy

Go to download

Bundles multiple OpenAPI files (in JSON or YAML formats) using external references into one JSON file.

There is a newer version: 4.0
Show newest version
package com.xliic.openapi.bundler;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;

public class Mapping {
    Location value = null;
    HashMap children = new HashMap<>();

    public Location find(String pointer) throws UnsupportedEncodingException {
        Mapping current = this;
        JsonPath path = new JsonPointer(pointer).getJsonPath();

        int i = 0;
        for (; i < path.size() && current.children.containsKey(path.get(i)); i++) {
            current = current.children.get(path.get(i));
        }

        Location value = current.value;

        if (value == null) {
            // mapping wasn't found
            return null;
        }

        if (i < path.size()) {
            JsonPath remaining = new JsonPath(path.subList(i, path.size()));
            return new Location(value.file, value.pointer + remaining.toPointer());
        }

        return value;
    }

    public static class Location {
        public final String file;
        public final String pointer;

        public Location(String file, JsonPointer pointer) {
            this.file = file;
            this.pointer = pointer.getValue();
        }

        public Location(String file, String pointer) {
            this.file = file;
            this.pointer = pointer;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy