/** * Returns <code>true</code> if this type is a complex type of reference to a complex type. */ public boolean isComplexTypeOrRef() { return isComplexType() || (isTypeRef() && asTypeRef().getRefTypeKind() == MTypeKind.COMPLEX); }
if(type.isComplexType()) { model = MetaUtils.toMetaModel(type.asComplexType()); return new ModelValidator(name, required, api, model, partial, true);
Class<?> toJavaType(MType type) { if(type.isSimpleType()) { return type.asSimpleType().getJavaType(); } if(type.isCollectionType()) { return Array.newInstance(toJavaType(type.asCollectionType().getElementType()), 0).getClass(); } if(type.isComplexType() || type.isDictionaryType() || type.isTypeRef()) { return Map.class; } if(type.isObjectType()) { return Object.class; } throw new IllegalStateException("Unsupported data type '" + type + "'"); }
if (mtype.isComplexType()) { CACHED_COMPLEX_TYPES.put(type, mtype.asComplexType()); onTypeResolved(mtype); if(alwaysReturnComplexTypeRef && mtype.isComplexType()) { return mtype.asComplexType().createTypeRef();
protected boolean isBodyType(MType type) { if(type.isComplexType()) { return true; } if(type.isTypeRef()) { return true; } if(type.isDictionaryType()) { return true; } if(type.isCollectionType()) { MType elementType = type.asCollectionType().getElementType(); return isBodyType(elementType); } return false; }
private void onTypeResolved(MType mtype) { if (mtype.isComplexType()) { MComplexType ct = mtype.asComplexType(); if (!complexTypes.containsKey(ct.getJavaType())) { listener.onComplexTypeResolved(ct.getJavaType(), mtype.asComplexType()); complexTypes.put(ct.getJavaType(), ct); } for (MProperty p : ct.getProperties()) { onTypeResolved(p.getType()); } } else if (mtype.isCollectionType()) { MType elementType = mtype.asCollectionType().getElementType(); onTypeResolved(elementType); } } }
@Override public MApiModelBuilder tryAddModel(ApiMetadataContext context, ApiMetadataBuilder md, MComplexType ct) { String name = modelName(context, ct); MApiModelBuilder model = md.tryGetModel(name); if(null != model) { if(null != ct.getJavaType() && !model.getJavaTypes().contains(ct.getJavaType())) { model.addJavaType(ct.getJavaType()); } return null; } model = new MApiModelBuilder(ct, name); model.getProperties().values().forEach(p -> { if(p.getType().isComplexType()) { MComplexType complexType = (MComplexType)p.getType(); if(null == md.tryGetModel(complexType.getName())) { tryAddModel(context, md, ct); } } }); md.addModel(model); return model; }
protected void createResponses(ApiMetadataContext context, ApiMetadataBuilder m) { ApiConfig c = context.getConfig(); c.getCommonResponses().forEach((name, r) -> { MType type = r.getType(); if(type.isComplexType()) { MComplexType ct = type.asComplexType(); if(!m.containsModel(ct.getName())) { tryAddModel(context, m, ct); } type = ct.createTypeRef(); } MApiResponseBuilder rb = new MApiResponseBuilder(r); rb.setType(type); m.putResponse(name, rb); }); }
protected boolean setDefaultLocation(RouteBuilder route, MApiParameterBuilder p) { if(null == p.getLocation()) { if (route.getPathTemplate().getTemplateVariables().contains(p.getName())) { p.setLocation(MApiParameter.Location.PATH); return true; } if(p.getType().isComplexType() || p.getType().isTypeRef() || p.getType().isDictionaryType()) { p.setLocation(MApiParameter.Location.BODY); return true; } p.setLocation(MApiParameter.Location.QUERY); return true; } 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 + "'"); }
public MetaModel read(Resource file) { String content = file.getContent().trim(); if (content.length() == 0) { return null; } String name = Strings.upperFirst(Paths.getFileNameWithoutExtension(file.getFilename())); JsonObject o = JSON.parse(file.getContent()).asJsonObject(); if(o.asMap().isEmpty()) { return null; } MetaModel model = JSON.convert(o.asMap(), MetaModel.class); if (!Strings.isEmpty(model.getClassName())) { Class<?> c = Classes.tryForName(model.getClassName()); if (null == c) { throw new IllegalStateException("Model class '" + model.getClassName() + "' not found!"); } MType type = MTypes.getMType(c); if (!type.isComplexType()) { throw new IllegalStateException("The model class '" + model.getClassName() + "' must be complex type!"); } MetaUtils.tryCopyModel(type.asComplexType(), model); } MApiModelBuilder am = nonValidateSwaggerReader.readModel(name, o.asMap(), new SwaggerTypeEx()); MetaUtils.tryCopyModel(am, model); validator.validate("Model(" + model.getName() + ")", model); return model; }
protected void resolveArgumentType(RouteBuilder route, MApiParameterBuilder p, ArgumentBuilder arg) { MType type = p.getType(); if (type.isComplexType() || type.isTypeRef()) { arg.setType(Map.class); return;
if(type.isComplexType()) { MComplexType ct = type.asComplexType(); if(m.getModels().containsKey(ct.getName())) {
if(type.isComplexType()){ MComplexType ct = type.asComplexType(); MApiModel model = null;