diff --git a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxCSharpGenerator.java b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxCSharpGenerator.java index 3df875b..28d9abf 100644 --- a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxCSharpGenerator.java +++ b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxCSharpGenerator.java @@ -244,6 +244,12 @@ public boolean supportsStacksTemplates() return true; } + @Override + public boolean permissionResourceTypeAsString() + { + return true; + } + @NotNull @Override public Collection getTypeAdapterImports() diff --git a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxGenerator.java b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxGenerator.java index 7a85d52..0443ddc 100644 --- a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxGenerator.java +++ b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxGenerator.java @@ -17,6 +17,8 @@ public interface InfluxGenerator String toEnumConstructorDefaultValue(String value, String datatype); + String toEnumVarName(String value, String datatype); + @Nullable String optionalDatatypeKeyword(); @@ -28,6 +30,8 @@ public interface InfluxGenerator boolean supportsStacksTemplates(); + boolean permissionResourceTypeAsString(); + @Nonnull Collection getTypeAdapterImports(); } diff --git a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxJavaGenerator.java b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxJavaGenerator.java index 6184825..e83d70d 100644 --- a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxJavaGenerator.java +++ b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxJavaGenerator.java @@ -451,6 +451,12 @@ public boolean supportsStacksTemplates() return false; } + @Override + public boolean permissionResourceTypeAsString() + { + return true; + } + @NotNull @Override public Collection getTypeAdapterImports() diff --git a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPhpGenerator.java b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPhpGenerator.java index 1ab8e1f..47df650 100644 --- a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPhpGenerator.java +++ b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPhpGenerator.java @@ -209,6 +209,12 @@ public boolean supportsStacksTemplates() return false; } + @Override + public boolean permissionResourceTypeAsString() + { + return false; + } + @NotNull @Override public Collection getTypeAdapterImports() diff --git a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPythonGenerator.java b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPythonGenerator.java index e69bc7e..8bfab38 100644 --- a/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPythonGenerator.java +++ b/openapi-generator/src/main/java/com/influxdb/codegen/InfluxPythonGenerator.java @@ -205,6 +205,12 @@ public boolean supportsStacksTemplates() return true; } + @Override + public boolean permissionResourceTypeAsString() + { + return false; + } + @NotNull @Override public Collection getTypeAdapterImports() diff --git a/openapi-generator/src/main/java/com/influxdb/codegen/PostProcessHelper.java b/openapi-generator/src/main/java/com/influxdb/codegen/PostProcessHelper.java index 2ff5b3b..38d9994 100644 --- a/openapi-generator/src/main/java/com/influxdb/codegen/PostProcessHelper.java +++ b/openapi-generator/src/main/java/com/influxdb/codegen/PostProcessHelper.java @@ -192,6 +192,25 @@ void postProcessOpenAPI() } } + // + // Change PermissionResource type to String schema - fixup to avoid exception for non-existing item + // + if (generator.permissionResourceTypeAsString()) + { + StringSchema oldSchema = (StringSchema) openAPI.getComponents().getSchemas().get("Resource").getProperties().get("type"); + StringSchema newSchema = new StringSchema(); + List> staticValues = oldSchema.getEnum().stream().map(item -> { + Map map = new HashMap<>(); + map.put("title", generator.toEnumVarName("type_" + org.openapitools.codegen.utils.StringUtils.camelize(item), oldSchema.getType())); + map.put("value", item); + + return map; + }).collect(Collectors.toList()); + newSchema.addExtension("x-static-values", staticValues); + newSchema.addExtension("x-has-static-values", true); + changePropertySchema("type", "Resource", newSchema); + } + // // Drop supports for Geo // diff --git a/openapi-generator/src/main/resources/Java/pojo.mustache b/openapi-generator/src/main/resources/Java/pojo.mustache index 426c59c..94a1074 100644 --- a/openapi-generator/src/main/resources/Java/pojo.mustache +++ b/openapi-generator/src/main/resources/Java/pojo.mustache @@ -78,6 +78,12 @@ public class {{classname}}{{#vendorExtensions.x-has-generic-type}}{{{vendorExten {{/isContainer}} {{/isXmlAttribute}} {{/withXml}} + {{#vendorExtensions.x-has-static-values}} + // Possible values for {{name}} property: + {{/vendorExtensions.x-has-static-values}} + {{#vendorExtensions.x-static-values}} + public static String {{title}} = "{{value}}"; + {{/vendorExtensions.x-static-values}} {{#gson}} public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}"; @SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}}) diff --git a/openapi-generator/src/main/resources/csharp/modelGeneric.mustache b/openapi-generator/src/main/resources/csharp/modelGeneric.mustache index 44f19c7..b46c95a 100644 --- a/openapi-generator/src/main/resources/csharp/modelGeneric.mustache +++ b/openapi-generator/src/main/resources/csharp/modelGeneric.mustache @@ -61,13 +61,13 @@ {{^isInherited}} {{^isReadOnly}} {{#required}} - // to ensure "{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}" is required (not null) - {{^isEnum}} + {{^vendorExtensions.x-has-static-values}}// to ensure "{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}" is required (not null){{/vendorExtensions.x-has-static-values}} + {{^isEnum}}{{^vendorExtensions.x-has-static-values}} if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} == null) { throw new InvalidDataException("{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} is a required property for {{classname}} and cannot be null"); } - {{/isEnum}} + {{/vendorExtensions.x-has-static-values}}{{/isEnum}} this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{/required}} {{/isReadOnly}} @@ -99,6 +99,13 @@ this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{#vars}} {{^isInherited}} {{^isEnum}} + {{#vendorExtensions.x-has-static-values}} + // Possible values for {{name}} property: + {{#vendorExtensions.x-static-values}} + public const string {{title}} = "{{value}}"; + {{/vendorExtensions.x-static-values}} + + {{/vendorExtensions.x-has-static-values}} /// /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} /// {{#description}}