use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class JodaDateTimeConverterTest method testJodaDateTime.
@Test
public void testJodaDateTime() {
final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaDateTime.class);
// don't create a Joda DateTime object
assertEquals(models.size(), 1);
final Model model = models.get("ModelWithJodaDateTime");
final Property dateTimeProperty = model.getProperties().get("createdAt");
assertTrue(dateTimeProperty instanceof DateTimeProperty);
assertEquals((int) dateTimeProperty.getPosition(), 1);
assertTrue(dateTimeProperty.getRequired());
assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
final Property nameProperty = model.getProperties().get("name");
assertTrue(nameProperty instanceof StringProperty);
assertEquals((int) nameProperty.getPosition(), 2);
assertEquals(nameProperty.getDescription(), "name of the model");
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class JodaLocalDateConverterTest method testJodaLocalDate.
@Test
public void testJodaLocalDate() {
final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaLocalDate.class);
assertEquals(models.size(), 1);
final Model model = models.get("ModelWithJodaLocalDate");
final Property dateTimeProperty = model.getProperties().get("createdAt");
assertTrue(dateTimeProperty instanceof DateProperty);
assertEquals((int) dateTimeProperty.getPosition(), 1);
assertTrue(dateTimeProperty.getRequired());
assertEquals(dateTimeProperty.getDescription(), "creation localDate");
final Property nameProperty = model.getProperties().get("name");
assertTrue(nameProperty instanceof StringProperty);
assertEquals((int) nameProperty.getPosition(), 2);
assertEquals(nameProperty.getDescription(), "name of the model");
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class SpecFilter method locateReferencedDefinitions.
private void locateReferencedDefinitions(Map<String, Property> props, Set<String> nestedReferencedDefinitions, Swagger swagger) {
if (props == null)
return;
for (String keyProp : props.keySet()) {
Property p = props.get(keyProp);
String ref = getPropertyRef(p);
if (ref != null) {
locateReferencedDefinitions(ref, nestedReferencedDefinitions, swagger);
}
}
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ServletReaderExtension method parseResponseHeaders.
private static Map<String, Property> parseResponseHeaders(ReaderContext context, ResponseHeader[] headers) {
Map<String, Property> responseHeaders = null;
for (ResponseHeader header : headers) {
final String name = header.name();
if (StringUtils.isNotEmpty(name)) {
if (responseHeaders == null) {
responseHeaders = new HashMap<String, Property>();
}
final Class<?> cls = header.response();
if (!ReflectionUtils.isVoid(cls)) {
final Property property = ModelConverters.getInstance().readAsProperty(cls);
if (property != null) {
final Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(), property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET);
responseProperty.setDescription(header.description());
responseHeaders.put(name, responseProperty);
appendModels(context.getSwagger(), cls);
}
}
}
}
return responseHeaders;
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ServletReaderExtension method applyResponses.
@Override
public void applyResponses(ReaderContext context, Operation operation, Method method) {
final Map<Integer, Response> result = new HashMap<Integer, Response>();
final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class);
if (apiOperation != null && StringUtils.isNotBlank(apiOperation.responseReference())) {
final Response response = new Response().description(SUCCESSFUL_OPERATION);
response.schema(new RefProperty(apiOperation.responseReference()));
result.put(apiOperation.code(), response);
}
final Type responseType = getResponseType(method);
if (isValidResponse(responseType)) {
final Property property = ModelConverters.getInstance().readAsProperty(responseType);
if (property != null) {
final Property responseProperty = ContainerWrapper.wrapContainer(getResponseContainer(apiOperation), property);
final int responseCode = apiOperation == null ? 200 : apiOperation.code();
final Map<String, Property> defaultResponseHeaders = apiOperation == null ? Collections.<String, Property>emptyMap() : parseResponseHeaders(context, apiOperation.responseHeaders());
final Response response = new Response().description(SUCCESSFUL_OPERATION).schema(responseProperty).headers(defaultResponseHeaders);
result.put(responseCode, response);
appendModels(context.getSwagger(), responseType);
}
}
final ApiResponses responseAnnotation = ReflectionUtils.getAnnotation(method, ApiResponses.class);
if (responseAnnotation != null) {
for (ApiResponse apiResponse : responseAnnotation.value()) {
final Map<String, Property> responseHeaders = parseResponseHeaders(context, apiResponse.responseHeaders());
final Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
if (StringUtils.isNotEmpty(apiResponse.reference())) {
response.schema(new RefProperty(apiResponse.reference()));
} else if (!ReflectionUtils.isVoid(apiResponse.response())) {
final Type type = apiResponse.response();
final Property property = ModelConverters.getInstance().readAsProperty(type);
if (property != null) {
response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
appendModels(context.getSwagger(), type);
}
}
result.put(apiResponse.code(), response);
}
}
for (Map.Entry<Integer, Response> responseEntry : result.entrySet()) {
if (responseEntry.getKey() == 0) {
operation.defaultResponse(responseEntry.getValue());
} else {
operation.response(responseEntry.getKey(), responseEntry.getValue());
}
}
}
Aggregations