Skip to content

Commit

Permalink
Merge pull request #8 from MobileTeleSystems/fix/issue6_notLoadYaml
Browse files Browse the repository at this point in the history
Dont check extension for detect file format
  • Loading branch information
genusP authored Oct 4, 2024
2 parents 753368d + 42ac55f commit f25310c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
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("}"));
}
}

}

Check warning on line 131 in src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs

View workflow job for this annotation

GitHub Actions / build_and_test

Check warning on line 131 in src/ApiCodeGenerator.OpenApi/ContentGeneratorBase.cs

View workflow job for this annotation

GitHub Actions / build_and_test

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

0 comments on commit f25310c

Please sign in to comment.