if (optionalRequestBody.isPresent()) { RequestBody requestBody = optionalRequestBody.get(); if (StringUtils.isBlank(requestBody.get$ref()) && (requestBody.getContent() == null || requestBody.getContent().isEmpty())) { if (requestBodyParameter.getSchema() != null) { Content content = processContent(requestBody.getContent(), requestBodyParameter.getSchema(), methodConsumes, classConsumes); requestBody.setContent(content); } else if (StringUtils.isBlank(requestBody.get$ref()) && requestBody.getContent() != null && !requestBody.getContent().isEmpty()) { if (requestBodyParameter.getSchema() != null) { for (MediaType mediaType : requestBody.getContent().values()) { if (mediaType.getSchema() == null) { if (requestBodyParameter.getSchema() == null) { if (operation.getRequestBody() == null) { boolean isRequestBodyEmpty = true; RequestBody requestBody = new RequestBody(); if (StringUtils.isNotBlank(requestBodyParameter.get$ref())) { requestBody.set$ref(requestBodyParameter.get$ref()); isRequestBodyEmpty = false; requestBody.setDescription(requestBodyParameter.getDescription()); isRequestBodyEmpty = false; requestBody.setRequired(requestBodyParameter.getRequired()); isRequestBodyEmpty = false;
return Optional.empty(); RequestBody requestBodyObject = new RequestBody(); boolean isEmpty = true; requestBodyObject.set$ref(requestBody.ref()); return Optional.of(requestBodyObject); requestBodyObject.setDescription(requestBody.description()); isEmpty = false; requestBodyObject.setRequired(requestBody.required()); isEmpty = false; if (extensions != null) { for (String ext : extensions.keySet()) { requestBodyObject.addExtension(ext, extensions.get(ext));
@Test(description = "it should serialize a ref BodyParameter") public void serializeRefBodyParameter() { final Schema model = new Schema().$ref("#/definitions/Cat"); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String json = "{\"content\":{\"*/*\":{\"schema\":{\"$ref\":\"#/definitions/Cat\"}}}}"; SerializationMatchers.assertEqualsToJson(p, json); }
Operation op = ops.get(key); if (op.getRequestBody() != null) { addContentSchemaRef(op.getRequestBody().getContent(), referencedDefinitions);
protected void updateLocalRefs(RequestBody body, String pathRef) { if(body.getContent() != null) { Map<String, MediaType> content = body.getContent(); for (String key: content.keySet()) { MediaType mediaType = content.get(key); if (mediaType.getSchema() != null) { updateLocalRefs(mediaType.getSchema(), pathRef); } } }else if(body.get$ref() != null){ } }
return null; final RequestBody body = new RequestBody(); String mungedRef = mungedRef(ref.textValue()); if (mungedRef != null) { body.set$ref(mungedRef); }else{ body.set$ref(ref.textValue()); body.setDescription(description); body.setRequired(required); body.setContent(getContent(contentNode, location + ".content", result)); body.setExtensions(extensions);
String $ref = convert.get$ref(); if ($ref != null && $ref.startsWith("#/components/requestBodies/") && isRefABodyParam(param)) { operation.setRequestBody(new RequestBody().$ref($ref)); } else if ($ref != null && $ref.startsWith("#/components/schemas/") && isRefAFormParam(param)) { formParams.add(param); body.getContent().forEach((key, content) -> { Schema schema = content.getSchema(); if (schema != null && schema.getRequired() != null && schema.getRequired().size() > 0) { body.setRequired(Boolean.TRUE);
/** * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#requestBodyObject * * @param rpc * @return */ protected RequestBody getRequestBody(Rpc rpc) { RequestBody requestBody = new RequestBody(); ProtoType protoType = rpc.requestType(); Type type = schmea.getType(protoType); requestBody.description(type.documentation()); requestBody.required(true); requestBody.content(getContent(rpc.requestType())); return requestBody; }
return getDefaultValue(); if (body.getContent() == null) { throw new BallerinaOpenApiException("RequestBody content cannot be null"); if (!StringUtils.isEmpty(body.get$ref())) { String refType = getReferenceType(body.get$ref()); body = openAPI.getComponents().getRequestBodies().get(refType); this.description = body.getDescription(); this.required = body.getRequired(); this.extensions = body.getExtensions(); this.ref = body.get$ref(); this.content = new LinkedHashSet<>(); for (Map.Entry<String, MediaType> m : body.getContent().entrySet()) { BallerinaMediaType bMedia = new BallerinaMediaType().buildContext(m.getValue(), openAPI); bMedia.setMediaType(m.getKey());
static void processFormParam(Parameter formParameter, Operation operation, MethodDoc methodDoc, Components components) { Option<Method> methodOpt = ReflectionKit.loadMethod(methodDoc); if (methodOpt.isDefined()) { Method method = methodOpt.get(); Consumes methodConsumes = ReflectionUtils.getAnnotation(method, Consumes.class); Consumes classConsumes = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Consumes.class); RequestBody requestBody = operation.getRequestBody() != null ? operation.getRequestBody() : new RequestBody(); requestBody.description(formParameter.getDescription()); if (!Strings.isNullOrEmpty(formParameter.getDescription())) { requestBody.setDescription(formParameter.getDescription()); } Content content = processContent(requestBody.getContent(), formParameter.getSchema(), methodConsumes, classConsumes, true); requestBody.setContent(content); setRequestBodyExamples(formParameter, requestBody); operation.setRequestBody(requestBody); } }
public void processReferenceRequestBody(RequestBody requestBody){ RefFormat refFormat = computeRefFormat(requestBody.get$ref()); String $ref = requestBody.get$ref(); if (isAnExternalRefFormat(refFormat)){ final String newRef = externalRefProcessor.processRefToExternalRequestBody($ref, refFormat); if (newRef != null) { requestBody.set$ref(newRef); } } }
RequestBody rb = new RequestBody(); Content content = new Content(); MediaType mt = new MediaType(); if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { consumes = new HashSet<>(); consumes.add("application/json"); // default to application/json LOGGER.info("Default to application/json for inline body schema"); } else { consumes = requestBody.getContent().keySet(); rb.setContent(content); requestBody.set$ref(modelName);
operation.requestBody(parentRequestBody); } else { Content content = operation.getRequestBody().getContent(); if (content == null) { content = parentRequestBody.getContent(); operation.getRequestBody().setContent(content); } else if (parentRequestBody.getContent() != null){ for (String parentMediaType: parentRequestBody.getContent().keySet()) { if (content.get(parentMediaType) == null) { content.addMediaType(parentMediaType, parentRequestBody.getContent().get(parentMediaType));
.responses(new ApiResponses() .addApiResponse("default", errorResponse)) .requestBody(new RequestBody() .description("the pet to add") .content(new Content().addMediaType("*/*", new MediaType() .schema(new Schema().$ref("Person")))));
codegenParameter.baseName = REQUEST_BODY_NAME; codegenParameter.paramName = REQUEST_BODY_NAME; codegenParameter.description = body.getDescription(); codegenParameter.required = body.getRequired() != null ? body.getRequired() : Boolean.FALSE; codegenParameter.getVendorExtensions().put(CodegenConstants.IS_BODY_PARAM_EXT_NAME, Boolean.TRUE);
public String displayDescription(final MarkupDocBuilder markupDocBuilder) { return markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, body.getDescription()); }
public RequestBody $ref(String $ref) { set$ref($ref); return this; }
public boolean getRequired() { return Optional.ofNullable(body.getRequired()).orElse(false); }
protected String getContentType(RequestBody requestBody) { if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { return null; } return new ArrayList<>(requestBody.getContent().keySet()).get(0); }