Java Code Examples for io.github.swagger2markup.markup.builder.MarkupDocBuilder#sectionTitleLevel()
The following examples show how to use
io.github.swagger2markup.markup.builder.MarkupDocBuilder#sectionTitleLevel() .
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: ContactInfoComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@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 2
Source File: LicenseInfoComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@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 3
Source File: UriSchemeComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@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 4
Source File: ExternalDocsComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@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 5
Source File: VersionInfoComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@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 6
Source File: ConsumesComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CONSUMES)); markupDocBuilder.unorderedList(params.consumes.stream() .map(value -> literalText(markupDocBuilder, value)).collect(Collectors.toList())); return markupDocBuilder; }
Example 7
Source File: TagsComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.TAGS)); List<String> tagsList = params.tags.stream() .map(this::mapToString).collect(Collectors.toList()); if (config.getTagOrdering() != null) Collections.sort(tagsList, config.getTagOrdering()); markupDocBuilder.unorderedList(tagsList); return markupDocBuilder; }
Example 8
Source File: ProducesComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.PRODUCES)); markupDocBuilder.unorderedList(params.produces.stream() .map(value -> literalText(markupDocBuilder, value)).collect(Collectors.toList())); return markupDocBuilder; }
Example 9
Source File: ResponseComponent.java From swagger2markup with Apache License 2.0 | 4 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { SwaggerPathOperation operation = params.operation; Map<String, Response> responses = operation.getOperation().getResponses(); MarkupDocBuilder responsesBuilder = copyMarkupDocBuilder(markupDocBuilder); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_BEGIN, responsesBuilder, operation)); if (MapUtils.isNotEmpty(responses)) { StringColumn.Builder httpCodeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(HTTP_CODE_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "2"); StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "14") .putMetaData(TableComponent.HEADER_COLUMN, "true"); StringColumn.Builder schemaColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(SCHEMA_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "4") .putMetaData(TableComponent.HEADER_COLUMN, "true"); Map<String, Response> sortedResponses = toSortedMap(responses, config.getResponseOrdering()); sortedResponses.forEach((String responseName, Response response) -> { String schemaContent = labels.getLabel(NO_CONTENT); if (response.getResponseSchema() != null) { Model model = response.getResponseSchema(); Type type = null; if (model != null) { type = ModelUtils.getType(model, definitions, definitionDocumentResolver); } else { type = new BasicType("string", responseName); } if (config.isInlineSchemaEnabled()) { type = createInlineType(type, labels.getLabel(RESPONSE) + " " + responseName, operation.getId() + " " + labels.getLabel(RESPONSE) + " " + responseName, params.inlineDefinitions); } schemaContent = type.displaySchema(markupDocBuilder); } MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder); descriptionBuilder.text(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()), markupDocBuilder, response.getDescription())); Map<String, Property> headers = response.getHeaders(); if (MapUtils.isNotEmpty(headers)) { descriptionBuilder.newLine(true).boldText(labels.getLabel(HEADERS_COLUMN)).text(COLON); for (Map.Entry<String, Property> header : headers.entrySet()) { descriptionBuilder.newLine(true); Property headerProperty = header.getValue(); PropertyAdapter headerPropertyAdapter = new PropertyAdapter(headerProperty); Type propertyType = headerPropertyAdapter.getType(definitionDocumentResolver); String headerDescription = markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()), markupDocBuilder, headerProperty.getDescription()); Optional<Object> optionalDefaultValue = headerPropertyAdapter.getDefaultValue(); descriptionBuilder .literalText(header.getKey()) .text(String.format(" (%s)", propertyType.displaySchema(markupDocBuilder))); if (isNotBlank(headerDescription) || optionalDefaultValue.isPresent()) { descriptionBuilder.text(COLON); if (isNotBlank(headerDescription) && !headerDescription.endsWith(".")) headerDescription += "."; descriptionBuilder.text(headerDescription); optionalDefaultValue.ifPresent(o -> descriptionBuilder.text(" ") .boldText(labels.getLabel(DEFAULT_COLUMN)) .text(COLON).literalText(Json.pretty(o))); } } } httpCodeColumnBuilder.add(boldText(markupDocBuilder, responseName)); descriptionColumnBuilder.add(descriptionBuilder.toString()); schemaColumnBuilder.add(schemaContent); }); responsesBuilder = tableComponent.apply(responsesBuilder, TableComponent.parameters(httpCodeColumnBuilder.build(), descriptionColumnBuilder.build(), schemaColumnBuilder.build())); } applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_END, responsesBuilder, operation)); String responsesContent = responsesBuilder.toString(); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_BEFORE, markupDocBuilder, operation)); if (isNotBlank(responsesContent)) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(RESPONSES)); markupDocBuilder.text(responsesContent); } applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_AFTER, markupDocBuilder, operation)); return markupDocBuilder; }
Example 10
Source File: SecuritySchemeComponent.java From swagger2markup with Apache License 2.0 | 4 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { SwaggerPathOperation operation = params.operation; MarkupDocBuilder securityBuilder = copyMarkupDocBuilder(markupDocBuilder); List<Map<String, List<String>>> securitySchemes = operation.getOperation().getSecurity(); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_BEGIN, securityBuilder, operation)); if (CollectionUtils.isNotEmpty(securitySchemes)) { StringColumn.Builder typeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(TYPE_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "3"); StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "4"); StringColumn.Builder scopeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(SCOPES_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "13") .putMetaData(TableComponent.HEADER_COLUMN, "true"); for (Map<String, List<String>> securityScheme : securitySchemes) { for (Map.Entry<String, List<String>> securityEntry : securityScheme.entrySet()) { String securityKey = securityEntry.getKey(); String type = labels.getLabel(UNKNOWN); if (securityDefinitions != null && securityDefinitions.containsKey(securityKey)) { type = securityDefinitions.get(securityKey).getType(); } typeColumnBuilder.add(boldText(markupDocBuilder, type)); nameColumnBuilder.add(boldText(markupDocBuilder, crossReference(markupDocBuilder, securityDocumentResolver.apply(securityKey), securityKey, securityKey))); scopeColumnBuilder.add(Joiner.on(",").join(securityEntry.getValue())); } } securityBuilder = tableComponent.apply(securityBuilder, TableComponent.parameters(typeColumnBuilder.build(), nameColumnBuilder.build(), scopeColumnBuilder.build())); } applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_END, securityBuilder, operation)); String securityContent = securityBuilder.toString(); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_BEFORE, markupDocBuilder, operation)); if (isNotBlank(securityContent)) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SECURITY)); markupDocBuilder.text(securityContent); } applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_AFTER, markupDocBuilder, operation)); return markupDocBuilder; }
Example 11
Source File: ParameterTableComponent.java From swagger2markup with Apache License 2.0 | 4 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { SwaggerPathOperation operation = params.operation; List<ObjectType> inlineDefinitions = params.inlineDefinitions; List<Parameter> parameters = operation.getOperation().getParameters(); if (config.getParameterOrdering() != null) { Comparator<io.github.swagger2markup.model.Parameter> parameterOrdering = config.getParameterOrdering(); parameters.sort((o1, o2) -> { io.github.swagger2markup.model.Parameter p1 = new io.github.swagger2markup.model.Parameter(o1.getName(), o1.getIn()); io.github.swagger2markup.model.Parameter p2 = new io.github.swagger2markup.model.Parameter(o2.getName(), o2.getIn()); return parameterOrdering.compare(p1, p2); }); } // Filter parameters to display in parameters section List<Parameter> filteredParameters = parameters.stream() .filter(this::filterParameter).collect(Collectors.toList()); MarkupDocBuilder parametersBuilder = copyMarkupDocBuilder(markupDocBuilder); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_PARAMETERS_BEGIN, parametersBuilder, operation)); if (CollectionUtils.isNotEmpty(filteredParameters)) { StringColumn.Builder typeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(TYPE_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "2"); StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "3"); StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "9") .putMetaData(TableComponent.HEADER_COLUMN, "true"); StringColumn.Builder schemaColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(SCHEMA_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "4") .putMetaData(TableComponent.HEADER_COLUMN, "true"); StringColumn.Builder defaultColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DEFAULT_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "2") .putMetaData(TableComponent.HEADER_COLUMN, "true"); for (Parameter parameter : filteredParameters) { ParameterAdapter parameterAdapter = new ParameterAdapter(context, operation, parameter, definitionDocumentResolver); inlineDefinitions.addAll(parameterAdapter.getInlineDefinitions()); typeColumnBuilder.add(parameterAdapter.displayType(markupDocBuilder)); nameColumnBuilder.add(getParameterNameColumnContent(markupDocBuilder, parameterAdapter)); descriptionColumnBuilder.add(buildDescriptionForParameter(markupDocBuilder, parameterAdapter)); schemaColumnBuilder.add(parameterAdapter.displaySchema(markupDocBuilder)); defaultColumnBuilder.add(parameterAdapter.displayDefaultValue(markupDocBuilder)); } parametersBuilder = tableComponent.apply(parametersBuilder, TableComponent.parameters( typeColumnBuilder.build(), nameColumnBuilder.build(), descriptionColumnBuilder.build(), schemaColumnBuilder.build(), defaultColumnBuilder.build())); } applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_PARAMETERS_END, parametersBuilder, operation)); String parametersContent = parametersBuilder.toString(); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_PARAMETERS_BEFORE, markupDocBuilder, operation)); if (isNotBlank(parametersContent)) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(PARAMETERS)); markupDocBuilder.text(parametersContent); } applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_PARAMETERS_AFTER, markupDocBuilder, operation)); return markupDocBuilder; }