Exemplo n.º 1
0
        public async Task When_yaml_schema_has_references_it_works(string relativePath)
        {
            //// Arrange
            var path = GetTestDirectory() + relativePath;

            //// Act
            var document = await SwaggerYamlDocument.FromFileAsync(path);

            var json = document.ToJson();

            //// Assert
            Assert.Equal(JsonObjectType.Integer, document.Definitions["ContractObject"].Properties["foo"].ActualTypeSchema.Type);
            Assert.Equal(JsonObjectType.Boolean, document.Definitions["ContractObject"].Properties["bar"].ActualTypeSchema.Type);
        }
Exemplo n.º 2
0
 protected async Task <SwaggerDocument> ReadSwaggerDocumentAsync(string input)
 {
     if (!IsJson(input) && !IsYaml(input))
     {
         if (input.StartsWith("http://") || input.StartsWith("https://"))
         {
             if (input.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase) ||
                 input.EndsWith(".yml", StringComparison.OrdinalIgnoreCase))
             {
                 return(await SwaggerYamlDocument.FromUrlAsync(input).ConfigureAwait(false));
             }
             else
             {
                 return(await SwaggerDocument.FromUrlAsync(input).ConfigureAwait(false));
             }
         }
         else
         {
             if (input.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase) ||
                 input.EndsWith(".yml", StringComparison.OrdinalIgnoreCase))
             {
                 return(await SwaggerYamlDocument.FromFileAsync(input).ConfigureAwait(false));
             }
             else
             {
                 return(await SwaggerDocument.FromFileAsync(input).ConfigureAwait(false));
             }
         }
     }
     else
     {
         if (IsYaml(input))
         {
             return(await SwaggerYamlDocument.FromYamlAsync(input).ConfigureAwait(false));
         }
         else
         {
             return(await SwaggerDocument.FromJsonAsync(input).ConfigureAwait(false));
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>Loads the Swagger spec.</summary>
 public async Task <SwaggerDocument> RunAsync()
 {
     if (!string.IsNullOrEmpty(Swagger))
     {
         if (Swagger.StartsWith("{"))
         {
             return(await SwaggerDocument.FromJsonAsync(Swagger).ConfigureAwait(false));
         }
         else
         {
             return(await SwaggerYamlDocument.FromYamlAsync(Swagger).ConfigureAwait(false));
         }
     }
     else if (Url.StartsWith("http://") || Url.StartsWith("https://"))
     {
         if (Url.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase))
         {
             return(await SwaggerYamlDocument.FromUrlAsync(Url).ConfigureAwait(false));
         }
         else
         {
             return(await SwaggerDocument.FromUrlAsync(Url).ConfigureAwait(false));
         }
     }
     else
     {
         if (Url.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase))
         {
             return(await SwaggerYamlDocument.FromFileAsync(Url).ConfigureAwait(false));
         }
         else
         {
             return(await SwaggerDocument.FromFileAsync(Url).ConfigureAwait(false));
         }
     }
 }