本文整理匯總了Java中io.swagger.models.properties.Property類的典型用法代碼示例。如果您正苦於以下問題:Java Property類的具體用法?Java Property怎麽用?Java Property使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Property類屬於io.swagger.models.properties包,在下文中一共展示了Property類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: apply_ReturnsOkResponseWithEntityObject_ForTupleResult
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Test
public void apply_ReturnsOkResponseWithEntityObject_ForTupleResult() {
// Arrange
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getPath()).thenReturn("/");
when(containerRequestContextMock.getUriInfo()).thenReturn(uriInfo);
TupleQueryResult result = mock(TupleQueryResult.class);
final Map<String, Property> schemaMap = ImmutableMap.of();
when(informationProductMock.getResult(ImmutableMap.of())).thenReturn(result);
when(informationProductMock.getResultType()).thenReturn(ResultType.TUPLE);
// Act
Response response = getRequestHandler.apply(containerRequestContextMock);
// Assert
assertThat(response.getStatus(), equalTo(Status.OK.getStatusCode()));
assertThat(response.getEntity(), instanceOf(TupleEntity.class));
assertThat(((TupleEntity) response.getEntity()).getResult(), equalTo(result));
assertThat(((TupleEntity) response.getEntity()).getSchemaMap(), equalTo(schemaMap));
}
示例2: mapCollection
import io.swagger.models.properties.Property; //導入依賴的package包/類
private Object mapCollection(TupleEntity entity, ArrayProperty schema,
ValueContext valueContext) {
Property itemSchema = schema.getItems();
if (itemSchema == null) {
throw new EntityMapperRuntimeException("Array schemas must have an 'items' property.");
}
if (!(itemSchema instanceof ObjectProperty)) {
throw new EntityMapperRuntimeException(
"Only array items of type 'object' are supported for now.");
}
TupleQueryResult result = entity.getResult();
ImmutableList.Builder<Map<String, Object>> collectionBuilder = new ImmutableList.Builder<>();
Map<String, Property> itemProperties = ((ObjectProperty) itemSchema).getProperties();
while (result.hasNext()) {
collectionBuilder.add(mapBindingSet(result.next(), itemProperties, valueContext));
}
return collectionBuilder.build();
}
示例3: process
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Override
public Property process(OperationGenerator operationGenerator) {
// Response完全表達應答類型
// 如果produces是text,那麽可以假設是string,否則隻能報錯
List<String> produces = operationGenerator.getOperation().getProduces();
if (produces == null) {
produces = operationGenerator.getSwagger().getProduces();
}
if (produces != null) {
if (produces.contains(MediaType.TEXT_PLAIN)) {
Type responseType = String.class;
ParamUtils.addDefinitions(operationGenerator.getSwagger(), responseType);
return ModelConverters.getInstance().readAsProperty(responseType);
}
}
throw new Error("Use ApiOperation or ApiResponses to declare response type");
}
示例4: map_BodyParameter
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Test
public void map_BodyParameter() throws IOException {
// Arrange
Property property = mock(Property.class);
List<Parameter> parameters = createBodyParameter("object");
Operation newOp = new Operation();
newOp.setParameters(parameters);
newOp.vendorExtensions(ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
DBEERPEDIA.BREWERIES.stringValue()));
newOp.response(200, new Response().schema(property));
mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.APPLICATION_JSON).path(
"/breweries", new Path().get(newOp));
// Act
requestMapper.map(httpConfigurationMock);
// Assert
verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
Resource resource = resourceCaptor.getValue();
assertThat(resource.getPath(), equalTo("/" + DBEERPEDIA.OPENAPI_HOST + "/breweries"));
}
示例5: mapEndpointWithoutBasePath
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Test
public void mapEndpointWithoutBasePath() throws IOException {
// Arrange
mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.TEXT_PLAIN).path("/breweries",
new Path().get(new Operation().vendorExtensions(
ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
DBEERPEDIA.BREWERIES.stringValue())).response(Status.OK.getStatusCode(),
new Response().schema(mock(Property.class)))));
when(informationProductResourceProviderMock.get(DBEERPEDIA.BREWERIES)).thenReturn(
informationProductMock);
// Act
requestMapper.map(httpConfigurationMock);
// Assert
verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
Resource resource = resourceCaptor.getValue();
assertThat(resource.getPath(), equalTo("/" + DBEERPEDIA.OPENAPI_HOST + "/breweries"));
}
示例6: map_ProducesPrecedence_WithValidData
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Test
public void map_ProducesPrecedence_WithValidData() throws IOException {
// Arrange
mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.TEXT_PLAIN).path("/breweries",
new Path().get(new Operation().vendorExtensions(
ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
DBEERPEDIA.BREWERIES.stringValue())).produces(MediaType.APPLICATION_JSON).response(
Status.OK.getStatusCode(), new Response().schema(mock(Property.class)))));
when(informationProductResourceProviderMock.get(DBEERPEDIA.BREWERIES)).thenReturn(
informationProductMock);
// Act
requestMapper.map(httpConfigurationMock);
// Assert
verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
ResourceMethod method = resourceCaptor.getValue().getResourceMethods().get(0);
assertThat(method.getProducedTypes(), hasSize(1));
assertThat(method.getProducedTypes().get(0), equalTo(MediaType.APPLICATION_JSON_TYPE));
}
示例7: extractProperties
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Test
public void extractProperties() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(Family.class);
assertEquals(models.size(), 3);
final Model person = models.get("Person");
final Property employer = person.getProperties().get("employer");
assertTrue(employer instanceof ArrayProperty);
final ArrayProperty employerProperty = (ArrayProperty) employer;
final Property items = employerProperty.getItems();
assertTrue(items instanceof RefProperty);
assertEquals(((RefProperty) items).getSimpleRef(), "Employer");
final Property awards = person.getProperties().get("awards");
assertTrue(awards instanceof ArrayProperty);
assertTrue(((ArrayProperty) awards).getItems() instanceof StringProperty);
}
示例8: resolveProperty
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Override
public Property resolveProperty(JavaType propType, ModelConverterContext context, Annotation[] annotations,
Iterator<ModelConverter> next) {
checkType(propType);
PropertyCreator creator = propertyCreatorMap.get(propType.getRawClass());
if (creator != null) {
return creator.createProperty();
}
Property property = super.resolveProperty(propType, context, annotations, next);
if (StringProperty.class.isInstance(property)) {
if (StringPropertyConverter.isEnum((StringProperty) property)) {
setType(propType, property.getVendorExtensions());
}
}
return property;
}
示例9: map_BodyParameterNoObject
import io.swagger.models.properties.Property; //導入依賴的package包/類
@Test
public void map_BodyParameterNoObject() throws IOException {
// Arrange
Property property = mock(Property.class);
List<Parameter> parameters = createBodyParameter("object2");
Operation newOp = new Operation();
newOp.setParameters(parameters);
newOp.vendorExtensions(ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
DBEERPEDIA.BREWERIES.stringValue()));
newOp.response(200, new Response().schema(property));
mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.APPLICATION_JSON).path(
"/breweries", new Path().get(newOp));
// Assert
thrown.expect(ConfigurationException.class);
thrown.expectMessage(String.format("No object property in body parameter"));
// Act
requestMapper.map(httpConfigurationMock);
}
示例10: injectResultContainerModel
import io.swagger.models.properties.Property; //導入依賴的package包/類
private ModelImpl injectResultContainerModel(Swagger swagger, ModelImpl innerModel, SwaggerRefPropertyFactory.PropertyContainerType containerType) {
// Only inject result container model once.
if (innerModel.getName().startsWith(resultContainerName)) {
return null;
}
// Create result container model instance based on result container definition.
Model model = swagger.getDefinitions().get(resultContainerName);
if (model == null || !(model instanceof ModelImpl)) {
return null;
}
ModelImpl resultContainerModel = (ModelImpl) model.clone();
// Set unique name of result container model per container type to avoid overwriting documentation.
resultContainerModel.setName(resultContainerName + "-" + innerModel.getName() + "-" + containerType);
// Inject innerModel into 'data' property.
Property dataProperty = SwaggerRefPropertyFactory.create(containerType, innerModel);
dataProperty.setRequired(true);
dataProperty.setDescription(createDataPropertyDescription(containerType));
resultContainerModel.addProperty(resultContainerDataProperty, dataProperty);
// Put result container model with injected innerModel into Swagger.
swagger.addDefinition(resultContainerModel.getName(), resultContainerModel);
return resultContainerModel;
}
示例11: arrayParam
import io.swagger.models.properties.Property; //導入依賴的package包/類
public static SerializableParameter arrayParam(final boolean required,
final String collectionFormat,
final Integer minItems,
final Integer maxItems,
final Boolean unique,
final Property items) {
final SerializableParameter result = mock(SerializableParameter.class);
when(result.getName()).thenReturn("Test Parameter");
when(result.getType()).thenReturn("array");
when(result.getCollectionFormat()).thenReturn(collectionFormat);
when(result.getRequired()).thenReturn(required);
when(result.getMinItems()).thenReturn(minItems);
when(result.getMaxItems()).thenReturn(maxItems);
when(result.isUniqueItems()).thenReturn(unique);
when(result.getItems()).thenReturn(items);
return result;
}
示例12: parseResponseHeaders
import io.swagger.models.properties.Property; //導入依賴的package包/類
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;
}
示例13: load
import io.swagger.models.properties.Property; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private ModelImpl load(Collection<Entry<String, PropertyDescription>> desc) {
ModelImpl res = new ModelImpl();
for (Entry<String, PropertyDescription> e : desc) {
String name = e.getKey();
PropertyDescription pd = e.getValue();
if (pd.usageOptions.contains(PropertyUsageOption.INFRASTRUCTURE)
|| pd.usageOptions.contains(PropertyUsageOption.SERVICE_USE)) {
continue;
}
Property property = makeProperty(pd);
property.description(pd.propertyDocumentation);
if (pd.exampleValue instanceof Collection) {
property.setExample((Object) null);
}
if (pd.exampleValue != null && pd.exampleValue.getClass().isArray()) {
property.setExample((Object) null);
}
res.addProperty(name, property);
}
return res;
}
示例14: paramBody
import io.swagger.models.properties.Property; //導入依賴的package包/類
/**
* Build BodyParameter for the Route parameter of type body.
*/
private BodyParameter paramBody(List<RequestRouter.Parameter> routeParams, Route route) {
BodyParameter bodyParam = new BodyParameter();
bodyParam.setRequired(false);
Model model = new ModelImpl();
if (routeParams != null) {
Map<String, Property> properties = new HashMap<>(routeParams.size());
routeParams.stream().forEach((p) -> {
StringProperty stringProperty = new StringProperty();
stringProperty.setName(p.name);
stringProperty
.setDescription(isBlank(p.description) ? route.description : p.description);
stringProperty.setDefault(p.value);
stringProperty.setRequired(p.required);
stringProperty.setType(StringProperty.TYPE);
properties.put(p.name, stringProperty);
});
model.setProperties(properties);
}
bodyParam.setSchema(model);
return bodyParam;
}
示例15: parseResponseHeaders
import io.swagger.models.properties.Property; //導入依賴的package包/類
private static Map<String, Property> parseResponseHeaders(Swagger swagger, 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(swagger, cls);
}
}
}
}
return responseHeaders;
}