Java Code Examples for io.github.swagger2markup.markup.builder.MarkupDocBuilder#paragraph()

The following examples show how to use io.github.swagger2markup.markup.builder.MarkupDocBuilder#paragraph() . 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: SecuritySchemeDefinitionComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    String securitySchemeDefinitionName = params.securitySchemeDefinitionName;
    SecuritySchemeDefinition securitySchemeDefinition = params.securitySchemeDefinition;
    applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_BEFORE, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
    markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, securitySchemeDefinitionName);
    applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_BEGIN, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
    String description = securitySchemeDefinition.getDescription();
    if (isNotBlank(description)) {
        markupDocBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
                markupDocBuilder, description));
    }
    buildSecurityScheme(markupDocBuilder, securitySchemeDefinition);
    applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_END, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
    applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_AFTER, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
    return markupDocBuilder;
}
 
Example 2
Source File: PathOperationComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a operation description to the document.
 *
 * @param operation the Swagger Operation
 */
private void buildDescriptionSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
    MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder);
    applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEGIN, descriptionBuilder, operation));
    String description = operation.getOperation().getDescription();
    if (isNotBlank(description)) {
        descriptionBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()), markupDocBuilder, description));
    }
    applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_END, descriptionBuilder, operation));
    String descriptionContent = descriptionBuilder.toString();

    applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEFORE, markupDocBuilder, operation));
    if (isNotBlank(descriptionContent)) {
        buildSectionTitle(markupDocBuilder, labels.getLabel(DESCRIPTION));
        markupDocBuilder.text(descriptionContent);
    }
    applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_AFTER, markupDocBuilder, operation));
}
 
Example 3
Source File: ContactInfoComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    Contact contact = params.contact;
    if (isNotBlank(contact.getName()) || isNotBlank(contact.getEmail())) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CONTACT_INFORMATION));
        MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
        if (isNotBlank(contact.getName())) {
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.CONTACT_NAME))
                    .textLine(COLON + contact.getName());
        }
        if (isNotBlank(contact.getEmail())) {
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.CONTACT_EMAIL))
                    .textLine(COLON + contact.getEmail());
        }
        markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
    }
    return markupDocBuilder;
}
 
Example 4
Source File: LicenseInfoComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    Info info = params.info;
    License license = info.getLicense();
    String termOfService = info.getTermsOfService();
    if ((license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) || isNotBlank(termOfService)) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(LICENSE_INFORMATION));
        MarkupDocBuilder paragraph = copyMarkupDocBuilder(markupDocBuilder);
        if (license != null) {
            if (isNotBlank(license.getName())) {
                paragraph.italicText(labels.getLabel(LICENSE)).textLine(COLON + license.getName());
            }
            if (isNotBlank(license.getUrl())) {
                paragraph.italicText(labels.getLabel(LICENSE_URL)).textLine(COLON + license.getUrl());
            }
        }

        paragraph.italicText(labels.getLabel(TERMS_OF_SERVICE)).textLine(COLON + termOfService);

        markupDocBuilder.paragraph(paragraph.toString(), true);
    }

    return markupDocBuilder;
}
 
Example 5
Source File: DefinitionComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    String definitionName = params.definitionName;
    String definitionTitle = determineDefinitionTitle(params);

    Model model = params.model;
    applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_BEFORE, markupDocBuilder, definitionName, model));
    markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, definitionTitle, definitionName);
    applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_BEGIN, markupDocBuilder, definitionName, model));
    String description = model.getDescription();
    if (isNotBlank(description)) {
        markupDocBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
                markupDocBuilder, description));
    }
    inlineDefinitions(markupDocBuilder, typeSection(markupDocBuilder, definitionName, model), definitionName);
    applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_END, markupDocBuilder, definitionName, model));
    applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_AFTER, markupDocBuilder, definitionName, model));

    return markupDocBuilder;
}
 
Example 6
Source File: UriSchemeComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    Swagger swagger = params.swagger;
    if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.URI_SCHEME));
        MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
        if (isNotBlank(swagger.getHost())) {
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.HOST))
                    .textLine(COLON + swagger.getHost());
        }
        if (isNotBlank(swagger.getBasePath())) {
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.BASE_PATH))
                    .textLine(COLON + swagger.getBasePath());
        }
        if (isNotEmpty(swagger.getSchemes())) {
            List<String> schemes = swagger.getSchemes().stream()
                    .map(Enum::toString)
                    .collect(Collectors.toList());
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.SCHEMES))
                    .textLine(COLON + join(schemes, ", "));
        }
        markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
    }
    return markupDocBuilder;
}
 
Example 7
Source File: ExternalDocsComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    ExternalDocs externalDocs = params.externalDocs;
    String description = externalDocs.getDescription();
    String url = externalDocs.getUrl();
    if ((description != null && (isNotBlank(description) || (url != null && isNotBlank(url))))) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(EXTERNAL_DOCS));
        MarkupDocBuilder paragraph = copyMarkupDocBuilder(markupDocBuilder);

        if (isNotBlank(description)) {
            paragraph.italicText(labels.getLabel(EXTERNAL_DOCS_DESC)).textLine(COLON + description);
        }
        if (isNotBlank(url)) {
            paragraph.italicText(labels.getLabel(EXTERNAL_DOCS_URL)).textLine(COLON + url);
        }

        markupDocBuilder.paragraph(paragraph.toString(), true);
    }

    return markupDocBuilder;
}
 
Example 8
Source File: VersionInfoComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    String version = params.info.getVersion();
    if (isNotBlank(version)) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CURRENT_VERSION));
        MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
        paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.VERSION)).textLine(COLON + version);
        markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
    }
    return markupDocBuilder;
}
 
Example 9
Source File: SecuritySchemeDefinitionComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
private MarkupDocBuilder buildSecurityScheme(MarkupDocBuilder markupDocBuilder, SecuritySchemeDefinition securityScheme) {
    String type = securityScheme.getType();
    MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);

    paragraphBuilder.italicText(labels.getLabel(TYPE)).textLine(COLON + type);

    if (securityScheme instanceof ApiKeyAuthDefinition) {
        paragraphBuilder.italicText(labels.getLabel(NAME)).textLine(COLON + ((ApiKeyAuthDefinition) securityScheme).getName());
        paragraphBuilder.italicText(labels.getLabel(IN)).textLine(COLON + ((ApiKeyAuthDefinition) securityScheme).getIn());

        return markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
    } else if (securityScheme instanceof OAuth2Definition) {
        OAuth2Definition oauth2Scheme = (OAuth2Definition) securityScheme;
        String flow = oauth2Scheme.getFlow();
        paragraphBuilder.italicText(labels.getLabel(FLOW)).textLine(COLON + flow);
        if (isNotBlank(oauth2Scheme.getAuthorizationUrl())) {
            paragraphBuilder.italicText(labels.getLabel(AUTHORIZATION_URL)).textLine(COLON + oauth2Scheme.getAuthorizationUrl());
        }
        if (isNotBlank(oauth2Scheme.getTokenUrl())) {
            paragraphBuilder.italicText(labels.getLabel(TOKEN_URL)).textLine(COLON + oauth2Scheme.getTokenUrl());
        }

        markupDocBuilder.paragraph(paragraphBuilder.toString(), true);

        if (oauth2Scheme.getScopes() != null && !oauth2Scheme.getScopes().isEmpty()) {
            StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN)))
                    .putMetaData(TableComponent.WIDTH_RATIO, "3")
                    .putMetaData(TableComponent.HEADER_COLUMN, "true");
            StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
                    .putMetaData(TableComponent.WIDTH_RATIO, "17")
                    .putMetaData(TableComponent.HEADER_COLUMN, "true");

            for (Map.Entry<String, String> scope : oauth2Scheme.getScopes().entrySet()) {
                nameColumnBuilder.add(scope.getKey());
                descriptionColumnBuilder.add(scope.getValue());
            }

            return tableComponent.apply(markupDocBuilder, TableComponent.parameters(nameColumnBuilder.build(),
                    descriptionColumnBuilder.build()));
        } else {

            return markupDocBuilder;
        }

    } else {
        return markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
    }
}
 
Example 10
Source File: BodyParameterComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    SwaggerPathOperation operation = params.operation;
    List<ObjectType> inlineDefinitions = params.inlineDefinitions;
    if (config.isFlatBodyEnabled()) {
        List<Parameter> parameters = operation.getOperation().getParameters();
        if (CollectionUtils.isNotEmpty(parameters)) {
            for (Parameter parameter : parameters) {
                if (StringUtils.equals(parameter.getIn(), "body")) {
                    ParameterAdapter parameterAdapter = new ParameterAdapter(context,
                            operation, parameter, definitionDocumentResolver);

                    Type type = parameterAdapter.getType();
                    inlineDefinitions.addAll(parameterAdapter.getInlineDefinitions());

                    buildSectionTitle(markupDocBuilder, labels.getLabel(BODY_PARAMETER));
                    String description = parameter.getDescription();
                    if (isNotBlank(description)) {
                        MarkupLanguage markupLanguage = MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name());
                        markupDocBuilder.paragraph(markupDescription(markupLanguage, markupDocBuilder, description));
                    }

                    MarkupDocBuilder typeInfos = copyMarkupDocBuilder(markupDocBuilder);
                    typeInfos.italicText(labels.getLabel(NAME_COLUMN)).textLine(COLON + parameter.getName());
                    typeInfos.italicText(labels.getLabel(FLAGS_COLUMN)).textLine(COLON + (BooleanUtils.isTrue(parameter.getRequired()) ? labels.getLabel(FLAGS_REQUIRED).toLowerCase() : labels.getLabel(FLAGS_OPTIONAL).toLowerCase()));

                    if (!(type instanceof ObjectType)) {
                        typeInfos.italicText(labels.getLabel(TYPE_COLUMN)).textLine(COLON + type.displaySchema(markupDocBuilder));
                    }

                    markupDocBuilder.paragraph(typeInfos.toString(), true);

                    if (type instanceof ObjectType) {
                        List<ObjectType> localDefinitions = new ArrayList<>();

                        propertiesTableComponent.apply(markupDocBuilder, PropertiesTableComponent.parameters(
                                ((ObjectType) type).getProperties(),
                                operation.getId(),
                                localDefinitions
                        ));

                        inlineDefinitions.addAll(localDefinitions);
                    }
                }
            }
        }
    }
    return markupDocBuilder;
}
 
Example 11
Source File: OverviewDocument.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
void buildDescriptionParagraph(MarkupDocBuilder markupDocBuilder, String description) {
    if (isNotBlank(description)) {
        markupDocBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
                markupDocBuilder, description));
    }
}