use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-core by swagger-api.
the class ReaderTest method testRequestBodyExtensions.
@Test(description = "RequestBody Tests")
public void testRequestBodyExtensions() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(RequestBodyExtensionsResource.class);
assertNotNull(openAPI);
Map<String, Object> extensions = openAPI.getPaths().get("/user").getGet().getRequestBody().getExtensions();
assertNotNull(extensions);
assertEquals(extensions.size(), 2);
assertNotNull(extensions.get("x-extension"));
assertNotNull(extensions.get("x-extension2"));
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-core by swagger-api.
the class FormParamBeanTest method shouldSerializeTypeParameter.
@Test(description = "check schema of serialized BeanParam containing FormParams")
public void shouldSerializeTypeParameter() {
OpenAPI openApi = new Reader(new OpenAPI()).read(MyFormBeanParamResource.class);
RequestBody requestBody = openApi.getPaths().get("/").getGet().getRequestBody();
Assert.assertNotNull(requestBody);
MediaType mediaType = requestBody.getContent().get("application/x-www-form-urlencoded");
Assert.assertNotNull(mediaType);
Schema schema = mediaType.getSchema();
Assert.assertEquals(schema.getProperties().size(), 2);
Assert.assertEquals(schema.getProperties().get("param1"), new StringSchema());
Assert.assertEquals(schema.getProperties().get("param2"), new StringSchema());
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-core by swagger-api.
the class ReaderTest method testExampleWithFilter.
@Test(description = "Example with Ref Filter")
public void testExampleWithFilter() {
Components components = new Components();
components.addExamples("Id", new Example().description("Id Example").summary("Id Example").value("1"));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(SimpleExamplesResource.class);
OpenAPISpecFilter filterImpl = new RefExampleFilter();
SpecFilter f = new SpecFilter();
openAPI = f.filter(openAPI, filterImpl, null, null, null);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /example:\n" + " post:\n" + " description: subscribes a client to updates relevant to the requestor's account\n" + " operationId: subscribe\n" + " parameters:\n" + " - example:\n" + " $ref: '#/components/examples/Id'\n" + " requestBody:\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/SubscriptionResponse'\n" + "components:\n" + " schemas:\n" + " SubscriptionResponse:\n" + " type: object\n" + " properties:\n" + " subscriptionId:\n" + " type: string\n" + " examples:\n" + " Id:\n" + " summary: Id Example\n" + " description: Id Example\n" + " value: \"1\"\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-core by swagger-api.
the class ReaderTest method testRequestBodyWithFilter.
@Test(description = "RequestBody with filter")
public void testRequestBodyWithFilter() {
Components components = new Components();
components.addRequestBodies("User", new RequestBody());
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(SimpleRequestBodyResource.class);
OpenAPISpecFilter filterImpl = new RefRequestBodyFilter();
SpecFilter f = new SpecFilter();
openAPI = f.filter(openAPI, filterImpl, null, null, null);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with a payload complex input object\n" + " operationId: sendPayload\n" + " requestBody:\n" + " $ref: '#/components/requestBodies/User'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " deprecated: true\n" + "components:\n" + " schemas:\n" + " User:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " username:\n" + " type: string\n" + " firstName:\n" + " type: string\n" + " lastName:\n" + " type: string\n" + " email:\n" + " type: string\n" + " password:\n" + " type: string\n" + " phone:\n" + " type: string\n" + " userStatus:\n" + " type: integer\n" + " description: User Status\n" + " format: int32\n" + " xml:\n" + " name: User\n" + " requestBodies:\n" + " User: {}\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-core by swagger-api.
the class ReaderTest method testTicket3092.
@Test
public void testTicket3092() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(UploadResource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /upload:\n" + " post:\n" + " operationId: uploadWithBean\n" + " requestBody:\n" + " content:\n" + " multipart/form-data:\n" + " schema:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " picture:\n" + " $ref: '#/components/schemas/picture'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json: {}\n" + " /upload/requestbody:\n" + " post:\n" + " operationId: uploadWithBeanAndRequestBody\n" + " requestBody:\n" + " content:\n" + " multipart/form-data:\n" + " schema:\n" + " $ref: '#/components/schemas/UploadRequest'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json: {}\n" + "components:\n" + " schemas:\n" + " picture:\n" + " type: object\n" + " format: binary\n" + " UploadRequest:\n" + " title: Schema for Upload\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " picture:\n" + " type: string\n" + " format: binary";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Aggregations