Exemple #1
0
        /// <summary>
        /// Build composite types from definitions
        /// </summary>
        public virtual void BuildCompositeTypes()
        {
            // Load any external references
            foreach (var reference in ServiceDefinition.ExternalReferences)
            {
                string[] splitReference = reference.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                Debug.Assert(splitReference.Length == 2);
                string            filePath           = splitReference[0];
                string            externalDefinition = Settings.FileSystem.ReadFileAsText(filePath);
                ServiceDefinition external           = SwaggerParser.Parse(externalDefinition);
                external.Definitions.ForEach(d => ServiceDefinition.Definitions[d.Key] = d.Value);
            }

            // Build service types and validate allOf
            if (ServiceDefinition.Definitions != null)
            {
                foreach (var schemaName in ServiceDefinition.Definitions.Keys.ToArray())
                {
                    var schema = ServiceDefinition.Definitions[schemaName];
                    schema.GetBuilder(this).BuildServiceType(schemaName);

                    Resolver.ExpandAllOf(schema);
                    var parent = string.IsNullOrEmpty(schema.Extends.StripDefinitionPath())
                        ? null
                        : ServiceDefinition.Definitions[schema.Extends.StripDefinitionPath()];

                    if (parent != null &&
                        !AncestorsHaveProperties(parent.Properties, parent.Extends.StripDefinitionPath()))
                    {
                        throw ErrorManager.CreateError(Resources.InvalidAncestors, schemaName);
                    }
                }
            }
        }
Exemple #2
0
        public static ServiceDefinition Load(string path, IFileSystem fileSystem)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException("fileSystem");
            }

            return(SwaggerParser.Parse(fileSystem.ReadFileAsText(path)));
        }