コード例 #1
0
        private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext context, IEdmStructuredType structuredType, bool processBase, bool processExample)
        {
            Debug.Assert(context != null);
            Debug.Assert(structuredType != null);

            // A structured type without a base type is represented as a Schema Object of type object
            OpenApiSchema schema = new OpenApiSchema
            {
                Title = (structuredType as IEdmSchemaElement)?.Name,

                Type = "object",

                // Each structural property and navigation property is represented
                // as a name/value pair of the standard OpenAPI properties object.
                // Add properties from referenced types instead of using AllOf
                // because AllOf is not supported by PowerApps
                Properties = context.CreateStructuredTypeCombinedPropertiesSchema(structuredType),

                // make others null
                AllOf = null,
                OneOf = null,
                AnyOf = null
            };

            // It optionally can contain the field description,
            // whose value is the value of the unqualified annotation Core.Description of the structured type.
            if (structuredType.TypeKind == EdmTypeKind.Complex)
            {
                IEdmComplexType complex = (IEdmComplexType)structuredType;
                schema.Description = context.Model.GetDescriptionAnnotation(complex);
            }
            else if (structuredType.TypeKind == EdmTypeKind.Entity)
            {
                IEdmEntityType entity = (IEdmEntityType)structuredType;
                schema.Description = context.Model.GetDescriptionAnnotation(entity);
            }

            if (processExample)
            {
                schema.Example = CreateStructuredTypePropertiesExample(context, structuredType);
            }

            return(schema);
        }