/// <summary> /// Create the dictionary of <see cref="OpenApiExample"/> object. /// </summary> /// <param name="context">The OData to Open API context.</param> /// <returns>The created <see cref="OpenApiExample"/> dictionary.</returns> public static IDictionary <string, OpenApiExample> CreateExamples(this ODataContext context) { Utils.CheckArgumentNull(context, nameof(context)); IDictionary <string, OpenApiExample> examples = new Dictionary <string, OpenApiExample>(); // Each entity type, complex type, enumeration type, and type definition directly // or indirectly used in the paths field is represented as a name / value pair of the schemas map. // Ideally this would be driven off the types used in the paths, but in practice, it is simply // all of the types present in the model. IEnumerable <IEdmSchemaElement> elements = context.Model.GetAllElements(); foreach (var element in elements) { switch (element.SchemaElementKind) { case EdmSchemaElementKind.TypeDefinition: // Type definition { IEdmType reference = (IEdmType)element; OpenApiExample example = context.CreateExample(reference); if (example != null) { examples.Add(reference.FullTypeName(), example); } } break; } } return(examples); }
/// <summary> /// Create the dictionary of <see cref="OpenApiExample"/> object. /// </summary> /// <param name="context">The OData to Open API context.</param> /// <param name="securitySchemes">The securitySchemes.</param> /// <returns>The created <see cref="OpenApiExample"/> dictionary.</returns> public static IDictionary <string, OpenApiExample> CreateExamples(this ODataContext context) { Utils.CheckArgumentNull(context, nameof(context)); IDictionary <string, OpenApiExample> examples = new Dictionary <string, OpenApiExample>(); // Each entity type, complex type, enumeration type, and type definition directly // or indirectly used in the paths field is represented as a name / value pair of the schemas map. foreach (var element in context.Model.SchemaElements.Where(c => !c.Namespace.StartsWith("Org.OData."))) { switch (element.SchemaElementKind) { case EdmSchemaElementKind.TypeDefinition: // Type definition { IEdmType reference = (IEdmType)element; OpenApiExample example = context.CreateExample(reference); if (example != null) { examples.Add(reference.FullTypeName(), example); } } break; } } return(examples); }