private static MType doResolveType(MetaApi api, MType type) { if(type instanceof MUnresolvedTypeRef) { return resolveType(api, ((MUnresolvedTypeRef) type).getRefTypeName()); } if(type instanceof MCollectionType) { return new MCollectionType(doResolveType(api, type.asCollectionType().getElementType())); } if(type instanceof MDictionaryType) { return new MDictionaryType(type.asDictionaryType().getKeyType(), doResolveType(api, type.asDictionaryType().getValueType())); } throw new IllegalStateException("Unsupported type '" + type + "'"); }
protected MType getDictionaryType(MTypeContext context, Class<?> declaringType, Class<?> type, Type genericType, MTypeFactory root) { if(null == genericType) { return MDictionaryType.INSTANCE; } Type[] types = getDictionaryTypes(type, genericType); Type keyType = types[0]; Type valType = types[1]; MType keyMType = getMType(context, declaringType, Types.getActualType(keyType), keyType, root); MType valMType = getMType(context, declaringType, Types.getActualType(valType), valType, root); return new MDictionaryType(keyMType, valMType); }
protected static Validator ofMap(MetaApi api, String name, boolean required, MDictionaryType t) { MType valueType = t.getValueType(); Validator valueValidator = of(api, name + ".values", valueType); return new MapValidator(name, required, valueValidator); } }
return new MDictionaryType(MSimpleTypes.STRING, MObjectType.TYPE); throw new IllegalStateException("Invalid map type '" + typeName + "'"); return new MDictionaryType(MSimpleTypes.STRING, resolveType(api, valueType));
protected void writeDictionaryType(WriteContext context, ApiMetadata m, JsonWriter w, MDictionaryType type) { w.property(TYPE, OBJECT); w.property(ADDITIONAL_PROPERTIES, () -> { w.startObject(); writeType(context, m, w, type.getValueType()); w.endObject(); }); }
protected MType readObjectType(String name, JsonObject o) { JsonObject additionalProperties = o.getObject(ADDITIONAL_PROPERTIES); if(null == additionalProperties) { //check is nested model Object property = o.get(PROPERTIES); if(null != property && property instanceof Map) { if(null == name) { name = "Embedded"; } MApiModelBuilder model = readModel(name, o.asMap()); return model.toMComplexType().build(); }else { return MObjectType.TYPE; } }else{ if(additionalProperties.asMap().isEmpty()) { return MObjectType.TYPE; }else { MType valueType = readType(additionalProperties); return new MDictionaryType(MSimpleTypes.STRING, valueType); } } }
private static boolean hasUnresolvedType(MType type) { if(type instanceof MUnresolvedTypeRef) { return true; } if(type.isCollectionType()) { return hasUnresolvedType(type.asCollectionType().getElementType()); } if(type.isDictionaryType()) { return hasUnresolvedType(type.asDictionaryType().getValueType()); } return false; }
public static String toTypeName(MType type) { if(type.isSimpleType()) { SwaggerType st = swaggerWriter.convertSimpleType(type.asSimpleType()); if(null == st) { throw new IllegalStateException("Unsupported type '" + type + "'"); } return st.name().toLowerCase(); } if(type.isCollectionType()) { MType elementType = type.asCollectionType().getElementType(); return "array<" + toTypeName(elementType) + ">"; } if(type.isComplexType()) { return type.asComplexType().getName(); } if(type.isTypeRef()) { return type.asTypeRef().getRefTypeName(); } if(type.isDictionaryType()) { return "map<string," + toTypeName(type.asDictionaryType().getValueType()) + ">"; } if(type.isObjectType()) { return "object"; } if(type.isVoidType()) { return ""; } throw new IllegalStateException("Unsupported type '" + type + "'"); }