Ejemplo n.º 1
0
        private static Dictionary <string, object> BuildDictionaryExample(ComplexType ct, IEnumerable <Schema> otherSchema, MetadataValidationConfigs metadataValidationConfigs = null)
        {
            Dictionary <string, object> propertyExamples = new Dictionary <string, object>();

            if (!string.IsNullOrWhiteSpace(ct.Namespace))
            {
                var resourceType = BuildResourceTypeIdentifer(
                    ct.Namespace,
                    metadataValidationConfigs?.ModelConfigs?.AliasNamespace,
                    ct.TypeIdentifier,
                    metadataValidationConfigs?.ModelConfigs?.ValidateNamespace);

                propertyExamples.Add("@odata.type", resourceType);
            }

            foreach (var property in ct.Properties.Where(prop => prop.Type != "Edm.Stream"))
            {
                propertyExamples.Add(property.Name, ExampleOfType(property.Type, otherSchema));
            }

            return(propertyExamples);
        }
Ejemplo n.º 2
0
        public static string BuildJsonExample(ComplexType ct, IEnumerable <Schema> otherSchema, MetadataValidationConfigs metadataValidationConfigs = null)
        {
            Dictionary <string, object> dict = BuildDictionaryExample(ct, otherSchema, metadataValidationConfigs);

            return(JsonConvert.SerializeObject(dict, Newtonsoft.Json.Formatting.Indented));
        }
Ejemplo n.º 3
0
        private static IEnumerable <ResourceDefinition> CreateResourcesFromSchema(Schema schema, IEnumerable <Schema> otherSchema, IssueLogger issues, MetadataValidationConfigs metadataValidationConfigs)
        {
            List <ResourceDefinition> resources = new List <ResourceDefinition>();

            resources.AddRange(from ct in schema.ComplexTypes select ResourceDefinitionFromType(schema, otherSchema, ct, issues, metadataValidationConfigs));
            resources.AddRange(from et in schema.EntityTypes select ResourceDefinitionFromType(schema, otherSchema, et, issues, metadataValidationConfigs));

            return(resources);
        }
Ejemplo n.º 4
0
        private static ResourceDefinition ResourceDefinitionFromType(Schema schema, IEnumerable <Schema> otherSchema, ComplexType ct, IssueLogger issues, MetadataValidationConfigs metadataValidationConfigs)
        {
            var resourceType = BuildResourceTypeIdentifer(
                schema.Namespace,
                metadataValidationConfigs?.ModelConfigs?.AliasNamespace,
                ct.Name,
                metadataValidationConfigs?.ModelConfigs?.ValidateNamespace);

            var annotation = new CodeBlockAnnotation()
            {
                ResourceType = resourceType, BlockType = CodeBlockType.Resource
            };
            var json = BuildJsonExample(ct, otherSchema, metadataValidationConfigs);
            ResourceDefinition rd = new JsonResourceDefinition(annotation, json, null, issues);

            return(rd);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert resources found in the CSDL schema objects into ResourceDefintion instances
        /// that can be tested against the documentation.
        /// </summary>
        /// <param name="schemas"></param>
        /// <returns></returns>
        public static List <ResourceDefinition> GenerateResourcesFromSchemas(IEnumerable <Schema> schemas, IssueLogger issues, MetadataValidationConfigs metadataValidationConfigs = null)
        {
            List <ResourceDefinition> resources = new List <ResourceDefinition>();

            foreach (var schema in schemas)
            {
                resources.AddRange(CreateResourcesFromSchema(schema, schemas, issues, metadataValidationConfigs));
            }

            return(resources);
        }