public void CreateSchemasTypeTree(Models.OpenApi openApi) { var modelTypes = openApi.Components.Schemas.Keys.ToList(); foreach (var type in modelTypes) { AddKey(type); } }
public async Task BuildBareDefinitions(Models.OpenApi openApiModel) { var typeTree = new TypeTree(); typeTree.CreateSchemasTypeTree(openApiModel); await using (var streamWriter = new StreamWriter(Path.Combine( _destinationFolder, "GlobalUsings.cs"), append: false)) { await streamWriter.WriteAsync(GlobalUsingsText); } await using (var streamWriter = new StreamWriter(Path.Combine( _destinationFolder, "DotNetBungieAPIJsonSerializationContext.cs"), append: false)) { await streamWriter.WriteLineAsync("namespace DotNetBungieAPI.Generated.Models;"); await streamWriter.WriteLineAsync(); foreach (var(typeName, typeSchema) in openApiModel.Components.Schemas) { if (typeSchema.Type is "object" && (typeSchema.Properties is null || !typeSchema.Properties.Any())) { continue; } await streamWriter.WriteLineAsync($"[JsonSerializable(typeof({typeName}))]"); } await streamWriter.WriteLineAsync("public partial class DotNetBungieAPIJsonSerializationContext : JsonSerializerContext { }"); } foreach (var treeNode in typeTree.Nodes.Values) { await IterateThroughTypeTreeBare(openApiModel, treeNode, _destinationFolder); } foreach (var(responseName, openApiComponentResponse) in openApiModel.Components.Responses) { var schema = openApiComponentResponse.Content.Schema; } }
private async Task IterateThroughTypeTreeBare( Models.OpenApi openApiModel, TreeNode treeNode, string previousPath) { if (treeNode.IsFolder) { var currentFolder = Path.Combine(previousPath, treeNode.Name); Directory.CreateDirectory(currentFolder); foreach (var childNode in treeNode.Nodes.Values) { await IterateThroughTypeTreeBare(openApiModel, childNode, currentFolder); } } if (treeNode.IsType) { var currentFile = Path.Combine(previousPath, $"{treeNode.Name}.cs"); var fullTypeName = currentFile .Replace( _destinationFolder, string.Empty) .Replace( '\\', '.') [1..^ 3]; var typeSchema = openApiModel.Components.Schemas[fullTypeName]; if (typeSchema.Type is "array") { return; } if (typeSchema.Type is "object" && (typeSchema.Properties is null || !typeSchema.Properties.Any())) { return; } await using var streamWriter = new StreamWriter(currentFile, append: false); if (fullTypeName.Any(x => x == '.')) { var pathData = fullTypeName.Split('.')[0..^ 1];