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); } }
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(); }); }
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; }
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 + "'"); }
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 + "'"); }