io.swagger.converter.ModelConverter Java Examples
The following examples show how to use
io.swagger.converter.ModelConverter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelResolverExt.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@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; }
Example #2
Source File: ModelResolverExt.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@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 (model instanceof ModelImpl && !StringUtils.isEmpty(((ModelImpl) model).getName())) { setType(type, model.getVendorExtensions()); } return model; }
Example #3
Source File: PetIdToStringModelConverter.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
@Override public Property resolveProperty(Type type, ModelConverterContext modelConverterContext, Annotation[] annotations, Iterator<ModelConverter> iterator) { try { Type expectedType = _mapper.constructType(Class.forName("com.wordnik.sample.model.PetId")); if (type.equals(expectedType)) { return super.resolveProperty(_mapper.constructType(Class.forName("java.lang.String")), modelConverterContext, annotations, iterator); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } return super.resolveProperty(type, modelConverterContext, annotations, iterator); }
Example #4
Source File: ModelModifier.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
@Override public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { // for method parameter types we get here Type but we need JavaType JavaType javaType = toJavaType(type); if (modelSubtitutes.containsKey(javaType)) { return super.resolve(modelSubtitutes.get(javaType), context, chain); } else { return super.resolve(type, context, chain); } }
Example #5
Source File: ModelModifier.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { // for method parameter types we get here Type but we need JavaType JavaType javaType = toJavaType(type); if (modelSubtitutes.containsKey(javaType)) { return super.resolveProperty(modelSubtitutes.get(javaType), context, annotations, chain); } else if (chain.hasNext()) { return chain.next().resolveProperty(type, context, annotations, chain); } else { return super.resolveProperty(type, context, annotations, chain); } }
Example #6
Source File: SwaggerFilter.java From hawkular-metrics with Apache License 2.0 | 5 votes |
@Override public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (chain.hasNext()) { return chain.next().resolve(type, context, chain); } else { return null; } }
Example #7
Source File: SwaggerFilter.java From hawkular-metrics with Apache License 2.0 | 5 votes |
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { if (type instanceof Class<?>) { Class<?> cls = (Class<?>) type; if (paramClass.isAssignableFrom(cls)) { return propertySupplier.get(); } } if (chain.hasNext()) { return chain.next().resolveProperty(type, context, annotations, chain); } else { return null; } }
Example #8
Source File: RJsonModelConverter.java From datacollector with Apache License 2.0 | 5 votes |
@Override public Model resolve(java.lang.reflect.Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { JavaType javaType = _mapper.constructType(type); Model model = super.resolve(type, context, chain); if (javaType.isTypeOrSubTypeOf(RBean.class)) { RBEAN_INTERNAL_FIELDS.forEach(model.getProperties()::remove); } return model; }
Example #9
Source File: SwaggerModel.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Property resolveProperty(final Type type, final ModelConverterContext context, final Annotation[] annotations, final Iterator<ModelConverter> chain) { if (!BANNED_TYPE_NAMES.contains(type.getTypeName()) && chain.hasNext()) { return chain.next().resolveProperty(type, context, annotations, chain); } return null; }
Example #10
Source File: SwaggerModel.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Model resolve(final Type type, final ModelConverterContext context, final Iterator<ModelConverter> chain) { if (!BANNED_TYPE_NAMES.contains(type.getTypeName()) && chain.hasNext()) { return chain.next().resolve(type, context, chain); } return null; }
Example #11
Source File: SwaggerModelConverter.java From Web-API with MIT License | 5 votes |
@Override public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (chain.hasNext()) { Class c = null; if (type instanceof SimpleType) { c = ((SimpleType) type).getRawClass(); } else if (type instanceof Class) { c = (Class) type; } if (c != null) { // Process @JsonValue annotation on field first if we have any Optional<Field> optField = Arrays.stream(c.getFields()) .filter(f -> f.getAnnotation(JsonValue.class) != null) .findAny(); if (optField.isPresent()) { return resolve(optField.get().getGenericType(), context, chain); } // Process @JsonValue annotation on method first if we have any Optional<Method> optMethod = Arrays.stream(c.getMethods()) .filter(m -> m.getAnnotation(JsonValue.class) != null) .findAny(); if (optMethod.isPresent()) { return resolve(optMethod.get().getGenericReturnType(), context, chain); } // If we can find a cache/view object for this type, then use that for documentation, // because we can't annotate Sponge classes with @Swagger stuff Optional<Type> optClass = WebAPI.getSerializeService().getViewFor(c); if (optClass.isPresent()) { return resolve(optClass.get(), context, chain); } } return chain.next().resolve(type, context, chain); } else { return null; } }
Example #12
Source File: RxModelConverter.java From redpipe with Apache License 2.0 | 5 votes |
@Override public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { Type delegateType = type; if (discardType.contains(type.getTypeName())) { return null; // break the chain => ignore type } if (type instanceof ParameterizedType) { ParameterizedType param = (ParameterizedType) type; if (delegateToFirstTypeArg.contains(param.getRawType().getTypeName())) { delegateType = param.getActualTypeArguments()[0]; } } return chain.next().resolve(delegateType, context, chain); }
Example #13
Source File: RxModelConverter.java From redpipe with Apache License 2.0 | 5 votes |
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { Type delegateType = type; if (discardType.contains(type.getTypeName())) { return null; // break the chain => ignore type } if (type instanceof ParameterizedType) { ParameterizedType param = (ParameterizedType) type; if (delegateToFirstTypeArg.contains(param.getRawType().getTypeName())) { delegateType = param.getActualTypeArguments()[0]; } } return chain.next().resolveProperty(delegateType, context, annotations, chain); }
Example #14
Source File: ModelConverters.java From netty-rest with Apache License 2.0 | 4 votes |
public void addConverter(ModelConverter converter) { converters.add(0, converter); }
Example #15
Source File: ModelConverters.java From netty-rest with Apache License 2.0 | 4 votes |
public void removeConverter(ModelConverter converter) { converters.remove(converter); }
Example #16
Source File: RJsonModelConverter.java From datacollector with Apache License 2.0 | 4 votes |
@Override public Property resolveProperty(java.lang.reflect.Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { final JavaType jType = _mapper.constructType(type); if (jType != null) { final Class<?> cls = jType.getRawClass(); if (cls.equals(RString.class)) { return new StringProperty(); } else if (cls.equals(RChar.class)) { return new StringProperty(); } else if (cls.equals(RText.class)) { return new StringProperty(); } else if (cls.equals(RDate.class)) { return new LongProperty(); } else if (cls.equals(RDatetime.class)) { return new LongProperty(); } else if (cls.equals(RTime.class)) { return new LongProperty(); } else if (cls.equals(RLong.class)) { return new LongProperty(); } else if (cls.equals(RBoolean.class)) { return new BooleanProperty(); } else if(cls.equals(RDecimal.class)) { return new DecimalProperty(); } else if(cls.equals(RDouble.class)) { return new DoubleProperty(); } else if(cls.equals(REnum.class)) { Property property = new StringProperty(); if (jType.containedTypeCount() > 0) { _addEnumProps(jType.containedType(0).getRawClass(), property); } return property; } else if (RBean.class.isAssignableFrom(cls)) { // complex type Model innerModel = context.resolve(jType); RBEAN_INTERNAL_FIELDS.forEach(innerModel.getProperties()::remove); if (innerModel instanceof ComposedModel) { innerModel = ((ComposedModel) innerModel).getChild(); } if (innerModel instanceof ModelImpl) { ModelImpl mi = (ModelImpl) innerModel; return new RefProperty(StringUtils.isNotEmpty(mi.getReference()) ? mi.getReference() : mi.getName()); } } return chain.next().resolveProperty(type, context, annotations, chain); } else { return null; } }
Example #17
Source File: SwaggerModelConverter.java From Web-API with MIT License | 4 votes |
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { if (chain.hasNext()) { Class c = null; if (type instanceof SimpleType) { c = ((SimpleType) type).getRawClass(); } else if (type instanceof Class) { c = (Class) type; } else if (type instanceof ParameterizedType) { c = (Class) ((ParameterizedType)type).getRawType(); } if (c != null) { // Process @JsonValue annotation on field first if we have any Optional<Field> optField = Arrays.stream(c.getFields()) .filter(f -> f.getAnnotation(JsonValue.class) != null) .findAny(); if (optField.isPresent()) { return resolveProperty(optField.get().getGenericType(), context, annotations, chain); } // Process @JsonValue annotation on method first if we have any Optional<Method> optMethod = Arrays.stream(c.getMethods()) .filter(m -> m.getAnnotation(JsonValue.class) != null) .findAny(); if (optMethod.isPresent()) { return resolveProperty(optMethod.get().getGenericReturnType(), context, annotations, chain); } // If we can find a cache/view object for this type, then use that for documentation, // because we can't annotate Sponge classes with @Swagger stuff Optional<Type> optClass = WebAPI.getSerializeService().getViewFor(c); if (optClass.isPresent()) { return resolveProperty(optClass.get(), context, annotations, chain); } } return chain.next().resolveProperty(type, context, annotations, chain); } else { return null; } }