Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,12 @@ protected static async Task<OpenApiDocument> ReadAndProcessOpenApiDocument(Gener
var documentStr = context.DocumentReader!.ReadToEnd();
documentStr = InvokePreprocessors<string>(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>(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("}"));
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down