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); } } }
protected String modelName(ApiMetadataContext context, MComplexType ct) { if(null != ct.getJavaType()) { ApiModel a = ct.getJavaType().getAnnotation(ApiModel.class); if(null != a) { String name = Strings.firstNotEmpty(a.name(),a.value()); if(!Strings.isEmpty(name)) { return name; } } ModelConfig mc = context.getConfig().getModelConfig(ct.getJavaType()); if(null != mc && !Strings.isEmpty(mc.getName())) { return mc.getName(); } } return ct.getName(); }
@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; }
public MApiModelBuilder(MComplexType type, String name) { this.type = type; this.name = Strings.isEmpty(name) ? type.getName() : name; this.title = type.getTitle(); this.summary = type.getSummary(); this.description = type.getDescription(); this.entity = type.isEntity(); boolean annotatedOnly = false; if(null != type.getJavaType()) { this.javaTypes.add(type.getJavaType()); ApiModel a = type.getJavaType().getAnnotation(ApiModel.class); if(null != a) { this.name = Strings.firstNotEmpty(a.name(), a.value(), this.name); this.description = Strings.firstNotEmpty(a.desc(), this.description); annotatedOnly = a.explicitProperties(); } } for (MProperty mp : type.getProperties()) { if(annotatedOnly) { BeanProperty bp = mp.getBeanProperty(); if(null != bp && !bp.isAnnotationPresent(ApiProperty.class)) { continue; } } addProperty(new MApiPropertyBuilder(mp)); } }
MComplexType ct = type.asComplexType(); MApiModel model = null; if(null != ct.getJavaType()) { model = m.tryGetModel(ct.getJavaType()); }else { model = m.tryGetModel(ct.getName());