!requestBody.getContent().isEmpty()) { if (requestBodyParameter.getSchema() != null) { for (MediaType mediaType : requestBody.getContent().values()) { if (mediaType.getSchema() == null) { if (requestBodyParameter.getSchema() == null) {
private static Schema getSchemaFromContent(Content content) { if (content == null || content.isEmpty()) { return null; } if (content.size() > 1) { LOGGER.warn("Multiple schemas found, returning only the first one"); } MediaType mediaType = content.values().iterator().next(); return mediaType.getSchema(); }
@Override public boolean matches(final Message message, final ApiOperation operation, final Response response) { if (operation == null || operation.getOperation().getResponses() == null) { return false; } final ApiResponse apiResponse = getApiResponse(response, operation); if (apiResponse == null) { return false; } // TODO: This should really respect the content-type of the response to filter schemas return apiResponse.getContent().values().stream() .map(MediaType::getSchema) .filter(Objects::nonNull) .map(Schema::get$ref) .filter(Objects::nonNull) .anyMatch($ref -> $ref.endsWith("/" + entityName)); }
@Override public boolean matches(final Message message, final ApiOperation operation, final Request request) { if (operation == null || operation.getOperation().getRequestBody() == null) { return false; } final RequestBody apiRequestBody = operation.getOperation().getRequestBody(); // TODO: This should really respect the content-type of the response to filter schemas return apiRequestBody.getContent().values().stream() .map(MediaType::getSchema) .filter(Objects::nonNull) .map(Schema::get$ref) .filter(Objects::nonNull) .anyMatch($ref -> $ref.endsWith("/" + entityName)); }
private static void setRequestBodyExamples(Parameter bodyParameter, RequestBody requestBody) { requestBody.getContent().values().forEach(mediaType -> { if (bodyParameter.getExample() != null) { mediaType.example(bodyParameter.getExample()); } }); } }
public RequestBodyAdapter(Swagger2MarkupConverter.Context context, PathOperation operation, RequestBody body, DocumentResolver definitionDocumentResolver) { Validate.notNull(body, "parameter must not be null"); this.body = body; this.context = context; this.config = context.getConfig(); this.schema = body.getContent() .values() .stream() .findFirst() .map(MediaType::getSchema) .orElseThrow(IllegalArgumentException::new); this.schema.setTitle("body"); this.type = getType(definitionDocumentResolver); if (config.isInlineSchemaEnabled()) { type = InlineSchemaUtils.createInlineType(type, "body", "body", inlineDefinitions); } }
/** * Return the example value of the parameter. * * @param codegenParameter Codegen parameter * @param requestBody Request body */ public void setParameterExampleValue(CodegenParameter codegenParameter, RequestBody requestBody) { Content content = requestBody.getContent(); if (content.size() > 1) { // @see ModelUtils.getSchemaFromContent() LOGGER.warn("Multiple MediaTypes found, using only the first one"); } MediaType mediaType = content.values().iterator().next(); if (mediaType.getExample() != null) { codegenParameter.example = mediaType.getExample().toString(); return; } if (mediaType.getExamples() != null && !mediaType.getExamples().isEmpty()) { Example example = mediaType.getExamples().values().iterator().next(); if (example.getValue() != null) { codegenParameter.example = example.getValue().toString(); return; } } setParameterExampleValue(codegenParameter); }
protected Schema getSchemaFromResponse(ApiResponse response) { if (response.getContent() == null || response.getContent().isEmpty()) { return null; } Schema schema = null; for (MediaType mediaType : response.getContent().values()) { schema = mediaType.getSchema(); break; } return schema; }
protected Schema getSchemaFromResponse(ApiResponse response) { if (response.getContent() == null || response.getContent().isEmpty()) { return null; } Schema schema = null; for (MediaType mediaType : response.getContent().values()) { schema = mediaType.getSchema(); break; } return schema; }
.values() .stream() .findFirst()
final Optional<MediaType> mediaTypeOptional = Optional.ofNullable(requestBody).map(RequestBody::getContent) .flatMap(content -> content.values().stream().findFirst());
!requestBody.getContent().isEmpty()) { if (requestBodyParameter.getSchema() != null) { for (MediaType mediaType : requestBody.getContent().values()) { if (mediaType.getSchema() == null) { if (requestBodyParameter.getSchema() == null) {
for (MediaType mediaType : requestBody.getContent().values())
!requestBody.getContent().isEmpty()) { if (requestBodyParameter.getSchema() != null) { for (MediaType mediaType : requestBody.getContent().values()) { if (mediaType.getSchema() == null) { if (requestBodyParameter.getSchema() == null) {
String existing = matchGenerated(model); Content content = response.getContent(); for (MediaType mediaType : content.values()) { if (existing != null) { Schema schema = this.makeSchema(existing, property);