Java Code Examples for io.swagger.v3.oas.models.media.Content#forEach()

The following examples show how to use io.swagger.v3.oas.models.media.Content#forEach() . 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: OperationBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Merge operation operation.
 *
 * @param operation the operation
 * @param operationModel the operation model
 * @return the operation
 */
public Operation mergeOperation(Operation operation, Operation operationModel) {
	if (operationModel.getOperationId().length() < operation.getOperationId().length()) {
		operation.setOperationId(operationModel.getOperationId());
	}

	ApiResponses apiResponses = operation.getResponses();
	for (Entry<String, ApiResponse> apiResponseEntry : operationModel.getResponses().entrySet()) {
		if (apiResponses.containsKey(apiResponseEntry.getKey())) {
			Content existingContent = apiResponses.get(apiResponseEntry.getKey()).getContent();
			Content newContent = apiResponseEntry.getValue().getContent();
			if (newContent != null)
				newContent.forEach((mediaTypeStr, mediaType) -> SpringDocAnnotationsUtils.mergeSchema(existingContent, mediaType.getSchema(), mediaTypeStr));
		}
		else
			apiResponses.addApiResponse(apiResponseEntry.getKey(), apiResponseEntry.getValue());
	}
	return operation;
}
 
Example 2
Source File: MediaContentComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public StructuralNode apply(StructuralNode node, MediaContentComponent.Parameters parameters) {
    Content content = parameters.content;
    if (content == null || content.isEmpty()) return node;

    DescriptionListImpl mediaContentList = new DescriptionListImpl(node);
    mediaContentList.setTitle(labels.getLabel(LABEL_CONTENT));

    content.forEach((type, mediaType) -> {
        DescriptionListEntryImpl tagEntry = new DescriptionListEntryImpl(mediaContentList, Collections.singletonList(new ListItemImpl(mediaContentList, type)));
        ListItemImpl tagDesc = new ListItemImpl(tagEntry, "");

        Document tagDescDocument = schemaComponent.apply(mediaContentList, mediaType.getSchema());
        mediaTypeExampleComponent.apply(tagDescDocument, mediaType.getExample());
        examplesComponent.apply(tagDescDocument, mediaType.getExamples());
        encodingComponent.apply(tagDescDocument, mediaType.getEncoding());
        tagDesc.append(tagDescDocument);

        tagEntry.setDescription(tagDesc);
        mediaContentList.addEntry(tagEntry);
    });
    node.append(mediaContentList);
    return node;
}