Java Code Examples for org.eclipse.microprofile.openapi.models.OpenAPI#getTags()

The following examples show how to use org.eclipse.microprofile.openapi.models.OpenAPI#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: JaxRsAnnotationScanner.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Override
public OpenAPI scan(final AnnotationScannerContext context, OpenAPI openApi) {
    // Get all JaxRs applications and convert them to OpenAPI models (and merge them into a single one)
    processApplicationClasses(context, openApi);

    // This needs to be here just after we have done JaxRs Application
    boolean tagsDefined = openApi.getTags() != null && !openApi.getTags().isEmpty();

    // Now find all jax-rs endpoints
    processResourceClasses(context, openApi);

    // Sort the tags unless the application has defined the order in OpenAPIDefinition annotation(s)
    sortTags(openApi, tagsDefined);

    // Now that all paths have been created, sort them (we don't have a better way to organize them).
    sortPaths(openApi);

    return openApi;
}
 
Example 2
Source File: ModelUtil.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a {@link Tag} to the {@link OpenAPI} model. If a tag having the same
 * name already exists in the model, the tags' attributes are merged, with the
 * new tag's attributes overriding the value of any attributes specified on
 * both.
 * 
 * @param openApi the OpenAPI model
 * @param tag a new {@link Tag} to add
 */
public static void addTag(OpenAPI openApi, Tag tag) {
    List<Tag> tags = openApi.getTags();

    if (tags == null || tags.isEmpty()) {
        openApi.addTag(tag);
        return;
    }

    Tag current = tags.stream().filter(t -> t.getName().equals(tag.getName())).findFirst().orElse(null);
    int currentIndex = tags.indexOf(current);

    if (current != null) {
        Tag replacement = MergeUtil.mergeObjects(current, tag);
        tags = new ArrayList<>(tags);
        tags.set(currentIndex, replacement);
        openApi.setTags(tags);
    } else {
        openApi.addTag(tag);
    }
}
 
Example 3
Source File: SpringAnnotationScanner.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Override
public OpenAPI scan(final AnnotationScannerContext context, OpenAPI openApi) {
    // Get all Spring controllers and convert them to OpenAPI models (and merge them into a single one)
    processControllerClasses(context, openApi);

    boolean tagsDefined = openApi.getTags() != null && !openApi.getTags().isEmpty();

    // Sort the tags unless the application has defined the order in OpenAPIDefinition annotation(s)
    sortTags(openApi, tagsDefined);

    // Now that all paths have been created, sort them (we don't have a better way to organize them).
    sortPaths(openApi);

    return openApi;
}
 
Example 4
Source File: AnnotationScanner.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Sort the tags unless the application has defined the order in OpenAPIDefinition annotation(s)
 * 
 * @param openApi the openAPI model
 * @param tagsDefined is the tags defined
 */
default void sortTags(OpenAPI openApi, boolean tagsDefined) {

    if (!tagsDefined && openApi.getTags() != null) {
        openApi.setTags(openApi.getTags()
                .stream()
                .sorted(Comparator.comparing(Tag::getName))
                .collect(Collectors.toList()));
    }
}