Ejemplo n.º 1
0
        /// <summary>
        /// Initiates the parsing process of a fragment.  Not thread safe and should only be called once on a parsing context
        /// </summary>
        /// <param name="yamlDocument"></param>
        /// <param name="version">OpenAPI version of the fragment</param>
        /// <param name="diagnostic">Diagnostic object which will return diagnostic results of the operation.</param>
        /// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns>
        internal T ParseFragment <T>(YamlDocument yamlDocument, OpenApiSpecVersion version, OpenApiDiagnostic diagnostic) where T : IOpenApiElement
        {
            var node = ParseNode.Create(this, diagnostic, yamlDocument.RootNode);

            T element = default(T);

            switch (version)
            {
            case OpenApiSpecVersion.OpenApi2_0:
                VersionService = new OpenApiV2VersionService();
                element        = this.VersionService.LoadElement <T>(node);
                break;

            case OpenApiSpecVersion.OpenApi3_0:
                this.VersionService = new OpenApiV3VersionService();
                element             = this.VersionService.LoadElement <T>(node);
                break;
            }

            return(element);
        }