diff --git a/src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs b/src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs index e67ba8e..ce0a599 100644 --- a/src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs +++ b/src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs @@ -120,19 +120,12 @@ protected static async Task ReadAndProcessOpenApiDocument(Gener var documentStr = context.DocumentReader!.ReadToEnd(); documentStr = InvokePreprocessors(documentStr, context.Preprocessors, context.DocumentPath); - var openApiDocument = IsYaml() + var openApiDocument = !(documentStr.StartsWith("{") && documentStr.EndsWith("}")) ? await OpenApiYamlDocument.FromYamlAsync(documentStr) : await OpenApiDocument.FromJsonAsync(documentStr); openApiDocument = InvokePreprocessors(openApiDocument, context.Preprocessors, context.DocumentPath); return openApiDocument; - - bool IsYaml() - { - return - (context.DocumentPath is not null && (context.DocumentPath.EndsWith("yml") || context.DocumentPath.EndsWith("yaml"))) - || !(documentStr.StartsWith("{") && documentStr.EndsWith("}")); - } } } diff --git a/test/ApiCodeGenerator.OpenApi.Tests/ContentGeneratorFactoryTests.cs b/test/ApiCodeGenerator.OpenApi.Tests/ContentGeneratorFactoryTests.cs index b2a2852..160b885 100644 --- a/test/ApiCodeGenerator.OpenApi.Tests/ContentGeneratorFactoryTests.cs +++ b/test/ApiCodeGenerator.OpenApi.Tests/ContentGeneratorFactoryTests.cs @@ -128,14 +128,12 @@ public async Task LoadOpenApiDocument_WithModelPreprocess() Assert.That(sch, Is.EqualTo("{\"$schema\":\"http://json-schema.org/draft-04/schema#\",\"additionalProperties\":false,\"properties\":{\"processedModel\":{}}}")); } - [TestCase(null)] - [TestCase("testSchem.yaml")] - public async Task LoadOpenApiDocument_FromYaml(string? documentPath) + [Test] + public async Task LoadOpenApiDocument_FromYaml() { var context = CreateContext(new()); var schemaText = await File.ReadAllTextAsync(TestHelpers.GetSwaggerPath("testSchema.yaml")); context.DocumentReader = new StringReader(schemaText); - context.DocumentPath = documentPath; var gen = (CSharpClientContentGenerator)await CSharpClientContentGenerator.CreateAsync(context);