本文整理汇总了Java中io.swagger.models.ModelImpl类的典型用法代码示例。如果您正苦于以下问题:Java ModelImpl类的具体用法?Java ModelImpl怎么用?Java ModelImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelImpl类属于io.swagger.models包,在下文中一共展示了ModelImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initConverters
import io.swagger.models.ModelImpl; //导入依赖的package包/类
private static void initConverters() {
// inner converters
for (Class<? extends Property> propertyCls : PROPERTY_MAP.keySet()) {
addInnerConverter(propertyCls);
}
converterMap.put(RefProperty.class, new RefPropertyConverter());
converterMap.put(ArrayProperty.class, new ArrayPropertyConverter());
converterMap.put(MapProperty.class, new MapPropertyConverter());
converterMap.put(StringProperty.class, new StringPropertyConverter());
converterMap.put(ObjectProperty.class, new ObjectPropertyConverter());
converterMap.put(ModelImpl.class, new ModelImplConverter());
converterMap.put(RefModel.class, new RefModelConverter());
converterMap.put(ArrayModel.class, new ArrayModelConverter());
converterMap.put(BodyParameter.class, new BodyParameterConverter());
AbstractSerializableParameterConverter converter = new AbstractSerializableParameterConverter();
converterMap.put(QueryParameter.class, converter);
converterMap.put(PathParameter.class, converter);
converterMap.put(HeaderParameter.class, converter);
converterMap.put(FormParameter.class, converter);
converterMap.put(CookieParameter.class, converter);
}
示例2: toRefModel
import io.swagger.models.ModelImpl; //导入依赖的package包/类
private RefModel toRefModel(String modelType) {
if (RefProperty.class.isInstance(property)) {
return (RefModel) PropertyBuilder.toModel(property);
}
ModelImpl modelImpl = new ModelImpl();
modelImpl.setType("object");
modelImpl.setName(name);
modelImpl.addProperty(name, property);
operationGenerator.getSwagger().addDefinition(modelType, modelImpl);
RefModel refModel = new RefModel();
refModel.setReference("#/definitions/" + modelType);
return refModel;
}
示例3: load
import io.swagger.models.ModelImpl; //导入依赖的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;
}
示例4: paramBody
import io.swagger.models.ModelImpl; //导入依赖的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;
}
示例5: mapGraphValue_ReturnsResults_WhenRefCanBeResolved
import io.swagger.models.ModelImpl; //导入依赖的package包/类
@Test
public void mapGraphValue_ReturnsResults_WhenRefCanBeResolved() {
// Arrange
property.set$ref(DUMMY_REF);
Model refModel = new ModelImpl();
refModel.setProperties(ImmutableMap.of(KEY_1, PROPERTY_1, KEY_2, PROPERTY_2));
when(entityBuilderContext.getLdPathExecutor()).thenReturn(ldPathExecutor);
when(entityBuilderContext.getSwaggerDefinitions()).thenReturn(
ImmutableMap.of(property.getSimpleRef(), refModel));
when(ldPathExecutor.ldPathQuery(context, LD_PATH_QUERY)).thenReturn(ImmutableList.of(VALUE_2));
// Act
Map<String, Object> result =
(Map<String, Object>) schemaMapper.mapGraphValue(property, entityBuilderContext,
ValueContext.builder().value(context).build(), schemaMapperAdapter);
// Assert
assertThat(result.keySet(), hasSize(2));
assertEquals(((Optional) result.get(KEY_1)).orNull(), VALUE_1.stringValue());
assertEquals(((Optional) result.get(KEY_2)).orNull(), VALUE_2.intValue());
}
示例6: scanBeanParamResource
import io.swagger.models.ModelImpl; //导入依赖的package包/类
@Test
public void scanBeanParamResource() {
final Swagger swagger = getSwagger(ResourceWithBeanParams.class);
final List<Parameter> params = getParameters(swagger, "/bean/{id}");
final HeaderParameter headerParam1 = (HeaderParameter) params.get(0);
assertEquals(1, headerParam1.getDefaultValue());
assertEquals("test order annotation 1", headerParam1.getName());
final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
assertEquals(2, headerParam2.getDefaultValue());
assertEquals("test order annotation 2", headerParam2.getName());
final QueryParameter priority1 = (QueryParameter) params.get(2);
assertNull(priority1.getDefaultValue());
assertEquals("test priority 1", priority1.getName());
final QueryParameter priority2 = (QueryParameter) params.get(3);
assertEquals(4, priority2.getDefaultValue());
assertEquals("test priority 2", priority2.getName());
final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
assertEquals("bodyParam", bodyParam1.getDefaultValue());
}
示例7: createFields
import io.swagger.models.ModelImpl; //导入依赖的package包/类
/**
* Returns list of {@link com.google.protobuf.Field.Builder} created using the properties of a
* {@link ModelImpl} object.
*/
private ImmutableList.Builder<Field> createFields(
Service.Builder serviceBuilder, ModelImpl modelImpl) {
ImmutableList.Builder<Field> fieldsBuilder = ImmutableList.builder();
int count = 1;
if (modelImpl.getProperties() != null) {
for (String propertyName : modelImpl.getProperties().keySet()) {
Property prop = modelImpl.getProperties().get(propertyName);
TypeInfo typeInfo =
ensureNamed(
serviceBuilder,
getTypeInfo(serviceBuilder, prop),
NameConverter.propertyNameToMessageName(propertyName));
fieldsBuilder.add(createField(propertyName, count++, typeInfo).build());
}
}
return fieldsBuilder;
}
示例8: registerErrorModel
import io.swagger.models.ModelImpl; //导入依赖的package包/类
/**
* Manually register the Pippo Error class as Swagger model.
*
* @param swagger
* @return a ref for the Error model
*/
protected RefProperty registerErrorModel(Swagger swagger) {
String ref = Error.class.getSimpleName();
if (swagger.getDefinitions() != null && swagger.getDefinitions().containsKey(ref)) {
// model already registered
return new RefProperty(ref);
}
ModelImpl model = new ModelImpl();
swagger.addDefinition(ref, model);
model.setDescription("an error message");
model.addProperty("statusCode", new IntegerProperty().readOnly().description("http status code"));
model.addProperty("statusMessage", new StringProperty().readOnly().description("description of the http status code"));
model.addProperty("requestMethod", new StringProperty().readOnly().description("http request method"));
model.addProperty("requestUri", new StringProperty().readOnly().description("http request path"));
model.addProperty("message", new StringProperty().readOnly().description("application message"));
if (settings.isDev()) {
// in DEV mode the stacktrace is returned in the error message
model.addProperty("stacktrace", new StringProperty().readOnly().description("application stacktrace"));
}
return new RefProperty(ref);
}
示例9: collectRefProperty
import io.swagger.models.ModelImpl; //导入依赖的package包/类
protected DataProvider collectRefProperty(Swagger swagger, RefProperty schema, boolean clean) {
Model model = swagger.getDefinitions() != null ? swagger.getDefinitions().get(schema.getSimpleRef()) : null;
if (model == null) throw new IllegalArgumentException("CAN'T find model for " + schema.getSimpleRef());
if (model instanceof ArrayModel) {
DataProvider itemProvider = collect(swagger, ((ArrayModel) model).getItems(), clean);
return new ListDataProvider(itemProvider, schema.getSimpleRef());
} else if (model instanceof ModelImpl) {
Map<String, DataProvider> fields =
(model.getProperties() != null ? model.getProperties() : Collections.<String, Property>emptyMap()).entrySet().stream()
.map(e -> entry(e.getKey(), collect(swagger, e.getValue(), clean)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return new ObjectDataProvider(fields, schema.getSimpleRef());
}
throw new IllegalArgumentException("Unsupported model type: " + model.getClass());
}
示例10: getResponseSchema
import io.swagger.models.ModelImpl; //导入依赖的package包/类
private static Property getResponseSchema(String responseModelName, boolean inlineResponseSchema,
Swagger swagger, Map<String, Integer> modelRefCount) {
Property schema = new RefProperty(responseModelName);
if (inlineResponseSchema && !modelRefCount.containsKey(responseModelName)) {
io.swagger.models.Model model = swagger.getDefinitions().get(responseModelName);
//If empty model was generated for response type
if (model instanceof ModelImpl) {
Map<String, Property> modelProperties = ((ModelImpl) model).getProperties();
if (modelProperties == null || modelProperties.isEmpty()) {
String type = ((ModelImpl) model).getType();
if (type != null) {
Property property = PropertyBuilder.build(type, ((ModelImpl) model).getFormat(), null);
if (property != null) {
schema = property;
swagger.getDefinitions().remove(responseModelName);
}
}
}
}
}
return schema;
}
示例11: getDefinitions
import io.swagger.models.ModelImpl; //导入依赖的package包/类
private static Map<String, io.swagger.models.Model> getDefinitions(RestApi restApi)
throws IOException, JsonParseException, JsonMappingException {
Map<String, io.swagger.models.Model> result = new HashMap<String, io.swagger.models.Model>();
for (Models models = restApi.getModels(); models != null; models = safeGetNext(models)) {
for (Model modelItem : models.getItem()) {
String content = modelItem.getSchema();
io.swagger.models.Model model =
Json.mapper().readValue(content, io.swagger.models.Model.class);
if (model instanceof ModelImpl) {
((ModelImpl) model).setName(modelItem.getName());
}
model.setDescription(modelItem.getDescription());
result.put(modelItem.getName(), model);
}
}
return result;
}
示例12: processModelRefs
import io.swagger.models.ModelImpl; //导入依赖的package包/类
private static void processModelRefs(io.swagger.models.Model model, Map<String, Integer> modelRefCount) {
if (model instanceof RefModel) {
String ref = ((RefModel) model).getSimpleRef();
Integer count = modelRefCount.get(ref);
modelRefCount.put(ref, count != null ? (count + 1) : 1);
} else if (model instanceof ModelImpl) {
processPropertyModelRefs(((ModelImpl) model).getProperties(), modelRefCount);
processPropertyModelRefs(((ModelImpl) model).getAdditionalProperties(), modelRefCount);
} else if (model instanceof ArrayModel) {
processPropertyModelRefs(((ArrayModel) model).getProperties(), modelRefCount);
processPropertyModelRefs(((ArrayModel) model).getItems(), modelRefCount);
} else if (model instanceof ComposedModel) {
processPropertyModelRefs(((ComposedModel) model).getProperties(), modelRefCount);
processModelRefs(((ComposedModel) model).getChild(), modelRefCount);
processModelRefs(((ComposedModel) model).getParent(), modelRefCount);
processModelRefs(((ComposedModel) model).getAllOf(), modelRefCount);
processModelRefs(((ComposedModel) model).getInterfaces(), modelRefCount);
}
}
示例13: findByRef
import io.swagger.models.ModelImpl; //导入依赖的package包/类
public static JavaType findByRef(ClassLoader classLoader, String packageName, Swagger swagger, String refName) {
Model ref = swagger.getDefinitions().get(refName);
if (ModelImpl.class.isInstance(ref) && ((ModelImpl) ref).getName() == null) {
((ModelImpl) ref).setName(refName);
}
return findJavaType(classLoader, packageName, swagger, ref);
}
示例14: doConvert
import io.swagger.models.ModelImpl; //导入依赖的package包/类
@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object model) {
ModelImpl modelImpl = (ModelImpl) model;
JavaType javaType = ConverterMgr.findJavaType(modelImpl.getType(), modelImpl.getFormat());
if (javaType != null) {
return javaType;
}
if (modelImpl.getReference() != null) {
return ConverterMgr.findByRef(classLoader, packageName, swagger, modelImpl.getReference());
}
if (modelImpl.getAdditionalProperties() != null) {
return MapPropertyConverter.findJavaType(classLoader,
packageName,
swagger,
modelImpl.getAdditionalProperties());
}
if (ObjectProperty.TYPE.equals(modelImpl.getType())
&& modelImpl.getProperties() == null
&& modelImpl.getName() == null) {
return TypeFactory.defaultInstance().constructType(Object.class);
}
// 根据name、property动态生成class
if (packageName == null) {
throw new Error("packageName should not be null");
}
String clsName = packageName + "." + modelImpl.getName();
Class<?> cls =
ClassUtils.getOrCreateClass(classLoader, packageName, swagger, modelImpl.getProperties(), clsName);
return TypeFactory.defaultInstance().constructType(cls);
}
示例15: resolve
import io.swagger.models.ModelImpl; //导入依赖的package包/类
@Override
public Model resolve(JavaType type, ModelConverterContext context, Iterator<ModelConverter> next) {
// property is not a model
if (propertyCreatorMap.containsKey(type.getRawClass())) {
return null;
}
Model model = super.resolve(type, context, next);
if (model == null) {
return null;
}
checkType(type);
// 只有声明model的地方才需要标注类型
if (ModelImpl.class.isInstance(model) && !StringUtils.isEmpty(((ModelImpl) model).getName())) {
setType(type, model.getVendorExtensions());
}
return model;
}