static JObject CreateSwaggerDefinitionForStructureType(IEdmStructuredType edmType) { JObject swaggerProperties = new JObject(); foreach (var property in edmType.StructuralProperties()) { JObject swaggerProperty = new JObject().Description(property.Name); SetSwaggerType(swaggerProperty, property.Type.Definition); swaggerProperties.Add(property.Name, swaggerProperty); } //Add support for base type //Root base type to be ignored: microsoft.graph.entity string baseType = ""; if (edmType.BaseType() != null) { baseType = edmType.BaseType().FullTypeName(); } JObject _EntityDefintiion = null; if (baseType != "microsoft.graph.entity") { if (baseType == "microsoft.graph.directoryObject") { swaggerProperties.Remove("id"); _EntityDefintiion = new JObject() { { "allOf", new JArray(new JObject() { { "$ref", "#/definitions/microsoft.graph.directoryObject" } }, new JObject() { { "properties", swaggerProperties } }) } }; // } else { _EntityDefintiion = new JObject() { { "properties", swaggerProperties } }; } } else { _EntityDefintiion = new JObject() { { "properties", swaggerProperties } }; } return(_EntityDefintiion); }
// returns -1 if type does not derive from baseType and a positive number representing the distance // between them if it does. private static int IsDerivedTypeOf(IEdmStructuredType type, IEdmStructuredType baseType) { int distance = 0; while (type != null) { if (baseType == type) { return(distance); } type = type.BaseType(); distance++; } return(-1); }
/// <summary> /// Gets an enumerable containing the given type and all of its base/ancestor types. /// </summary> /// <param name="structuredType">The starting resource type. Will be included in the returned enumeration.</param> /// <returns>An enumerable containing the given type and all of its base/ancestor types.</returns> private static IEnumerable <IEdmStructuredType> GetBaseTypesAndSelf(IEdmStructuredType structuredType) { for (IEdmStructuredType currentType = structuredType; currentType != null; currentType = currentType.BaseType()) { yield return(currentType); } }