@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); }
@Test(description = "it should serialize a BodyParameter") public void serializeBodyParameter() { final Schema model = new Schema() .title("Cat") .addProperties("name", new StringSchema()); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String json = "{\"content\":{\"*/*\":{\"schema\":{\"title\":\"Cat\",\"properties\":{\"name\":{\"type\":\"string\"}}}}}}"; SerializationMatchers.assertEqualsToJson(p, json); }
@Test(description = "it should serialize an array BodyParameter") public void serializeArrayBodyParameter() { final Schema model = new ArraySchema().items(new Schema().$ref("#/definitions/Cat")); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String json = "{\"content\":{\"*/*\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Cat\"}}}}}"; SerializationMatchers.assertEqualsToJson(p, json); }
@Test(description = "it should serialize a BodyParameter to yaml") public void serializeBodyParameterToYaml() { final Schema model = new Schema() .title("Cat") .addProperties("name", new StringSchema()); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String yaml = "---\n" + "content:\n" + " '*/*':\n" + " schema:\n" + " title: Cat\n" + " properties:\n" + " name:\n" + " type: string"; SerializationMatchers.assertEqualsToYaml(p, yaml); }
.requestBody(new RequestBody() .description("the pet to add") .content(new Content().addMediaType("*/*", new MediaType() .schema(new Schema().$ref("Person")))));
private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List<String> consumes) { RequestBody body = new RequestBody(); BodyParameter bp = (BodyParameter) param; List<String> mediaTypes = new ArrayList<>(globalConsumes); if (consumes != null && consumes.size() > 0) { mediaTypes.clear(); mediaTypes.addAll(consumes); } if (mediaTypes.size() == 0) { mediaTypes.add("*/*"); } if (StringUtils.isNotBlank(param.getDescription())) { body.description(param.getDescription()); } body.required(param.getRequired()); Content content = new Content(); for (String type : mediaTypes) { content.addMediaType(type, new MediaType().schema( convert(bp.getSchema()))); if (StringUtils.isNotBlank(bp.getDescription())) { body.setDescription(bp.getDescription()); } } convertExamples(((BodyParameter) param).getExamples(), content); body.content(content); return body; }
private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List<String> consumes) { RequestBody body = new RequestBody(); BodyParameter bp = (BodyParameter) param; List<String> mediaTypes = new ArrayList<>(globalConsumes); if (consumes != null && consumes.size() > 0) { mediaTypes.clear(); mediaTypes.addAll(consumes); } if (mediaTypes.size() == 0) { mediaTypes.add("*/*"); } if (StringUtils.isNotBlank(param.getDescription())) { body.description(param.getDescription()); } body.required(param.getRequired()); Content content = new Content(); for (String type : mediaTypes) { content.addMediaType(type, new MediaType().schema( convert(bp.getSchema()))); if (StringUtils.isNotBlank(bp.getDescription())) { body.setDescription(bp.getDescription()); } } convertExamples(((BodyParameter) param).getExamples(), content); body.content(content); return body; }
private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List<String> consumes) { RequestBody body = new RequestBody(); BodyParameter bp = (BodyParameter) param; List<String> mediaTypes = new ArrayList<>(globalConsumes); if (consumes != null && consumes.size() > 0) { mediaTypes.clear(); mediaTypes.addAll(consumes); } if (mediaTypes.size() == 0) { mediaTypes.add("*/*"); } if (StringUtils.isNotBlank(param.getDescription())) { body.description(param.getDescription()); } body.required(param.getRequired()); Content content = new Content(); for (String type : mediaTypes) { content.addMediaType(type, new MediaType().schema( convert(bp.getSchema()))); if (StringUtils.isNotBlank(bp.getDescription())) { body.setDescription(bp.getDescription()); } } convertExamples(((BodyParameter) param).getExamples(), content); body.content(content); return body; }
content.addMediaType(type, new MediaType().schema(formSchema)); body.content(content); return body;
content.addMediaType(type, new MediaType().schema(formSchema)); body.content(content); return body;
content.addMediaType(type, new MediaType().schema(formSchema)); body.content(content); return body;
/** * 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; }