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); } } }
CACHED_COMPLEX_TYPES.put(type, mtype.asComplexType()); return mtype.asComplexType().createTypeRef();
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); }); }
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; }
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 + "'"); }
MComplexType ct = type.asComplexType(); if(m.getModels().containsKey(ct.getName())) { writeRefType(context, m, w, ((MComplexType)type).createTypeRef());
MComplexType ct = type.asComplexType(); MApiModel model = null; if(null != ct.getJavaType()) {
model = MetaUtils.toMetaModel(type.asComplexType()); return new ModelValidator(name, required, api, model, partial, true);