Java Code Examples for io.github.swagger2markup.GroupBy#AS_IS

The following examples show how to use io.github.swagger2markup.GroupBy#AS_IS . 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: PathOperationComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a operation title to the document.
 *
 * @param title  the operation title
 * @param anchor optional anchor (null => auto-generate from title)
 */
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, String title, String anchor) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        markupDocBuilder.sectionTitleWithAnchorLevel2(title, anchor);
    } else {
        markupDocBuilder.sectionTitleWithAnchorLevel3(title, anchor);
    }
}
 
Example 2
Source File: PathOperationComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a operation section title to the document.
 *
 * @param title the section title
 */
private void buildSectionTitle(MarkupDocBuilder markupDocBuilder, String title) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        markupDocBuilder.sectionTitleLevel3(title);
    } else {
        markupDocBuilder.sectionTitleLevel4(title);
    }
}
 
Example 3
Source File: PathOperationComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
private void buildTagsSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        List<String> tags = operation.getOperation().getTags();
        if (CollectionUtils.isNotEmpty(tags)) {
            buildSectionTitle(markupDocBuilder, labels.getLabel(TAGS));
            if (config.getTagOrdering() != null) {
                tags.sort(config.getTagOrdering());
            }
            markupDocBuilder.unorderedList(tags);
        }
    }
}
 
Example 4
Source File: PathOperationComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the title level for sections
 */
private int getSectionTitleLevel() {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        return 3;
    } else {
        return 4;
    }
}
 
Example 5
Source File: PathOperationComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a example title to the document.
 *
 * @param title the section title
 */
private void buildExampleTitle(MarkupDocBuilder markupDocBuilder, String title) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        markupDocBuilder.sectionTitleLevel4(title);
    } else {
        markupDocBuilder.sectionTitleLevel5(title);
    }
}
 
Example 6
Source File: BodyParameterComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
private void buildSectionTitle(MarkupDocBuilder markupDocBuilder, String title) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        markupDocBuilder.sectionTitleLevel3(title);
    } else {
        markupDocBuilder.sectionTitleLevel4(title);
    }
}
 
Example 7
Source File: PathsDocument.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the paths section. Groups the paths either as-is, by tags or using regex.
 *
 * @param paths the Swagger paths
 */
private void buildsPathsSection(MarkupDocBuilder markupDocBuilder, Map<String, Path> paths) {
    List<SwaggerPathOperation> pathOperations = PathUtils.toPathOperationsList(paths, getHostname(), getBasePath(), config.getOperationOrdering());
    if (CollectionUtils.isNotEmpty(pathOperations)) {
        if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
            pathOperations.forEach(operation -> buildOperation(markupDocBuilder, operation, config));
        } else if (config.getPathsGroupedBy() == GroupBy.TAGS) {
            Validate.notEmpty(context.getSchema().getTags(), "Tags must not be empty, when operations are grouped by tags");
            // Group operations by tag
            Multimap<String, SwaggerPathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getOperationOrdering());

            Map<String, Tag> tagsMap = TagUtils.toSortedMap(context.getSchema().getTags(), config.getTagOrdering());

            tagsMap.forEach((String tagName, Tag tag) -> {
                markupDocBuilder.sectionTitleWithAnchorLevel2(WordUtils.capitalize(tagName), tagName + "_resource");
                String description = tag.getDescription();
                if (StringUtils.isNotBlank(description)) {
                    markupDocBuilder.paragraph(description);
                }
                operationsGroupedByTag.get(tagName).forEach(operation -> buildOperation(markupDocBuilder, operation, config));

            });
        } else if (config.getPathsGroupedBy() == GroupBy.REGEX) {
            Validate.notNull(config.getHeaderPattern(), "Header regex pattern must not be empty when operations are grouped using regex");

            Pattern headerPattern = config.getHeaderPattern();
            Multimap<String, SwaggerPathOperation> operationsGroupedByRegex = RegexUtils.groupOperationsByRegex(pathOperations, headerPattern);
            Set<String> keys = operationsGroupedByRegex.keySet();
            String[] sortedHeaders = RegexUtils.toSortedArray(keys);

            for (String header : sortedHeaders) {
                markupDocBuilder.sectionTitleWithAnchorLevel2(WordUtils.capitalize(header), header + "_resource");
                operationsGroupedByRegex.get(header).forEach(operation -> buildOperation(markupDocBuilder, operation, config));
            }
        }
    }
}
 
Example 8
Source File: PathsDocument.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the path title depending on the operationsGroupedBy configuration setting.
 */
private void buildPathsTitle(MarkupDocBuilder markupDocBuilder) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.PATHS));
    } else if (config.getPathsGroupedBy() == GroupBy.REGEX) {
        buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.OPERATIONS));
    } else {
        buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.RESOURCES));
    }
}
 
Example 9
Source File: PathsDocument.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a operation title to the document.
 *
 * @param title  the operation title
 * @param anchor optional anchor (null => auto-generate from title)
 */
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, String title, String anchor) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        markupDocBuilder.sectionTitleWithAnchorLevel2(title, anchor);
    } else {
        markupDocBuilder.sectionTitleWithAnchorLevel3(title, anchor);
    }
}