Java Code Examples for io.swagger.models.Swagger#getTags()

The following examples show how to use io.swagger.models.Swagger#getTags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagDescriptionAsNameSwaggerFilter.java    From RestDoc with Apache License 2.0 6 votes vote down vote up
@Override
public Swagger handle(Swagger swagger) {
    if (swagger.getTags() == null) return swagger;

    for (Tag tag : swagger.getTags())
    {
        String newTagName = TextUtils.getFirstLine(tag.getDescription());

        swagger.getPaths().values().forEach(path -> {
            handleOperation(tag, newTagName, path.getGet());
            handleOperation(tag, newTagName, path.getPost());
            handleOperation(tag, newTagName, path.getPut());
            handleOperation(tag, newTagName, path.getDelete());
            handleOperation(tag, newTagName, path.getHead());
            handleOperation(tag, newTagName, path.getOptions());
            handleOperation(tag, newTagName, path.getPatch());
        });

        tag.setName(newTagName);
    }
    return swagger;
}
 
Example 2
Source File: SwaggerInventory.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
public SwaggerInventory process(Swagger swagger) {
    Iterator var2;
    if(swagger.getTags() != null) {
        var2 = swagger.getTags().iterator();

        while(var2.hasNext()) {
            Tag key = (Tag)var2.next();
            this.process(key);
        }
    }

    String key1;
    if(swagger.getPaths() != null) {
        var2 = swagger.getPaths().keySet().iterator();

        while(var2.hasNext()) {
            key1 = (String)var2.next();
            Path model = swagger.getPath(key1);
            this.process(model);
        }
    }

    if(swagger.getDefinitions() != null) {
        var2 = swagger.getDefinitions().keySet().iterator();

        while(var2.hasNext()) {
            key1 = (String)var2.next();
            Model model1 = (Model)swagger.getDefinitions().get(key1);
            this.process(model1);
        }
    }

    return this;
}
 
Example 3
Source File: Utils.java    From swagger-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void sortSwagger(Swagger swagger) throws GenerateException {
    if (swagger == null || swagger.getPaths() == null) {
        return;
    }

    TreeMap<String, Path> sortedMap = new TreeMap<String, Path>();
    if (swagger.getPaths() == null) {
        return;
    }
    sortedMap.putAll(swagger.getPaths());
    swagger.paths(sortedMap);

    for (Path path : swagger.getPaths().values()) {
        String methods[] = {"Get", "Delete", "Post", "Put", "Options", "Patch"};
        for (String m : methods) {
            sortResponses(path, m);
        }
    }

    //reorder definitions
    if (swagger.getDefinitions() != null) {
        TreeMap<String, Model> defs = new TreeMap<String, Model>();
        defs.putAll(swagger.getDefinitions());
        swagger.setDefinitions(defs);
    }

    // order the tags
    if (swagger.getTags() != null) {
        Collections.sort(swagger.getTags(), new Comparator<Tag>() {
            public int compare(final Tag a, final Tag b) {
                return a.toString().toLowerCase().compareTo(b.toString().toLowerCase());
            }
        });
    }

}