diff --git a/CHANGELOG.md b/CHANGELOG.md index 4051ebc4271..ddfaa6c48ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Fix #5423: OkHttpClientImpl supports setting request method for empty payload requests #### Improvements +* Fix #5432: [java-generator] Add the possibility to always emit `additionalProperties` on generated POJOs * Fix #5368: added support for additional ListOptions fields * Fix #5377: added a createOr and unlock function to provide a straight-forward replacement for createOrReplace. * Fix #5388: [crd-generator] Generate deterministic CRDs diff --git a/doc/java-generation-from-CRD.md b/doc/java-generation-from-CRD.md index eb27293854c..ec98f90f6a4 100644 --- a/doc/java-generation-from-CRD.md +++ b/doc/java-generation-from-CRD.md @@ -88,6 +88,9 @@ Usage: java-gen [-hV] [-add-extra-annotations] [-enum-uppercase] -add-extra-annotations, --add-extra-annotations Add extra lombok and sundrio annotation to the generated classes + -always-preserve-unknown, --always-preserve-unknown + Always preserve unknown fields in the generated + classes -deserialization-datetime-format, --deserialization-datetime-format= DateTime format used for Deserialization of fields of @@ -117,6 +120,10 @@ Usage: java-gen [-hV] [-add-extra-annotations] [-enum-uppercase] And the corresponding configurations of the Maven plugin are (output of `mvn help:describe -DgroupId=io.fabric8 -DartifactId=java-generator-maven-plugin -Dversion= -Ddetail`): ``` + alwaysPreserveUnknown + User property: fabric8.java-generator.always-preserve-unknown + Always inject additional properties in the generated classes + datetimeDeserializationFormat User property: fabric8.java-generator.datetime-deserialization-format DateTime format used for Deserialization of fields of type `date-time` diff --git a/java-generator/cli/src/main/java/io/fabric8/java/generator/cli/GenerateJavaSources.java b/java-generator/cli/src/main/java/io/fabric8/java/generator/cli/GenerateJavaSources.java index a0de34bfa91..e12a9452636 100644 --- a/java-generator/cli/src/main/java/io/fabric8/java/generator/cli/GenerateJavaSources.java +++ b/java-generator/cli/src/main/java/io/fabric8/java/generator/cli/GenerateJavaSources.java @@ -63,6 +63,10 @@ public class GenerateJavaSources implements Runnable { "--skip-generated-annotations" }, description = "Skip emitting the @javax.annotation.processing.Generated annotation on the generated sources", required = false, hidden = true) Boolean skipGeneratedAnnotations = null; + @Option(names = { "-always-preserve-unknown", + "--always-preserve-unknown" }, description = "Always preserve unknown fields in the generated classes", required = false, hidden = false) + Boolean alwaysPreserveUnkown = null; + @Option(names = { "-package-overrides", "--package-overrides" }, description = "Apply the overrides to the package names", required = false) Map packageOverrides = null; @@ -86,6 +90,7 @@ public void run() { uppercaseEnum, addExtraAnnotations, !noGeneratedAnnotations, + alwaysPreserveUnkown, packageOverrides, filesSuffixes, serializationDateTimeFormat, diff --git a/java-generator/core/src/main/java/io/fabric8/java/generator/Config.java b/java-generator/core/src/main/java/io/fabric8/java/generator/Config.java index 165079a568a..e545320e7aa 100644 --- a/java-generator/core/src/main/java/io/fabric8/java/generator/Config.java +++ b/java-generator/core/src/main/java/io/fabric8/java/generator/Config.java @@ -29,6 +29,7 @@ public class Config { public static final boolean DEFAULT_UPPERCASE_ENUM = true; public static final boolean DEFAULT_ADD_EXTRA_ANNOTATIONS = false; public static final boolean DEFAULT_ADD_GENERATED_ANNOTATIONS = true; + public static final boolean DEFAULT_ALWAYS_PRESERVE_UNKNOWN = false; public static final Map DEFAULT_PACKAGE_OVERRIDES = new HashMap<>(); public static final List DEFAULT_FILES_SUFFIXES = Arrays.asList(".yaml", ".yml", ".json"); // RFC 3339 - from: https://swagger.io/docs/specification/data-models/data-types/ @@ -38,6 +39,7 @@ public class Config { private Boolean uppercaseEnums = DEFAULT_UPPERCASE_ENUM; private Boolean objectExtraAnnotations = DEFAULT_ADD_EXTRA_ANNOTATIONS; private Boolean generatedAnnotations = DEFAULT_ADD_GENERATED_ANNOTATIONS; + private Boolean alwaysPreserveUnknown = DEFAULT_ALWAYS_PRESERVE_UNKNOWN; private Map packageOverrides = DEFAULT_PACKAGE_OVERRIDES; private List filesSuffixes = DEFAULT_FILES_SUFFIXES; private String serDatetimeFormat = DEFAULT_SER_DATETIME_FORMAT; @@ -116,6 +118,41 @@ public Config( } } + public Config( + Boolean uppercaseEnums, + Boolean objectExtraAnnotations, + Boolean generatedAnnotations, + Boolean alwaysPreserveUnknown, + Map packageOverrides, + List filesSuffixes, + String serDatetimeFormat, + String deserDatetimeFormat) { + if (uppercaseEnums != null) { + this.uppercaseEnums = uppercaseEnums; + } + if (objectExtraAnnotations != null) { + this.objectExtraAnnotations = objectExtraAnnotations; + } + if (generatedAnnotations != null) { + this.generatedAnnotations = generatedAnnotations; + } + if (alwaysPreserveUnknown != null) { + this.alwaysPreserveUnknown = alwaysPreserveUnknown; + } + if (packageOverrides != null) { + this.packageOverrides = packageOverrides; + } + if (filesSuffixes != null) { + this.filesSuffixes = filesSuffixes; + } + if (serDatetimeFormat != null) { + this.serDatetimeFormat = serDatetimeFormat; + } + if (deserDatetimeFormat != null) { + this.deserDatetimeFormat = deserDatetimeFormat; + } + } + public boolean isUppercaseEnums() { return (uppercaseEnums == null) ? DEFAULT_UPPERCASE_ENUM : uppercaseEnums; } @@ -132,6 +169,12 @@ public boolean isGeneratedAnnotations() { : generatedAnnotations; } + public boolean isAlwaysPreserveUnknown() { + return (alwaysPreserveUnknown == null) + ? DEFAULT_ALWAYS_PRESERVE_UNKNOWN + : alwaysPreserveUnknown; + } + public Map getPackageOverrides() { return (packageOverrides == null || packageOverrides.isEmpty()) ? DEFAULT_PACKAGE_OVERRIDES 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 ca8127a986e..5910e4ce9bd 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 @@ -307,7 +307,7 @@ public GeneratorResult generateJava() { } } - if (this.preserveUnknownFields) { + if (this.preserveUnknownFields || config.isAlwaysPreserveUnknown()) { ClassOrInterfaceType mapType = new ClassOrInterfaceType() .setName(Keywords.JAVA_UTIL_MAP) .setTypeArguments( diff --git a/java-generator/core/src/test/java/io/fabric8/java/generator/ConfigTest.java b/java-generator/core/src/test/java/io/fabric8/java/generator/ConfigTest.java index be4eb6b6b8a..05a9ba3b59b 100644 --- a/java-generator/core/src/test/java/io/fabric8/java/generator/ConfigTest.java +++ b/java-generator/core/src/test/java/io/fabric8/java/generator/ConfigTest.java @@ -23,11 +23,12 @@ class ConfigTest { @Test void defaultValuesWithAllArgsConstructor() { - final Config result = new Config(null, null, null, null, null, null, null); + final Config result = new Config(null, null, null, null, null, null, null, null); assertThat(result) .returns(Config.DEFAULT_UPPERCASE_ENUM, Config::isUppercaseEnums) .returns(Config.DEFAULT_ADD_EXTRA_ANNOTATIONS, Config::isObjectExtraAnnotations) .returns(Config.DEFAULT_ADD_GENERATED_ANNOTATIONS, Config::isGeneratedAnnotations) + .returns(Config.DEFAULT_ALWAYS_PRESERVE_UNKNOWN, Config::isAlwaysPreserveUnknown) .returns(Config.DEFAULT_PACKAGE_OVERRIDES, Config::getPackageOverrides) .returns(Config.DEFAULT_FILES_SUFFIXES, Config::getFilesSuffixes) .returns(Config.DEFAULT_SER_DATETIME_FORMAT, Config::getSerDatetimeFormat) @@ -41,6 +42,7 @@ void defaultValuesWithNoArgsConstructor() { .returns(Config.DEFAULT_UPPERCASE_ENUM, Config::isUppercaseEnums) .returns(Config.DEFAULT_ADD_EXTRA_ANNOTATIONS, Config::isObjectExtraAnnotations) .returns(Config.DEFAULT_ADD_GENERATED_ANNOTATIONS, Config::isGeneratedAnnotations) + .returns(Config.DEFAULT_ALWAYS_PRESERVE_UNKNOWN, Config::isAlwaysPreserveUnknown) .returns(Config.DEFAULT_PACKAGE_OVERRIDES, Config::getPackageOverrides) .returns(Config.DEFAULT_FILES_SUFFIXES, Config::getFilesSuffixes) .returns(Config.DEFAULT_SER_DATETIME_FORMAT, Config::getSerDatetimeFormat) @@ -54,6 +56,7 @@ void defaultValuesWithBuilder() { .returns(Config.DEFAULT_UPPERCASE_ENUM, Config::isUppercaseEnums) .returns(Config.DEFAULT_ADD_EXTRA_ANNOTATIONS, Config::isObjectExtraAnnotations) .returns(Config.DEFAULT_ADD_GENERATED_ANNOTATIONS, Config::isGeneratedAnnotations) + .returns(Config.DEFAULT_ALWAYS_PRESERVE_UNKNOWN, Config::isAlwaysPreserveUnknown) .returns(Config.DEFAULT_PACKAGE_OVERRIDES, Config::getPackageOverrides) .returns(Config.DEFAULT_FILES_SUFFIXES, Config::getFilesSuffixes) .returns(Config.DEFAULT_SER_DATETIME_FORMAT, Config::getSerDatetimeFormat) 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 89f435d2bde..7fd026f5c35 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 @@ -613,6 +613,33 @@ void testObjectWithPreservedFields() { assertTrue(clzT.get().getFieldByName("additionalProperties").isPresent()); } + @Test + void testConfigToGeneratePreservedUnknownFields() { + // Arrange + Config config = new Config(null, null, null, true, new HashMap<>(), new ArrayList<>(), null, null); + JObject obj = new JObject( + null, + "t", + null, + null, + false, + config, + null, + Boolean.FALSE, + null); + + // Act + GeneratorResult res = obj.generateJava(); + + // Assert + assertEquals(1, res.getTopLevelClasses().size()); + assertEquals("T", res.getTopLevelClasses().get(0).getName()); + + Optional clzT = res.getTopLevelClasses().get(0).getClassByName("T"); + assertTrue(clzT.isPresent()); + assertTrue(clzT.get().getFieldByName("additionalProperties").isPresent()); + } + @Test void testObjectWithSpecialFieldNames() { // Arrange diff --git a/java-generator/gradle-plugin/src/main/java/io/fabric8/java/generator/gradle/plugin/JavaGeneratorPluginExtension.java b/java-generator/gradle-plugin/src/main/java/io/fabric8/java/generator/gradle/plugin/JavaGeneratorPluginExtension.java index 09443a35961..c3b11042381 100644 --- a/java-generator/gradle-plugin/src/main/java/io/fabric8/java/generator/gradle/plugin/JavaGeneratorPluginExtension.java +++ b/java-generator/gradle-plugin/src/main/java/io/fabric8/java/generator/gradle/plugin/JavaGeneratorPluginExtension.java @@ -100,6 +100,7 @@ public void setEnumUppercase(final Boolean isEnumUppercase) { javaGeneratorConfig = new Config(isEnumUppercase, javaGeneratorConfig.isObjectExtraAnnotations(), javaGeneratorConfig.isGeneratedAnnotations(), + javaGeneratorConfig.isAlwaysPreserveUnknown(), javaGeneratorConfig.getPackageOverrides(), javaGeneratorConfig.getFilesSuffixes(), javaGeneratorConfig.getSerDatetimeFormat(), @@ -118,6 +119,7 @@ public void setExtraAnnotations(final Boolean isExtraAnnotations) { javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), isExtraAnnotations, javaGeneratorConfig.isGeneratedAnnotations(), + javaGeneratorConfig.isAlwaysPreserveUnknown(), javaGeneratorConfig.getPackageOverrides(), javaGeneratorConfig.getFilesSuffixes(), javaGeneratorConfig.getSerDatetimeFormat(), @@ -136,12 +138,32 @@ public void setGeneratedAnnotations(final Boolean isGeneratedAnnotations) { javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), javaGeneratorConfig.isObjectExtraAnnotations(), isGeneratedAnnotations, + javaGeneratorConfig.isAlwaysPreserveUnknown(), javaGeneratorConfig.getPackageOverrides(), javaGeneratorConfig.getFilesSuffixes(), javaGeneratorConfig.getSerDatetimeFormat(), javaGeneratorConfig.getDeserDatetimeFormat()); } + /** + * Emit the @javax.annotation.processing.Generated annotation on the generated sources + * + */ + public Boolean getAlwaysPreserveUnknown() { + return javaGeneratorConfig.isAlwaysPreserveUnknown(); + } + + public void setAlwaysPreserveUnknown(final Boolean isAlwaysPreserveUnknown) { + javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), + javaGeneratorConfig.isObjectExtraAnnotations(), + javaGeneratorConfig.isGeneratedAnnotations(), + isAlwaysPreserveUnknown, + javaGeneratorConfig.getPackageOverrides(), + javaGeneratorConfig.getFilesSuffixes(), + javaGeneratorConfig.getSerDatetimeFormat(), + javaGeneratorConfig.getDeserDatetimeFormat()); + } + /** * Package names to be substituted * @@ -154,6 +176,7 @@ public void setPackageOverrides(final Map packageOverrides) { javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), javaGeneratorConfig.isObjectExtraAnnotations(), javaGeneratorConfig.isGeneratedAnnotations(), + javaGeneratorConfig.isAlwaysPreserveUnknown(), packageOverrides, javaGeneratorConfig.getFilesSuffixes(), javaGeneratorConfig.getSerDatetimeFormat(), @@ -172,6 +195,7 @@ public void setPackageOverrides(final List filesSuffixes) { javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), javaGeneratorConfig.isObjectExtraAnnotations(), javaGeneratorConfig.isGeneratedAnnotations(), + javaGeneratorConfig.isAlwaysPreserveUnknown(), javaGeneratorConfig.getPackageOverrides(), filesSuffixes, javaGeneratorConfig.getSerDatetimeFormat(), @@ -190,6 +214,7 @@ public void setSerializationDatetimeFormat(final String serDatetimeFmt) { javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), javaGeneratorConfig.isObjectExtraAnnotations(), javaGeneratorConfig.isGeneratedAnnotations(), + javaGeneratorConfig.isAlwaysPreserveUnknown(), javaGeneratorConfig.getPackageOverrides(), javaGeneratorConfig.getFilesSuffixes(), serDatetimeFmt, @@ -208,6 +233,7 @@ public void setDeserializationDatetimeFormat(final String deserDatetimeFmt) { javaGeneratorConfig = new Config(javaGeneratorConfig.isUppercaseEnums(), javaGeneratorConfig.isObjectExtraAnnotations(), javaGeneratorConfig.isGeneratedAnnotations(), + javaGeneratorConfig.isAlwaysPreserveUnknown(), javaGeneratorConfig.getPackageOverrides(), javaGeneratorConfig.getFilesSuffixes(), javaGeneratorConfig.getSerDatetimeFormat(), diff --git a/java-generator/it/src/it/preserve-unknown-objects-through-config/invoker.properties b/java-generator/it/src/it/preserve-unknown-objects-through-config/invoker.properties new file mode 100644 index 00000000000..9135f207843 --- /dev/null +++ b/java-generator/it/src/it/preserve-unknown-objects-through-config/invoker.properties @@ -0,0 +1,17 @@ +# +# 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. +# + +invoker.goals=test diff --git a/java-generator/it/src/it/preserve-unknown-objects-through-config/pom.xml b/java-generator/it/src/it/preserve-unknown-objects-through-config/pom.xml new file mode 100644 index 00000000000..f1faaa891f6 --- /dev/null +++ b/java-generator/it/src/it/preserve-unknown-objects-through-config/pom.xml @@ -0,0 +1,89 @@ + + + + + 4.0.0 + + preserve-unknown-objects + io.fabric8.it + 0.0-SNAPSHOT + jar + + + @maven.compiler.source@ + @maven.compiler.target@ + + + + + io.fabric8 + java-generator-integration-tests + @project.version@ + + + io.fabric8 + generator-annotations + @project.version@ + + + org.junit.jupiter + junit-jupiter-api + @junit.version@ + test + + + org.junit.jupiter + junit-jupiter-engine + @junit.version@ + test + + + + + + + io.fabric8 + java-generator-maven-plugin + @project.version@ + + + + generate + + + + + src/test/resources/dapr-components-crd.yaml + false + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + false + false + + + + + + diff --git a/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/java/io/fabric8/it/certmanager/TestPreserveUnkonwnUsabilityFromConfig.java b/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/java/io/fabric8/it/certmanager/TestPreserveUnkonwnUsabilityFromConfig.java new file mode 100644 index 00000000000..d7acfd82e0f --- /dev/null +++ b/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/java/io/fabric8/it/certmanager/TestPreserveUnkonwnUsabilityFromConfig.java @@ -0,0 +1,107 @@ +/** + * 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. + */ +package io.fabric8.it.certmanager; + +import com.fasterxml.jackson.databind.JsonNode; +import io.dapr.v1alpha1.Component; +import io.dapr.v1alpha1.ComponentSpec; +import io.dapr.v1alpha1.componentspec.Metadata; +import io.fabric8.kubernetes.api.model.AnyType; +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.client.utils.Serialization; +import org.junit.jupiter.api.Test; +import io.fabric8.java.generator.testing.KubernetesResourceDiff; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TestPreserveUnknownUsabilityFromConfig { + + @Test + void testDeserialization() { + // Arrange + Component sample = + Serialization.unmarshal(getClass().getResourceAsStream("/sample.yaml"), Component.class); + + // Act + List metadataList = sample.getSpec().getMetadata(); + + // Assert + assertEquals(5, metadataList.size()); + } + + private Component createSampleComponent() throws Exception { + Component component = new Component(); + ComponentSpec spec = new ComponentSpec(); + spec.setType("pubsub.mqtt"); + spec.setVersion("v1"); + + Metadata meta1 = new Metadata(); + meta1.setAdditionalProperty("consumerID", new AnyType("{uuid}")); + + Metadata meta2 = new Metadata(); + meta2.setAdditionalProperty("url", new AnyType("tcp://admin:public@localhost:1883")); + + Metadata meta3 = new Metadata(); + meta3.setAdditionalProperty("qos", new AnyType(1)); + + Metadata meta4 = new Metadata(); + meta4.setAdditionalProperty("anArray", new AnyType(new int[]{1, 2, 3})); + + Metadata meta5 = new Metadata(); + Map obj = new HashMap(); + obj.put("ONE", 1); + obj.put("TWO", 2); + meta5.setAdditionalProperty("anObject", new AnyType(obj)); + + List lst = new ArrayList(); + lst.add(meta1); + lst.add(meta2); + lst.add(meta3); + lst.add(meta4); + lst.add(meta5); + spec.setMetadata(lst); + + component.setSpec(spec); + ObjectMeta om = new ObjectMeta(); + om.setName("messagebus"); + component.setMetadata(om); + + return component; + } + + @Test + void testAgainstSample() throws Exception { + // Arrange + Path resPath = Paths.get(getClass().getResource("/sample.yaml").toURI()); + String yamlContent = new String(Files.readAllBytes(resPath), "UTF8"); + Component sample = createSampleComponent(); + KubernetesResourceDiff diff = new KubernetesResourceDiff(yamlContent, Serialization.asYaml(sample)); + + // Act + List aggregatedDiffs = diff.getListOfDiffs(); + + // Assert + assertEquals(0, aggregatedDiffs.size()); + } +} diff --git a/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/resources/dapr-components-crd.yaml b/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/resources/dapr-components-crd.yaml new file mode 100644 index 00000000000..68ca245f97c --- /dev/null +++ b/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/resources/dapr-components-crd.yaml @@ -0,0 +1,105 @@ +# +# 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: components.dapr.io +spec: + group: dapr.io + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Component describes an Dapr component type + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + auth: + description: Auth represents authentication details for the component + properties: + secretStore: + type: string + required: + - secretStore + type: object + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + scopes: + items: + type: string + type: array + spec: + description: ComponentSpec is the spec for a component + properties: + initTimeout: + type: string + ignoreErrors: + type: boolean + metadata: + items: + description: MetadataItem is a name/value pair for a metadata + properties: + name: + type: string + secretKeyRef: + description: SecretKeyRef is a reference to a secret holding + the value for the metadata item. Name is the secret name, + and key is the field in the secret. + properties: + key: + type: string + name: + type: string + required: + - key + - name + type: object + # intentionally left out + # value: + # x-kubernetes-preserve-unknown-fields: true + required: + - name + type: object + type: array + type: + type: string + version: + type: string + required: + - metadata + - type + - version + type: object + type: object + served: true + storage: true + names: + kind: Component + plural: components + singular: component + categories: + - all + - dapr + scope: Namespaced diff --git a/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/resources/sample.yaml b/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/resources/sample.yaml new file mode 100644 index 00000000000..e6cd487c2e0 --- /dev/null +++ b/java-generator/it/src/it/preserve-unknown-objects-through-config/src/test/resources/sample.yaml @@ -0,0 +1,34 @@ +# +# 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: dapr.io/v1alpha1 +kind: Component +metadata: + name: messagebus +spec: + type: pubsub.mqtt + version: v1 + metadata: + - consumerID: "{uuid}" + - url: "tcp://admin:public@localhost:1883" + - qos: 1 + - anArray: + - 1 + - 2 + - 3 + - anObject: + ONE: 1 + TWO: 2 diff --git a/java-generator/maven-plugin/src/main/java/io/fabric8/java/generator/maven/plugin/JavaGeneratorMojo.java b/java-generator/maven-plugin/src/main/java/io/fabric8/java/generator/maven/plugin/JavaGeneratorMojo.java index e160b62d0c3..4cdbe078f54 100644 --- a/java-generator/maven-plugin/src/main/java/io/fabric8/java/generator/maven/plugin/JavaGeneratorMojo.java +++ b/java-generator/maven-plugin/src/main/java/io/fabric8/java/generator/maven/plugin/JavaGeneratorMojo.java @@ -87,6 +87,13 @@ public class JavaGeneratorMojo extends AbstractMojo { @Parameter(property = "fabric8.java-generator.generated-annotations", required = false) Boolean generatedAnnotations = null; + /** + * Always inject additional properties in the generated classes + * + */ + @Parameter(property = "fabric8.java-generator.always-preserve-unknown", required = false) + Boolean alwaysPreserveUnknown = null; + /** * Package names to be substituted * @@ -121,6 +128,7 @@ public void execute() throws MojoExecutionException { .uppercaseEnums(enumUppercase) .objectExtraAnnotations(extraAnnotations) .generatedAnnotations(generatedAnnotations) + .alwaysPreserveUnknown(alwaysPreserveUnknown) .packageOverrides(packageOverrides) .filesSuffixes(filesSuffixes) .serDatetimeFormat(datetimeSerializationFormat)