use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class ReaderTest method test2497.
@Test(description = "test resource with array in response content")
public void test2497() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ResponseContentWithArrayResource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 1);
PathItem pathItem = paths.get("/user");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
ArraySchema schema = (ArraySchema) operation.getResponses().get("200").getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getItems().get$ref(), "#/components/schemas/User");
assertEquals(openAPI.getComponents().getSchemas().get("User").getRequired().get(0), "issue3438");
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class ReaderTest method testParameterWithFilter.
@Test(description = "Responses with filter")
public void testParameterWithFilter() {
Components components = new Components();
components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(SimpleParameterResource.class);
OpenAPISpecFilter filterImpl = new RefParameterFilter();
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" + " parameters:\n" + " - $ref: '#/components/parameters/id'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " deprecated: true\n" + "components:\n" + " parameters: \n" + " id:\n" + " in: query\n" + " description: Id Description\n" + " required: true\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " example: 1\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class ReaderTest method testTicket3624.
@Test(description = "Optional handling")
public void testTicket3624() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Service.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /example/model:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve models for display to the user'\n" + " operationId: getModels\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Response'\n" + " /example/model/by/ids:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve models by their ids'\n" + " operationId: getModelsById\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ByIdResponse'\n" + " /example/containerized/model:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve review insights for a specific product'\n" + " operationId: getContainerizedModels\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ContainerizedResponse'\n" + "components:\n" + " schemas:\n" + " Model:\n" + " type: object\n" + " properties:\n" + " text:\n" + " type: string\n" + " title:\n" + " type: string\n" + " active:\n" + " type: boolean\n" + " schemaParent:\n" + " $ref: '#/components/schemas/Model'\n" + " optionalString:\n" + " type: string\n" + " parent:\n" + " $ref: '#/components/schemas/Model'\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " Response:\n" + " type: object\n" + " properties:\n" + " count:\n" + " type: integer\n" + " format: int32\n" + " models:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/Model'\n" + " ByIdResponse:\n" + " type: object\n" + " properties:\n" + " modelsById:\n" + " type: object\n" + " additionalProperties:\n" + " $ref: '#/components/schemas/Model'\n" + " ContainerizedResponse:\n" + " type: object\n" + " properties:\n" + " totalCount:\n" + " type: integer\n" + " format: int32\n" + " containerizedModels:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/ModelContainer'\n" + " ModelContainer:\n" + " type: object\n" + " properties:\n" + " text:\n" + " type: string\n" + " model:\n" + " $ref: '#/components/schemas/Model'\n" + " id:\n" + " type: integer\n" + " format: int32";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.media.Content 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.annotations.media.Content 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