use of io.swagger.v3.oas.models.media.XML in project swagger-core by swagger-api.
the class ReaderTest method testAnotherResourceWithSubresources.
@Test(description = "test another resource with subresources")
public void testAnotherResourceWithSubresources() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(TestResource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 3);
PathItem pathItem = paths.get("/test/status");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
Schema schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/test/more/otherStatus");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
assertFalse(operation.getResponses().getDefault().getContent().keySet().contains("application/xml"));
schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/test/evenmore/otherStatus");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
assertFalse(operation.getResponses().getDefault().getContent().keySet().contains("application/xml"));
schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
assertEquals(operation.getRequestBody().getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/Pet");
}
use of io.swagger.v3.oas.models.media.XML 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.media.XML in project swagger-core by swagger-api.
the class SnakeCaseConverterTest method testConvert.
@Test(description = "it should change naming style")
public void testConvert() {
// add the custom converter
final SnakeCaseConverter snakeCaseConverter = new SnakeCaseConverter();
final ModelConverters converters = new ModelConverters();
converters.addConverter(snakeCaseConverter);
final Map<String, Schema> models = converters.readAll(SnakeCaseModel.class);
final String json = "{" + " \"bar\":{" + " \"type\":\"object\"," + " \"properties\":{" + " \"foo\":{" + " \"type\":\"string\"" + " }" + " }" + " }," + " \"snake_case_model\":{" + " \"type\":\"object\"," + " \"properties\":{" + " \"bar\":{" + " \"$ref\":\"#/components/schemas/bar\"" + " }," + " \"title\":{" + " \"type\":\"string\"" + " }" + " }," + " \"xml\":{" + " \"name\":\"snakeCaseModel\"" + " }" + " }" + "}";
// TODO test xml if/when added to annotations and resolver
Json.prettyPrint(models);
SerializationMatchers.assertEqualsToJson(models, json);
}
use of io.swagger.v3.oas.models.media.XML in project swagger-core by swagger-api.
the class XmlModelTest method itShouldNotCreateXmlObject.
@Test(description = "it should not create an xml object")
public void itShouldNotCreateXmlObject() {
final Map<String, Schema> schemas = ModelConverters.getInstance().readAll(Address.class);
final Schema model = schemas.get("Address");
assertNotNull(model);
assertTrue(model instanceof Schema);
final Schema property = (Schema) model.getProperties().get("streetNumber");
final XML xml = property.getXml();
assertNull(xml);
}
use of io.swagger.v3.oas.models.media.XML in project swagger-core by swagger-api.
the class XmlModelTest method processModelWithJAXBAnnotations.
@Test(description = "it should process a model with JAXB annotations")
public void processModelWithJAXBAnnotations() {
final Map<String, Schema> schemas = ModelConverters.getInstance().readAll(ModelWithJAXBAnnotations.class);
assertEquals(schemas.size(), 1);
final Schema model = schemas.get("ModelWithJAXBAnnotations");
assertNotNull(model);
assertTrue(model instanceof Schema);
final XML rootXml = model.getXml();
assertNotNull(rootXml);
assertEquals(rootXml.getName(), "rootName");
Map<String, Schema> props = model.getProperties();
for (Map.Entry<String, Schema> entry : props.entrySet()) {
final String name = entry.getKey();
final Schema property = entry.getValue();
if ("id".equals(name)) {
final XML xml = property.getXml();
assertNotNull(xml);
assertNull(xml.getName());
assertTrue(xml.getAttribute());
assertNull(xml.getWrapped());
} else if ("name".equals(name)) {
final XML xml = property.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "renamed");
assertNull(xml.getAttribute());
assertNull(xml.getWrapped());
} else if (Arrays.asList("list", "forcedElement").contains(name)) {
assertNull(property.getXml());
} else if ("wrappedList".equals(name)) {
final XML xml = property.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "wrappedListItems");
assertNull(xml.getAttribute());
assertTrue(xml.getWrapped());
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
Aggregations