diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b31a8d56b..81ee6524036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ #### Bugs #### Improvements +* Fix #5843: Support javaType and existingJavaType extensions in java-generator #### Dependency Upgrade diff --git a/doc/java-generation-from-CRD.md b/doc/java-generation-from-CRD.md index 57eac379632..abdbf6652e5 100644 --- a/doc/java-generation-from-CRD.md +++ b/doc/java-generation-from-CRD.md @@ -174,6 +174,43 @@ And the corresponding configurations of the Maven plugin are (output of `mvn hel The URLs to be used to download CRDs from remote locations ``` +## Extension support + +The `JavaType` extension allows the fully qualified name of the generated class to be specified, +and potentially reused such as `Point` in the example snippet below. The `existingJavaType` extension +allows the generator to make use of an existing java type, such as `Affinity` in the example snippet +below. + +``` +spec: + versions: + - schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + affinity: + type: object + existingJavaType: io.fabric8.kubernetes.api.model.Affinity + properties: + ignored-by-generator: + type: object + point-A: + type: object + javaType: com.example.Point + properties: &point-properties + x-position: + type: integer + y-position: + type: integer + point-B: + type: object + existingJavaType: com.example.Point + properties: *point-properties +``` + ## Compiling the generated code The generated code depends on a few dependencies to successfully compile: diff --git a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/AbstractJSONSchema2Pojo.java b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/AbstractJSONSchema2Pojo.java index 3cb55d2be5d..3db31010a0b 100644 --- a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/AbstractJSONSchema2Pojo.java +++ b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/AbstractJSONSchema2Pojo.java @@ -294,6 +294,20 @@ private static AbstractJSONSchema2Pojo fromJsonSchema( prop.getDefault()); case OBJECT: final boolean preserveUnknownFields = Boolean.TRUE.equals(prop.getXKubernetesPreserveUnknownFields()); + // Added to support javaType and existingJavaType extensions for generating Java classes + boolean existingClass = false; + String type = null; + if (null != prop.getJavaType()) { + type = prop.getJavaType(); + } else if (null != prop.getExistingJavaType()) { + type = prop.getExistingJavaType(); + existingClass = true; + } + if (null != type) { + int index = type.lastIndexOf("."); + parentPkg = type.substring(0, Math.max(0, index)); + key = type.substring(index + 1); + } return new JObject( parentPkg, key, @@ -303,7 +317,8 @@ private static AbstractJSONSchema2Pojo fromJsonSchema( config, prop.getDescription(), isNullable, - prop.getDefault()); + prop.getDefault(), + existingClass); case ENUM: String enumType = JAVA_LANG_STRING; switch (prop.getType()) { diff --git a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java index 0bff149e7f9..7c47a82be35 100644 --- a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java +++ b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java @@ -53,6 +53,7 @@ public class JObject extends AbstractJSONSchema2Pojo implements JObjectExtraAnno private final Set deprecated = new HashSet<>(); private final boolean preserveUnknownFields; + private final boolean existingClass; // Added to support existingJavaType extensions for generating Java classes public JObject( String pkg, @@ -63,11 +64,13 @@ public JObject( Config config, String description, final boolean isNullable, - JsonNode defaultValue) { + JsonNode defaultValue, + boolean existingClass) { super(config, description, isNullable, defaultValue, null); this.required = new HashSet<>(Optional.ofNullable(required).orElse(Collections.emptyList())); this.fields = new HashMap<>(); this.preserveUnknownFields = preserveUnknownFields; + this.existingClass = existingClass; this.pkg = (pkg == null) ? "" : pkg.trim(); String pkgPrefix = (this.pkg.isEmpty()) ? this.pkg : this.pkg + "."; @@ -153,6 +156,9 @@ private String getSortedFieldsAsParam(Set list) { @Override public GeneratorResult generateJava() { + if (existingClass) { + return new GeneratorResult(Collections.emptyList()); + } CompilationUnit cu = new CompilationUnit(); if (!this.pkg.isEmpty()) { cu.setPackageDeclaration(new PackageDeclaration(new Name(this.pkg))); diff --git a/java-generator/core/src/test/java/io/fabric8/java/generator/ApprovalTest.java b/java-generator/core/src/test/java/io/fabric8/java/generator/ApprovalTest.java index da2e40e8038..489ee4f7149 100644 --- a/java-generator/core/src/test/java/io/fabric8/java/generator/ApprovalTest.java +++ b/java-generator/core/src/test/java/io/fabric8/java/generator/ApprovalTest.java @@ -44,7 +44,8 @@ private static Stream getCRDGenerationInputData() { Arguments.of("testJokeCrd", "jokerequests-crd.yml", "JokeRequest", "JokeRequestJavaCr", new Config()), Arguments.of("testAkkaMicroservicesCrd", "akka-microservices-crd.yml", "AkkaMicroservice", "AkkaMicroserviceJavaCr", new Config()), - Arguments.of("testCalicoIPPoolCrd", "calico-ippool-crd.yml", "IPPool", "CalicoIPPoolCr", new Config())); + Arguments.of("testCalicoIPPoolCrd", "calico-ippool-crd.yml", "IPPool", "CalicoIPPoolCr", new Config()), + Arguments.of("testJavaType", "java-type-crd.yml", "JavaType", "JavaTypeCr", new Config())); } @ParameterizedTest diff --git a/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java b/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java index 6c87615a55d..63008da6644 100644 --- a/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java +++ b/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java @@ -295,7 +295,8 @@ void testEmptyObject() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -318,7 +319,8 @@ void testEmptyObjectWithoutNamespace() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -345,7 +347,8 @@ void testObjectOfPrimitives() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -379,7 +382,8 @@ void testObjectWithRequiredField() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -401,7 +405,8 @@ void testObjectWithAndWithoutGeneratedAnnotation() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); Config config = new Config(null, null, false, new HashMap<>()); JObject obj2 = new JObject( "v1alpha1", @@ -412,7 +417,8 @@ void testObjectWithAndWithoutGeneratedAnnotation() { config, null, Boolean.FALSE, - null); + null, + false); String generatedAnnotationName = AbstractJSONSchema2Pojo.newGeneratedAnnotation().getNameAsString(); // Act @@ -592,7 +598,8 @@ void testArrayOfObjects() { defaultConfig, null, Boolean.FALSE, - null), + null, + false), defaultConfig, null, false, @@ -620,7 +627,8 @@ void testMapOfObjects() { defaultConfig, null, Boolean.FALSE, - null), + null, + false), defaultConfig, null, Boolean.FALSE, @@ -651,7 +659,8 @@ void testObjectOfObjects() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -681,7 +690,8 @@ void testObjectWithPreservedFields() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -708,7 +718,8 @@ void testConfigToGeneratePreservedUnknownFields() { config, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -739,7 +750,8 @@ void testObjectWithSpecialFieldNames() { defaultConfig, null, Boolean.FALSE, - null); + null, + false); // Act GeneratorResult res = obj.generateJava(); @@ -767,7 +779,7 @@ void testObjectNullableFieldsManagement() { nonNullableObj.setNullable(Boolean.FALSE); props.put("o2", nonNullableObj); - JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null); + JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null, false); // Act GeneratorResult res = obj.generateJava(); @@ -816,7 +828,7 @@ void testObjectWithAdditionalPropertiesTrue() { obj.setAdditionalProperties(new JSONSchemaPropsOrBool(true, null)); props.put("o1", obj); - JObject jobj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null); + JObject jobj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null, false); // Act GeneratorResult res = jobj.generateJava(); @@ -850,7 +862,7 @@ void testClassNamesDisambiguationWithPackageNesting() { newObj2.setProperties(obj2Props); props.put("o1", newObj1); props.put("o2", newObj2); - JObject obj = new JObject("v1alpha1", "t", props, null, false, defaultConfig, null, Boolean.FALSE, null); + JObject obj = new JObject("v1alpha1", "t", props, null, false, defaultConfig, null, Boolean.FALSE, null, false); // Act GeneratorResult res = obj.generateJava(); @@ -905,7 +917,7 @@ void testObjectDefaultFieldsManagement() { objWithoutDefaultValues.setType("object"); props.put("o2", objWithoutDefaultValues); - JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null); + JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null, false); // Act GeneratorResult res = obj.generateJava(); @@ -959,7 +971,7 @@ void testExactlyMoreThanOneDuplicatedFieldFailsWithException() { // Assert assertThrows(JavaGeneratorException.class, () -> { // Act - JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null); + JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null, false); }, "An exception is expected to be thrown when an object contains more that one duplicated field"); } @@ -978,8 +990,31 @@ void testExactlyDuplicatedFieldNotMarkedAsDeprecatedFailsWithException() { // Assert assertThrows(JavaGeneratorException.class, () -> { // Act - JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null); + JObject obj = new JObject(null, "t", props, null, false, defaultConfig, null, Boolean.FALSE, null, false); }, "An exception is expected to be thrown when an object contains one duplicated field that is not marked as deprecated"); } + + @Test + void testExistingJavaTypeObject() { + // Arrange + JObject obj = new JObject( + "v1alpha1", + "T", + null, + null, + false, + defaultConfig, + null, + Boolean.FALSE, + null, + true); + + // Act + GeneratorResult res = obj.generateJava(); + + // Assert + assertEquals("v1alpha1.T", obj.getType()); + assertEquals(0, res.getTopLevelClasses().size()); + } } diff --git a/java-generator/core/src/test/resources/io/fabric8/java/generator/approvals/ApprovalTest.generate_withValidCrd_shouldGeneratePojos.testJavaType.approved.txt b/java-generator/core/src/test/resources/io/fabric8/java/generator/approvals/ApprovalTest.generate_withValidCrd_shouldGeneratePojos.testJavaType.approved.txt new file mode 100644 index 00000000000..557c8934e17 --- /dev/null +++ b/java-generator/core/src/test/resources/io/fabric8/java/generator/approvals/ApprovalTest.generate_withValidCrd_shouldGeneratePojos.testJavaType.approved.txt @@ -0,0 +1,54 @@ +JavaTypeCr[0] = package org.test.v1; + +@io.fabric8.kubernetes.model.annotation.Version(value = "v1" , storage = true , served = true) +@io.fabric8.kubernetes.model.annotation.Group("example.com") +@io.fabric8.kubernetes.model.annotation.Plural("javatypes") +@javax.annotation.processing.Generated("io.fabric8.java.generator.CRGeneratorRunner") +public class JavaType extends io.fabric8.kubernetes.client.CustomResource implements io.fabric8.kubernetes.api.model.Namespaced { +} + +JavaTypeCr[1] = package org.test.v1; + +@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@com.fasterxml.jackson.annotation.JsonPropertyOrder({"affinity","point-A","point-B"}) +@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) +@javax.annotation.processing.Generated("io.fabric8.java.generator.CRGeneratorRunner") +public class JavaTypeSpec implements io.fabric8.kubernetes.api.model.KubernetesResource { + + @com.fasterxml.jackson.annotation.JsonProperty("affinity") + @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP) + private io.fabric8.kubernetes.api.model.Affinity affinity; + + public io.fabric8.kubernetes.api.model.Affinity getAffinity() { + return affinity; + } + + public void setAffinity(io.fabric8.kubernetes.api.model.Affinity affinity) { + this.affinity = affinity; + } + + @com.fasterxml.jackson.annotation.JsonProperty("point-A") + @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP) + private com.example.Point pointA; + + public com.example.Point getPointA() { + return pointA; + } + + public void setPointA(com.example.Point pointA) { + this.pointA = pointA; + } + + @com.fasterxml.jackson.annotation.JsonProperty("point-B") + @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP) + private com.example.Point pointB; + + public com.example.Point getPointB() { + return pointB; + } + + public void setPointB(com.example.Point pointB) { + this.pointB = pointB; + } +} + diff --git a/java-generator/core/src/test/resources/java-type-crd.yml b/java-generator/core/src/test/resources/java-type-crd.yml new file mode 100644 index 00000000000..c2415509fb9 --- /dev/null +++ b/java-generator/core/src/test/resources/java-type-crd.yml @@ -0,0 +1,55 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: java.type.example.com +spec: + scope: Namespaced + names: + plural: javatypes + kind: JavaType + group: example.com + versions: + - name: v1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + affinity: + type: object + existingJavaType: io.fabric8.kubernetes.api.model.Affinity + properties: + ignored-by-generator: + type: object + point-A: + type: object + javaType: com.example.Point + properties: &point-properties + x-position: + type: integer + y-position: + type: integer + point-B: + type: object + existingJavaType: com.example.Point + properties: *point-properties diff --git a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/JSONSchemaProps.java b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/JSONSchemaProps.java index dcf8a6ad258..25ee062cb0b 100644 --- a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/JSONSchemaProps.java +++ b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/JSONSchemaProps.java @@ -50,10 +50,12 @@ "example", "exclusiveMaximum", "exclusiveMinimum", + "existingJavaType", "externalDocs", "format", "id", "items", + "javaType", "maxItems", "maxLength", "maxProperties", @@ -136,6 +138,8 @@ public class JSONSchemaProps implements Editable , Kuber private Boolean exclusiveMaximum; @JsonProperty("exclusiveMinimum") private Boolean exclusiveMinimum; + @JsonProperty("existingJavaType") + private java.lang.String existingJavaType; @JsonProperty("externalDocs") private ExternalDocumentation externalDocs; @JsonProperty("format") @@ -144,6 +148,8 @@ public class JSONSchemaProps implements Editable , Kuber private java.lang.String id; @JsonProperty("items") private JSONSchemaPropsOrArray items; + @JsonProperty("javaType") + private java.lang.String javaType; @JsonProperty("maxItems") private Long maxItems; @JsonProperty("maxLength") @@ -210,7 +216,7 @@ public class JSONSchemaProps implements Editable , Kuber public JSONSchemaProps() { } - public JSONSchemaProps(java.lang.String $ref, java.lang.String $schema, JSONSchemaPropsOrBool additionalItems, JSONSchemaPropsOrBool additionalProperties, List allOf, List anyOf, JsonNode _default, Map definitions, Map dependencies, java.lang.String description, List _enum, JsonNode example, Boolean exclusiveMaximum, Boolean exclusiveMinimum, ExternalDocumentation externalDocs, java.lang.String format, java.lang.String id, JSONSchemaPropsOrArray items, Long maxItems, Long maxLength, Long maxProperties, Double maximum, Long minItems, Long minLength, Long minProperties, Double minimum, Double multipleOf, JSONSchemaProps not, Boolean nullable, List oneOf, java.lang.String pattern, Map patternProperties, Map properties, List required, java.lang.String title, java.lang.String type, Boolean uniqueItems, Boolean xKubernetesEmbeddedResource, Boolean xKubernetesIntOrString, List xKubernetesListMapKeys, java.lang.String xKubernetesListType, java.lang.String xKubernetesMapType, Boolean xKubernetesPreserveUnknownFields, List xKubernetesValidations) { + public JSONSchemaProps(java.lang.String $ref, java.lang.String $schema, JSONSchemaPropsOrBool additionalItems, JSONSchemaPropsOrBool additionalProperties, List allOf, List anyOf, JsonNode _default, Map definitions, Map dependencies, java.lang.String description, List _enum, JsonNode example, Boolean exclusiveMaximum, Boolean exclusiveMinimum, java.lang.String existingJavaType, ExternalDocumentation externalDocs, java.lang.String format, java.lang.String id, JSONSchemaPropsOrArray items, java.lang.String javaType, Long maxItems, Long maxLength, Long maxProperties, Double maximum, Long minItems, Long minLength, Long minProperties, Double minimum, Double multipleOf, JSONSchemaProps not, Boolean nullable, List oneOf, java.lang.String pattern, Map patternProperties, Map properties, List required, java.lang.String title, java.lang.String type, Boolean uniqueItems, Boolean xKubernetesEmbeddedResource, Boolean xKubernetesIntOrString, List xKubernetesListMapKeys, java.lang.String xKubernetesListType, java.lang.String xKubernetesMapType, Boolean xKubernetesPreserveUnknownFields, List xKubernetesValidations) { super(); this.$ref = $ref; this.$schema = $schema; @@ -226,10 +232,12 @@ public JSONSchemaProps(java.lang.String $ref, java.lang.String $schema, JSONSche this.example = example; this.exclusiveMaximum = exclusiveMaximum; this.exclusiveMinimum = exclusiveMinimum; + this.existingJavaType = existingJavaType; this.externalDocs = externalDocs; this.format = format; this.id = id; this.items = items; + this.javaType = javaType; this.maxItems = maxItems; this.maxLength = maxLength; this.maxProperties = maxProperties; @@ -398,6 +406,16 @@ public void setExclusiveMinimum(Boolean exclusiveMinimum) { this.exclusiveMinimum = exclusiveMinimum; } + @JsonProperty("existingJavaType") + public java.lang.String getExistingJavaType() { + return existingJavaType; + } + + @JsonProperty("existingJavaType") + public void setExistingJavaType(java.lang.String existingJavaType) { + this.existingJavaType = existingJavaType; + } + @JsonProperty("externalDocs") public ExternalDocumentation getExternalDocs() { return externalDocs; @@ -438,6 +456,16 @@ public void setItems(JSONSchemaPropsOrArray items) { this.items = items; } + @JsonProperty("javaType") + public java.lang.String getJavaType() { + return javaType; + } + + @JsonProperty("javaType") + public void setJavaType(java.lang.String javaType) { + this.javaType = javaType; + } + @JsonProperty("maxItems") public Long getMaxItems() { return maxItems; diff --git a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1beta1/JSONSchemaProps.java b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1beta1/JSONSchemaProps.java index 7dbf2bdedf6..2e561750a15 100644 --- a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1beta1/JSONSchemaProps.java +++ b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1beta1/JSONSchemaProps.java @@ -50,10 +50,12 @@ "example", "exclusiveMaximum", "exclusiveMinimum", + "existingJavaType", "externalDocs", "format", "id", "items", + "javaType", "maxItems", "maxLength", "maxProperties", @@ -136,6 +138,8 @@ public class JSONSchemaProps implements Editable , Kuber private Boolean exclusiveMaximum; @JsonProperty("exclusiveMinimum") private Boolean exclusiveMinimum; + @JsonProperty("existingJavaType") + private java.lang.String existingJavaType; @JsonProperty("externalDocs") private ExternalDocumentation externalDocs; @JsonProperty("format") @@ -144,6 +148,8 @@ public class JSONSchemaProps implements Editable , Kuber private java.lang.String id; @JsonProperty("items") private JSONSchemaPropsOrArray items; + @JsonProperty("javaType") + private java.lang.String javaType; @JsonProperty("maxItems") private Long maxItems; @JsonProperty("maxLength") @@ -210,7 +216,7 @@ public class JSONSchemaProps implements Editable , Kuber public JSONSchemaProps() { } - public JSONSchemaProps(java.lang.String $ref, java.lang.String $schema, JSONSchemaPropsOrBool additionalItems, JSONSchemaPropsOrBool additionalProperties, List allOf, List anyOf, JsonNode _default, Map definitions, Map dependencies, java.lang.String description, List _enum, JsonNode example, Boolean exclusiveMaximum, Boolean exclusiveMinimum, ExternalDocumentation externalDocs, java.lang.String format, java.lang.String id, JSONSchemaPropsOrArray items, Long maxItems, Long maxLength, Long maxProperties, Double maximum, Long minItems, Long minLength, Long minProperties, Double minimum, Double multipleOf, JSONSchemaProps not, Boolean nullable, List oneOf, java.lang.String pattern, Map patternProperties, Map properties, List required, java.lang.String title, java.lang.String type, Boolean uniqueItems, Boolean xKubernetesEmbeddedResource, Boolean xKubernetesIntOrString, List xKubernetesListMapKeys, java.lang.String xKubernetesListType, java.lang.String xKubernetesMapType, Boolean xKubernetesPreserveUnknownFields, List xKubernetesValidations) { + public JSONSchemaProps(java.lang.String $ref, java.lang.String $schema, JSONSchemaPropsOrBool additionalItems, JSONSchemaPropsOrBool additionalProperties, List allOf, List anyOf, JsonNode _default, Map definitions, Map dependencies, java.lang.String description, List _enum, JsonNode example, Boolean exclusiveMaximum, Boolean exclusiveMinimum, java.lang.String existingJavaType, ExternalDocumentation externalDocs, java.lang.String format, java.lang.String id, JSONSchemaPropsOrArray items, java.lang.String javaType, Long maxItems, Long maxLength, Long maxProperties, Double maximum, Long minItems, Long minLength, Long minProperties, Double minimum, Double multipleOf, JSONSchemaProps not, Boolean nullable, List oneOf, java.lang.String pattern, Map patternProperties, Map properties, List required, java.lang.String title, java.lang.String type, Boolean uniqueItems, Boolean xKubernetesEmbeddedResource, Boolean xKubernetesIntOrString, List xKubernetesListMapKeys, java.lang.String xKubernetesListType, java.lang.String xKubernetesMapType, Boolean xKubernetesPreserveUnknownFields, List xKubernetesValidations) { super(); this.$ref = $ref; this.$schema = $schema; @@ -226,10 +232,12 @@ public JSONSchemaProps(java.lang.String $ref, java.lang.String $schema, JSONSche this.example = example; this.exclusiveMaximum = exclusiveMaximum; this.exclusiveMinimum = exclusiveMinimum; + this.existingJavaType = existingJavaType; this.externalDocs = externalDocs; this.format = format; this.id = id; this.items = items; + this.javaType = javaType; this.maxItems = maxItems; this.maxLength = maxLength; this.maxProperties = maxProperties; @@ -398,6 +406,16 @@ public void setExclusiveMinimum(Boolean exclusiveMinimum) { this.exclusiveMinimum = exclusiveMinimum; } + @JsonProperty("existingJavaType") + public java.lang.String getExistingJavaType() { + return existingJavaType; + } + + @JsonProperty("existingJavaType") + public void setExistingJavaType(java.lang.String existingJavaType) { + this.existingJavaType = existingJavaType; + } + @JsonProperty("externalDocs") public ExternalDocumentation getExternalDocs() { return externalDocs; @@ -438,6 +456,16 @@ public void setItems(JSONSchemaPropsOrArray items) { this.items = items; } + @JsonProperty("javaType") + public java.lang.String getJavaType() { + return javaType; + } + + @JsonProperty("javaType") + public void setJavaType(java.lang.String javaType) { + this.javaType = javaType; + } + @JsonProperty("maxItems") public Long getMaxItems() { return maxItems; diff --git a/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/kube-schema.json b/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/kube-schema.json index e53d20fad6c..76640e22426 100644 --- a/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/kube-schema.json +++ b/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/kube-schema.json @@ -521,6 +521,9 @@ "exclusiveMinimum": { "type": "boolean" }, + "existingJavaType": { + "type": "string" + }, "externalDocs": { "$ref": "#/definitions/kubernetes_apiextensions_v1_ExternalDocumentation", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1.ExternalDocumentation" @@ -535,6 +538,9 @@ "$ref": "#/definitions/kubernetes_apiextensions_v1_JSONSchemaPropsOrArray", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaPropsOrArray" }, + "javaType": { + "type": "string" + }, "maxItems": { "type": "integer", "existingJavaType": "Long" @@ -1266,6 +1272,9 @@ "exclusiveMinimum": { "type": "boolean" }, + "existingJavaType": { + "type": "string" + }, "externalDocs": { "$ref": "#/definitions/kubernetes_apiextensions_v1beta1_ExternalDocumentation", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1beta1.ExternalDocumentation" @@ -1280,6 +1289,9 @@ "$ref": "#/definitions/kubernetes_apiextensions_v1beta1_JSONSchemaPropsOrArray", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1beta1.JSONSchemaPropsOrArray" }, + "javaType": { + "type": "string" + }, "maxItems": { "type": "integer", "existingJavaType": "Long" diff --git a/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/validation-schema.json b/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/validation-schema.json index 67a3f14c540..e2aba2a01f5 100644 --- a/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/validation-schema.json +++ b/kubernetes-model-generator/kubernetes-model-apiextensions/src/main/resources/schema/validation-schema.json @@ -521,6 +521,9 @@ "exclusiveMinimum": { "type": "boolean" }, + "existingJavaType": { + "type": "string" + }, "externalDocs": { "$ref": "#/definitions/kubernetes_apiextensions_v1_ExternalDocumentation", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1.ExternalDocumentation" @@ -535,6 +538,9 @@ "$ref": "#/definitions/kubernetes_apiextensions_v1_JSONSchemaPropsOrArray", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaPropsOrArray" }, + "javaType": { + "type": "string" + }, "maxItems": { "type": "integer", "existingJavaType": "Long" @@ -1266,6 +1272,9 @@ "exclusiveMinimum": { "type": "boolean" }, + "existingJavaType": { + "type": "string" + }, "externalDocs": { "$ref": "#/definitions/kubernetes_apiextensions_v1beta1_ExternalDocumentation", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1beta1.ExternalDocumentation" @@ -1280,6 +1289,9 @@ "$ref": "#/definitions/kubernetes_apiextensions_v1beta1_JSONSchemaPropsOrArray", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1beta1.JSONSchemaPropsOrArray" }, + "javaType": { + "type": "string" + }, "maxItems": { "type": "integer", "existingJavaType": "Long" @@ -3042,6 +3054,9 @@ "exclusiveMinimum": { "type": "boolean" }, + "existingJavaType": { + "type": "string" + }, "externalDocs": { "$ref": "#/definitions/kubernetes_apiextensions_v1beta1_ExternalDocumentation", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1beta1.ExternalDocumentation" @@ -3056,6 +3071,9 @@ "$ref": "#/definitions/kubernetes_apiextensions_v1beta1_JSONSchemaPropsOrArray", "existingJavaType": "io.fabric8.kubernetes.api.model.apiextensions.v1beta1.JSONSchemaPropsOrArray" }, + "javaType": { + "type": "string" + }, "maxItems": { "type": "integer", "existingJavaType": "Long" diff --git a/kubernetes-model-generator/pkg/schemagen/generate.go b/kubernetes-model-generator/pkg/schemagen/generate.go index fe6f00455f7..e6bddc9b7ce 100644 --- a/kubernetes-model-generator/pkg/schemagen/generate.go +++ b/kubernetes-model-generator/pkg/schemagen/generate.go @@ -497,6 +497,19 @@ func (g *schemaGenerator) getStructProperties(t reflect.Type) map[string]JSONPro props[name] = prop } } + // Added to support javaType and existingJavaType extensions for generating Java classes + if t.Name() == "JSONSchemaProps" { + extensions := [2]string{"javaType", "existingJavaType"} + for _, name := range extensions { + prop := JSONPropertyDescriptor{ + JSONDescriptor: &JSONDescriptor{ + Type: "string", + }, + } + g.addConstraints(name, name, &prop) + props[name] = prop + } + } return props }