diff --git a/gen/KubernetesGenerator/ApiGenerator.cs b/gen/KubernetesGenerator/ApiGenerator.cs index c89b79b..47a70b2 100644 --- a/gen/KubernetesGenerator/ApiGenerator.cs +++ b/gen/KubernetesGenerator/ApiGenerator.cs @@ -8,10 +8,10 @@ namespace KubernetesGenerator { public class ApiGenerator { - public void Generate(SwaggerDocument swagger, string outputDirectory) + public void Generate(OpenApiDocument swagger, string outputDirectory) { var data = swagger.Operations - .Where(o => o.Method != SwaggerOperationMethod.Options) + .Where(o => o.Method != OpenApiOperationMethod.Options) .GroupBy(o => o.Operation.OperationId) .Select(g => { @@ -50,6 +50,7 @@ namespace KubernetesGenerator .Select(o => { o.Path = o.Path.TrimStart('/'); + o.Method = char.ToUpper(o.Method[0]) + o.Method.Substring(1); return o; }) .ToArray(); diff --git a/gen/KubernetesGenerator/ClassNameHelper.cs b/gen/KubernetesGenerator/ClassNameHelper.cs index 548f073..815513e 100644 --- a/gen/KubernetesGenerator/ClassNameHelper.cs +++ b/gen/KubernetesGenerator/ClassNameHelper.cs @@ -11,10 +11,10 @@ namespace KubernetesGenerator { private readonly Dictionary classNameMap; private readonly HashSet schemaDefinitionsInMultipleGroups; - private readonly Dictionary schemaToNameMapCooked; - private readonly Dictionary schemaToNameMapUnprocessed; + private readonly Dictionary schemaToNameMapCooked; + private readonly Dictionary schemaToNameMapUnprocessed; - public ClassNameHelper(SwaggerDocument swaggerCooked, SwaggerDocument swaggerUnprocessed) + public ClassNameHelper(OpenApiDocument swaggerCooked, OpenApiDocument swaggerUnprocessed) { classNameMap = InitClassNameMap(swaggerCooked); @@ -28,19 +28,19 @@ namespace KubernetesGenerator Helpers.Register(nameof(GetClassName), GetClassName); } - private static Dictionary GenerateSchemaToNameMapUnprocessed( - SwaggerDocument swaggerUnprocessed) + private static Dictionary GenerateSchemaToNameMapUnprocessed( + OpenApiDocument swaggerUnprocessed) { return swaggerUnprocessed.Definitions.ToDictionary(x => x.Value, x => x.Key); } - private static Dictionary GenerateSchemaToNameMapCooked(SwaggerDocument swaggerCooked) + private static Dictionary GenerateSchemaToNameMapCooked(OpenApiDocument swaggerCooked) { return swaggerCooked.Definitions.ToDictionary(x => x.Value, x => x.Key.Replace(".", "").ToPascalCase()); } private static HashSet InitSchemaDefinitionsInMultipleGroups( - Dictionary schemaToNameMap) + Dictionary schemaToNameMap) { return schemaToNameMap.Values.Select(x => { @@ -60,7 +60,7 @@ namespace KubernetesGenerator .ToHashSet(); } - private Dictionary InitClassNameMap(SwaggerDocument doc) + private Dictionary InitClassNameMap(OpenApiDocument doc) { var map = new Dictionary(); foreach (var (k, v) in doc.Definitions) @@ -83,17 +83,17 @@ namespace KubernetesGenerator public void GetClassName(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerOperation) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiOperation) { - context.Write(GetClassName(arguments[0] as SwaggerOperation)); + context.Write(GetClassName(arguments[0] as OpenApiOperation)); } - else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) + else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema) { - context.Write(GetClassNameForSchemaDefinition(arguments[0] as JsonSchema4)); + context.Write(GetClassNameForSchemaDefinition(arguments[0] as JsonSchema)); } } - public string GetClassName(SwaggerOperation operation) + public string GetClassName(OpenApiOperation operation) { var groupVersionKind = (Dictionary)operation.ExtensionData["x-kubernetes-group-version-kind"]; @@ -109,7 +109,7 @@ namespace KubernetesGenerator return classNameMap[$"{group}_{kind}_{version}"]; } - public string GetClassName(JsonSchema4 definition) + public string GetClassName(JsonSchema definition) { var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"]; var groupVersionKind = (Dictionary)groupVersionKindElements[0]; @@ -117,7 +117,7 @@ namespace KubernetesGenerator return GetClassName(groupVersionKind); } - public string GetClassNameForSchemaDefinition(JsonSchema4 definition) + public string GetClassNameForSchemaDefinition(JsonSchema definition) { if (definition.ExtensionData != null && definition.ExtensionData.ContainsKey("x-kubernetes-group-version-kind")) @@ -144,7 +144,7 @@ namespace KubernetesGenerator return $"{group}{version}{entityName}".ToPascalCase(); } - private static Dictionary InitSchemaToNameCooked(SwaggerDocument swaggercooked) + private static Dictionary InitSchemaToNameCooked(OpenApiDocument swaggercooked) { return swaggercooked.Definitions.ToDictionary(x => x.Value, x => x.Key.Replace(".", "").ToPascalCase()); } diff --git a/gen/KubernetesGenerator/GeneralNameHelper.cs b/gen/KubernetesGenerator/GeneralNameHelper.cs index f96fd18..e498865 100644 --- a/gen/KubernetesGenerator/GeneralNameHelper.cs +++ b/gen/KubernetesGenerator/GeneralNameHelper.cs @@ -27,13 +27,13 @@ namespace KubernetesGenerator public void GetInterfaceName(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema) { - context.Write(GetInterfaceName(arguments[0] as JsonSchema4)); + context.Write(GetInterfaceName(arguments[0] as JsonSchema)); } } - private string GetInterfaceName(JsonSchema4 definition) + private string GetInterfaceName(JsonSchema definition) { var interfaces = new List(); if (definition.Properties.TryGetValue("metadata", out var metadataProperty)) @@ -71,7 +71,7 @@ namespace KubernetesGenerator public void GetMethodName(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerOperation) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiOperation) { string suffix = null; if (arguments.Count > 1) @@ -79,16 +79,16 @@ namespace KubernetesGenerator suffix = arguments[1] as string; } - context.Write(GetMethodName(arguments[0] as SwaggerOperation, suffix)); + context.Write(GetMethodName(arguments[0] as OpenApiOperation, suffix)); } } public void GetDotNetName(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerParameter) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiParameter) { - var parameter = arguments[0] as SwaggerParameter; + var parameter = arguments[0] as OpenApiParameter; context.Write(GetDotNetName(parameter.Name)); if (arguments.Count > 1 && arguments[1] as string == "true" && !parameter.IsRequired) @@ -133,7 +133,7 @@ namespace KubernetesGenerator { return "continueProperty"; } - else if (jsonName == "__referencePath") + else if (jsonName == "$ref") { return "refProperty"; } @@ -179,7 +179,7 @@ namespace KubernetesGenerator return jsonName.ToCamelCase(); } - public static string GetMethodName(SwaggerOperation watchOperation, string suffix) + public static string GetMethodName(OpenApiOperation watchOperation, string suffix) { var tag = watchOperation.Tags[0]; tag = tag.Replace("_", string.Empty); diff --git a/gen/KubernetesGenerator/KubernetesGenerator.csproj b/gen/KubernetesGenerator/KubernetesGenerator.csproj index 24e6476..9834647 100644 --- a/gen/KubernetesGenerator/KubernetesGenerator.csproj +++ b/gen/KubernetesGenerator/KubernetesGenerator.csproj @@ -1,4 +1,4 @@ - + Exe @@ -6,11 +6,11 @@ - - - - - + + + + + diff --git a/gen/KubernetesGenerator/MetaHelper.cs b/gen/KubernetesGenerator/MetaHelper.cs index ac6ab58..c9ca95c 100644 --- a/gen/KubernetesGenerator/MetaHelper.cs +++ b/gen/KubernetesGenerator/MetaHelper.cs @@ -19,13 +19,13 @@ namespace KubernetesGenerator public static void GetKind(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema) { - context.Write(GetKind(arguments[0] as JsonSchema4)); + context.Write(GetKind(arguments[0] as JsonSchema)); } } - private static string GetKind(JsonSchema4 definition) + private static string GetKind(JsonSchema definition) { var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"]; var groupVersionKind = (Dictionary)groupVersionKindElements[0]; @@ -36,13 +36,13 @@ namespace KubernetesGenerator public static void GetGroup(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema) { - context.Write(GetGroup(arguments[0] as JsonSchema4)); + context.Write(GetGroup(arguments[0] as JsonSchema)); } } - private static string GetGroup(JsonSchema4 definition) + private static string GetGroup(JsonSchema definition) { var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"]; var groupVersionKind = (Dictionary)groupVersionKindElements[0]; @@ -54,13 +54,13 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema) { - context.Write(GetApiVersion(arguments[0] as JsonSchema4)); + context.Write(GetApiVersion(arguments[0] as JsonSchema)); } } - private static string GetApiVersion(JsonSchema4 definition) + private static string GetApiVersion(JsonSchema definition) { var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"]; var groupVersionKind = (Dictionary)groupVersionKindElements[0]; @@ -72,14 +72,14 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { if (arguments != null && arguments.Count > 0 && arguments[0] != null && - arguments[0] is SwaggerOperationDescription) + arguments[0] is OpenApiOperationDescription) { - var operation = arguments[0] as SwaggerOperationDescription; + var operation = arguments[0] as OpenApiOperationDescription; context.Write(GetPathExpression(operation)); } } - private static string GetPathExpression(SwaggerOperationDescription operation) + private static string GetPathExpression(OpenApiOperationDescription operation) { var pathExpression = operation.Path; diff --git a/gen/KubernetesGenerator/ModelExtGenerator.cs b/gen/KubernetesGenerator/ModelExtGenerator.cs index e4967b2..32ea51c 100644 --- a/gen/KubernetesGenerator/ModelExtGenerator.cs +++ b/gen/KubernetesGenerator/ModelExtGenerator.cs @@ -15,7 +15,7 @@ namespace KubernetesGenerator this.classNameHelper = classNameHelper; } - public void Generate(SwaggerDocument swagger, string outputDirectory) + public void Generate(OpenApiDocument swagger, string outputDirectory) { // Generate the interface declarations var skippedTypes = new HashSet { "V1WatchEvent" }; diff --git a/gen/KubernetesGenerator/ModelGenerator.cs b/gen/KubernetesGenerator/ModelGenerator.cs index 01570fc..7da09a4 100644 --- a/gen/KubernetesGenerator/ModelGenerator.cs +++ b/gen/KubernetesGenerator/ModelGenerator.cs @@ -13,7 +13,7 @@ namespace KubernetesGenerator this.classNameHelper = classNameHelper; } - public void Generate(SwaggerDocument swaggercooked, string outputDirectory) + public void Generate(OpenApiDocument swaggercooked, string outputDirectory) { Directory.CreateDirectory(Path.Combine(outputDirectory, "Models")); diff --git a/gen/KubernetesGenerator/ParamHelper.cs b/gen/KubernetesGenerator/ParamHelper.cs index 5007769..25bae27 100644 --- a/gen/KubernetesGenerator/ParamHelper.cs +++ b/gen/KubernetesGenerator/ParamHelper.cs @@ -27,7 +27,7 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { - var operation = arguments?.FirstOrDefault() as SwaggerOperation; + var operation = arguments?.FirstOrDefault() as OpenApiOperation; if (operation != null) { string name = null; @@ -59,7 +59,7 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { - var schema = arguments[0] as JsonSchema4; + var schema = arguments[0] as JsonSchema; if (schema != null) { diff --git a/gen/KubernetesGenerator/PluralHelper.cs b/gen/KubernetesGenerator/PluralHelper.cs index 216894b..45e2eab 100644 --- a/gen/KubernetesGenerator/PluralHelper.cs +++ b/gen/KubernetesGenerator/PluralHelper.cs @@ -12,7 +12,7 @@ namespace KubernetesGenerator private readonly Dictionary _classNameToPluralMap; private readonly ClassNameHelper classNameHelper; - public PluralHelper(ClassNameHelper classNameHelper, SwaggerDocument swagger) + public PluralHelper(ClassNameHelper classNameHelper, OpenApiDocument swagger) { this.classNameHelper = classNameHelper; _classNameToPluralMap = InitClassNameToPluralMap(swagger); @@ -26,9 +26,9 @@ namespace KubernetesGenerator public void GetPlural(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema) { - var plural = GetPlural(arguments[0] as JsonSchema4); + var plural = GetPlural(arguments[0] as JsonSchema); if (plural != null) { context.Write($"\"{plural}\""); @@ -40,13 +40,13 @@ namespace KubernetesGenerator } } - public string GetPlural(JsonSchema4 definition) + public string GetPlural(JsonSchema definition) { var className = classNameHelper.GetClassNameForSchemaDefinition(definition); return _classNameToPluralMap.GetValueOrDefault(className, null); } - private Dictionary InitClassNameToPluralMap(SwaggerDocument swagger) + private Dictionary InitClassNameToPluralMap(OpenApiDocument swagger) { var classNameToPluralMap = swagger.Operations .Where(x => x.Operation.OperationId.StartsWith("list", StringComparison.InvariantCulture)) @@ -54,7 +54,7 @@ namespace KubernetesGenerator { PluralName = x.Path.Split("/").Last(), ClassName = classNameHelper.GetClassNameForSchemaDefinition(x.Operation.Responses["200"] - .ActualResponseSchema), + .ActualResponse.Schema.ActualSchema), }) .Distinct() .ToDictionary(x => x.ClassName, x => x.PluralName); diff --git a/gen/KubernetesGenerator/Program.cs b/gen/KubernetesGenerator/Program.cs index 1e9f607..56eb346 100644 --- a/gen/KubernetesGenerator/Program.cs +++ b/gen/KubernetesGenerator/Program.cs @@ -20,9 +20,9 @@ namespace KubernetesWatchGenerator { var outputDirectory = options.OutputPath; - var swaggerCooked = await SwaggerDocument.FromFileAsync(Path.Combine(outputDirectory, "swagger.json")) + var swaggerCooked = await OpenApiDocument.FromFileAsync(Path.Combine(outputDirectory, "swagger.json")) .ConfigureAwait(false); - var swaggerUnprocessed = await SwaggerDocument + var swaggerUnprocessed = await OpenApiDocument .FromFileAsync(Path.Combine(outputDirectory, "swagger.json.unprocessed")) .ConfigureAwait(false); @@ -45,7 +45,7 @@ namespace KubernetesWatchGenerator ; builder.RegisterType() - .WithParameter(new TypedParameter(typeof(SwaggerDocument), swaggerUnprocessed)) + .WithParameter(new TypedParameter(typeof(OpenApiDocument), swaggerUnprocessed)) .AsImplementedInterfaces() ; diff --git a/gen/KubernetesGenerator/TypeHelper.cs b/gen/KubernetesGenerator/TypeHelper.cs index b9ab415..8b8299e 100644 --- a/gen/KubernetesGenerator/TypeHelper.cs +++ b/gen/KubernetesGenerator/TypeHelper.cs @@ -28,9 +28,9 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { - if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerParameter) + if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiParameter) { - var parameter = arguments[0] as SwaggerParameter; + var parameter = arguments[0] as OpenApiParameter; if (parameter.Schema?.Reference != null) { @@ -47,9 +47,9 @@ namespace KubernetesGenerator parameter.Format)); } } - else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonProperty) + else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchemaProperty) { - var property = arguments[0] as JsonProperty; + var property = arguments[0] as JsonSchemaProperty; context.Write(GetDotNetType(property)); } else if (arguments != null && arguments.Count > 2 && arguments[0] != null && arguments[1] != null && @@ -61,11 +61,11 @@ namespace KubernetesGenerator } else if (arguments != null && arguments.Count > 0 && arguments[0] != null) { - context.Write($"ERROR: Expected SwaggerParameter but got {arguments[0].GetType().FullName}"); + context.Write($"ERROR: Expected OpenApiParameter but got {arguments[0].GetType().FullName}"); } else { - context.Write("ERROR: Expected a SwaggerParameter argument but got none."); + context.Write("ERROR: Expected a OpenApiParameter argument but got none."); } } @@ -147,7 +147,7 @@ namespace KubernetesGenerator } } - private string GetDotNetType(JsonSchema4 schema, JsonProperty parent) + private string GetDotNetType(JsonSchema schema, JsonSchemaProperty parent) { if (schema != null) { @@ -176,11 +176,11 @@ namespace KubernetesGenerator return GetDotNetType(parent.Type, parent.Name, parent.IsRequired, parent.Format); } - public string GetDotNetType(JsonProperty p) + public string GetDotNetType(JsonSchemaProperty p) { - if (p.SchemaReference != null) + if (p.Reference != null) { - return classNameHelper.GetClassNameForSchemaDefinition(p.SchemaReference); + return classNameHelper.GetClassNameForSchemaDefinition(p.Reference); } if (p.IsArray) @@ -201,7 +201,7 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { - var operation = arguments?.FirstOrDefault() as SwaggerOperation; + var operation = arguments?.FirstOrDefault() as OpenApiOperation; if (operation != null) { string style = null; @@ -214,9 +214,9 @@ namespace KubernetesGenerator } } - private string GetReturnType(SwaggerOperation operation, string sytle) + private string GetReturnType(OpenApiOperation operation, string sytle) { - SwaggerResponse response; + OpenApiResponse response; if (!operation.Responses.TryGetValue("200", out response)) { @@ -292,7 +292,7 @@ namespace KubernetesGenerator IDictionary options, RenderBlock fn, RenderBlock inverse) { - var operation = arguments?.FirstOrDefault() as SwaggerOperation; + var operation = arguments?.FirstOrDefault() as OpenApiOperation; if (operation != null) { string type = null; @@ -320,7 +320,7 @@ namespace KubernetesGenerator public static void IfType(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - var property = arguments?.FirstOrDefault() as JsonProperty; + var property = arguments?.FirstOrDefault() as JsonSchemaProperty; if (property != null) { string type = null; diff --git a/gen/KubernetesGenerator/UtilHelper.cs b/gen/KubernetesGenerator/UtilHelper.cs index 0343463..444f835 100644 --- a/gen/KubernetesGenerator/UtilHelper.cs +++ b/gen/KubernetesGenerator/UtilHelper.cs @@ -29,7 +29,7 @@ namespace KubernetesGenerator public static void IfKindIs(RenderContext context, IList arguments, IDictionary options, RenderBlock fn, RenderBlock inverse) { - var parameter = arguments?.FirstOrDefault() as SwaggerParameter; + var parameter = arguments?.FirstOrDefault() as OpenApiParameter; if (parameter != null) { string kind = null; @@ -38,11 +38,11 @@ namespace KubernetesGenerator kind = arguments[1] as string; } - if (kind == "query" && parameter.Kind == SwaggerParameterKind.Query) + if (kind == "query" && parameter.Kind == OpenApiParameterKind.Query) { fn(null); } - else if (kind == "path" && parameter.Kind == SwaggerParameterKind.Path) + else if (kind == "path" && parameter.Kind == OpenApiParameterKind.Path) { fn(null); } diff --git a/gen/KubernetesGenerator/WatchGenerator.cs b/gen/KubernetesGenerator/WatchGenerator.cs index 80c117d..58b4255 100644 --- a/gen/KubernetesGenerator/WatchGenerator.cs +++ b/gen/KubernetesGenerator/WatchGenerator.cs @@ -7,7 +7,7 @@ namespace KubernetesGenerator { public class WatchGenerator { - public void Generate(SwaggerDocument swagger, string outputDirectory) + public void Generate(OpenApiDocument swagger, string outputDirectory) { // Generate the Watcher operations // We skip operations where the name of the class in the C# client could not be determined correctly.