Java Code Examples for io.swagger.models.ModelImpl#getReference()

The following examples show how to use io.swagger.models.ModelImpl#getReference() . 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: ModelImplConverter.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public JavaType doConvert(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 convertRef(swagger, modelImpl.getReference());
  }

  if (modelImpl.getAdditionalProperties() != null) {
    return MapPropertyConverter.findJavaType(swagger, modelImpl.getAdditionalProperties());
  }

  return OBJECT_JAVA_TYPE;
}
 
Example 2
Source File: RJsonModelConverter.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@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;
  }
}