-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a model generator for FluentHub.Octokit (#197)
- Loading branch information
Showing
2,146 changed files
with
68,050 additions
and
15,151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace FluentHub.Octokit.Generation | ||
{ | ||
internal static class AttributeGenerator | ||
{ | ||
public static string GenerateObsoleteAttribute(string reason) | ||
{ | ||
if (string.IsNullOrWhiteSpace(reason)) | ||
{ | ||
return "[Obsolete]"; | ||
} | ||
|
||
return $"[Obsolete(@\"{reason}\")]"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using FluentHub.Octokit.Generation.Models; | ||
using Octokit.GraphQL.Core.Introspection; | ||
|
||
namespace FluentHub.Octokit.Generation | ||
{ | ||
public static class CodeGenerator | ||
{ | ||
public static IEnumerable<GeneratedFile> Generate(SchemaModel schema, string rootNamespace, string entityNamespace = null) | ||
{ | ||
foreach (var type in schema.Types) | ||
{ | ||
if (!type.Name.StartsWith("__") && type.Kind != TypeKind.Scalar) | ||
{ | ||
yield return Generate(type, rootNamespace, schema.QueryType, entityNamespace); | ||
} | ||
} | ||
} | ||
|
||
public static GeneratedFile Generate(TypeModel type, string rootNamespace, string queryType, string entityNamespace = null) | ||
{ | ||
entityNamespace = entityNamespace ?? rootNamespace; | ||
|
||
string result = null; | ||
switch (type.Kind) | ||
{ | ||
case TypeKind.Object: | ||
if (type.Name == queryType || type.Name == "Mutation") | ||
{ | ||
// Mutation.cs and Query.cs is not needed | ||
} | ||
else | ||
{ | ||
result = EntityGenerator.Generate(type, entityNamespace, queryType, entityNamespace: entityNamespace); | ||
} | ||
break; | ||
|
||
case TypeKind.Interface: | ||
result = InterfaceGenerator.Generate(type, entityNamespace, queryType); | ||
break; | ||
|
||
case TypeKind.Enum: | ||
result = EnumGenerator.Generate(type, entityNamespace); | ||
break; | ||
|
||
case TypeKind.InputObject: | ||
result = InputObjectGenerator.Generate(type, entityNamespace); | ||
break; | ||
|
||
case TypeKind.Union: | ||
result = UnionGenerator.Generate(type, entityNamespace); | ||
break; | ||
} | ||
|
||
var fileName = type.Name + ".cs"; | ||
return new GeneratedFile(fileName, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Text; | ||
using System.Xml; | ||
|
||
namespace FluentHub.Octokit.Generation | ||
{ | ||
internal static class DocCommentGenerator | ||
{ | ||
public static void GenerateSummary(string summary, int indentation, StringBuilder builder) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(summary)) | ||
{ | ||
var indent = new string(' ', indentation); | ||
builder.Append(indent); | ||
builder.AppendLine("/// <summary>"); | ||
GenerateCommentBlock(summary, indent, builder); | ||
builder.Append(indent); | ||
builder.AppendLine(@"/// </summary>"); | ||
} | ||
} | ||
|
||
private static void GenerateCommentBlock(string text, string indent, StringBuilder builder) | ||
{ | ||
text = text.Replace("&", "&").Replace("<", "<").Replace(">", ">"); | ||
|
||
foreach (var line in text.Split('\r', '\n')) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(line)) | ||
{ | ||
builder.Append(indent); | ||
builder.Append("/// "); | ||
builder.AppendLine(line); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.