<commit_before>//-----------------------------------------------------------------------
// <copyright file="NSwagDocument.cs" company="NSwag">
//     Copyright (c) <NAME>. All rights reserved.
// </copyright>
// <license>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</license>
// <author><NAME>, <EMAIL></author>
//-----------------------------------------------------------------------

using System.Threading.Tasks;
using NSwag.CodeGeneration.Commands;
using NSwag.CodeGeneration.Utilities;
using NSwag.Commands;

namespace NSwag.CodeGeneration
{
    /// <summary>The NSwagDocument implementation.</summary>
    /// <seealso cref="NSwag.Commands.NSwagDocumentBase" />
    public class NSwagDocument : NSwagDocumentBase
    {
        /// <summary>Initializes a new instance of the <see cref="NSwagDocument"/> class.</summary>
        public NSwagDocument()
        {
            SwaggerGenerators.Add(WebApiToSwaggerCommand = new WebApiToSwaggerCommand());
            SwaggerGenerators.Add(AssemblyTypeToSwaggerCommand = new AssemblyTypeToSwaggerCommand());
        }

        /// <summary>Creates a new NSwagDocument.</summary>
        /// <returns>The document.</returns>
        public static NSwagDocument Create()
        {
            return Create<NSwagDocument>();
        }

        /// <summary>Loads an existing NSwagDocument.</summary>
        /// <param name="filePath">The file path.</param>
        /// <returns>The document.</returns>
        public static Task<NSwagDocument> LoadAsync(string filePath)
        {
            return LoadAsync<NSwagDocument>(filePath);
        }

        /// <summary>Converts to absolute path.</summary>
        /// <param name="pathToConvert">The path to convert.</param>
        /// <returns></returns>
        protected override string ConvertToAbsolutePath(string pathToConvert)
        {
            if (!string.IsNullOrEmpty(pathToConvert) && !System.IO.Path.IsPathRooted(pathToConvert))
                return PathUtilities.MakeAbsolutePath(pathToConvert, System.IO.Path.GetDirectoryName(Path));
            return pathToConvert;
        }

        /// <summary>Converts a path to an relative path.</summary>
        /// <param name="pathToConvert">The path to convert.</param>
        /// <returns>The relative path.</returns>
        protected override string ConvertToRelativePath(string pathToConvert)
        {
            if (!string.IsNullOrEmpty(pathToConvert) && !pathToConvert.Contains("C:\\Program Files\\"))
                return PathUtilities.MakeRelativePath(pathToConvert, System.IO.Path.GetDirectoryName(Path));
            return pathToConvert;
        }

        /// <summary>Generates the Swagger specification.</summary>
        /// <returns>The Swagger specification.</returns>
        protected override async Task<SwaggerDocument> GenerateDocumentAsync()
        {
            if (SelectedSwaggerGenerator == 1)
                return await WebApiToSwaggerCommand.RunAsync();
            else if (SelectedSwaggerGenerator == 3)
                return await AssemblyTypeToSwaggerCommand.RunAsync();
            else
                return await base.GenerateDocumentAsync();
        }
    }
}<commit_msg>Fixed nswag reading from relative path, fixes #413<commit_after>//-----------------------------------------------------------------------
// <copyright file="NSwagDocument.cs" company="NSwag">
//     Copyright (c) <NAME>. All rights reserved.
// </copyright>
// <license>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</license>
// <author><NAME>, <EMAIL></author>
//-----------------------------------------------------------------------

using System.Threading.Tasks;
using NSwag.CodeGeneration.Commands;
using NSwag.CodeGeneration.Utilities;
using NSwag.Commands;

namespace NSwag.CodeGeneration
{
    /// <summary>The NSwagDocument implementation.</summary>
    /// <seealso cref="NSwag.Commands.NSwagDocumentBase" />
    public class NSwagDocument : NSwagDocumentBase
    {
        /// <summary>Initializes a new instance of the <see cref="NSwagDocument"/> class.</summary>
        public NSwagDocument()
        {
            SwaggerGenerators.Add(WebApiToSwaggerCommand = new WebApiToSwaggerCommand());
            SwaggerGenerators.Add(AssemblyTypeToSwaggerCommand = new AssemblyTypeToSwaggerCommand());
        }

        /// <summary>Creates a new NSwagDocument.</summary>
        /// <returns>The document.</returns>
        public static NSwagDocument Create()
        {
            return Create<NSwagDocument>();
        }

        /// <summary>Loads an existing NSwagDocument.</summary>
        /// <param name="filePath">The file path.</param>
        /// <returns>The document.</returns>
        public static Task<NSwagDocument> LoadAsync(string filePath)
        {
            return LoadAsync<NSwagDocument>(filePath);
        }

        /// <summary>Converts to absolute path.</summary>
        /// <param name="pathToConvert">The path to convert.</param>
        /// <returns></returns>
        protected override string ConvertToAbsolutePath(string pathToConvert)
        {
            if (!string.IsNullOrEmpty(pathToConvert) && !System.IO.Path.IsPathRooted(pathToConvert))
                return PathUtilities.MakeAbsolutePath(pathToConvert, GetDocumentDirectory());
            return pathToConvert;
        }

        /// <summary>Converts a path to an relative path.</summary>
        /// <param name="pathToConvert">The path to convert.</param>
        /// <returns>The relative path.</returns>
        protected override string ConvertToRelativePath(string pathToConvert)
        {
            if (!string.IsNullOrEmpty(pathToConvert) && !pathToConvert.Contains("C:\\Program Files\\"))
                return PathUtilities.MakeRelativePath(pathToConvert, GetDocumentDirectory());
            return pathToConvert;
        }

        /// <summary>Generates the Swagger specification.</summary>
        /// <returns>The Swagger specification.</returns>
        protected override async Task<SwaggerDocument> GenerateDocumentAsync()
        {
            if (SelectedSwaggerGenerator == 1)
                return await WebApiToSwaggerCommand.RunAsync();
            else if (SelectedSwaggerGenerator == 3)
                return await AssemblyTypeToSwaggerCommand.RunAsync();
            else
                return await base.GenerateDocumentAsync();
        }

        private string GetDocumentDirectory()
        {
            var absoluteDocumentPath = PathUtilities.MakeAbsolutePath(Path, System.IO.Directory.GetCurrentDirectory());
            return System.IO.Path.GetDirectoryName(absoluteDocumentPath);
        }
    }
}
{'fraction_non_alphanumeric': 0.15455091619104835, 'fraction_numerical': 0.0010513667768098527, 'mean_word_length': 2.2578277886497067, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 93, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6604810', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1656, 'n_words': 336}