Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,36 @@ public void testJdkHttpClientWithAndWithoutParentExtension() {
.content().contains("public class AnotherChild {");
}

@Test
public void testAdditionalPropertiesFieldIsTransientForGson() {
final Path output = newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName(JAVA_GENERATOR)
// use default `okhttp-gson`
.addAdditionalProperty(CodegenConstants.API_PACKAGE, "xyz.abcdef.api")
.addAdditionalProperty(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model")
.addAdditionalProperty(CodegenConstants.INVOKER_PACKAGE, "xyz.abcdef.invoker")
.addAdditionalProperty("disallowAdditionalPropertiesIfNotPresent", "false")
.setInputSpec("src/test/resources/3_0/allOf_extension_parent.yaml")
.setOutputDir(output.toString().replace("\\", "/"));

DefaultGenerator generator = new DefaultGenerator();
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
generator.opts(configurator.toClientOptInput()).generate();

// gson's reflective adapter refuses a class with two JSON fields of one name; without
// `transient` an allOf child declares additionalProperties itself and inherits it too,
// making it undeserializable ("declares multiple JSON fields named
// 'additionalProperties'"). The bag is read and written by the model's own
// TypeAdapterFactory, never by gson reflection, so hiding the field changes nothing else.
assertThat(output.resolve("src/main/java/xyz/abcdef/model/Child.java"))
.content()
.contains("public class Child extends Person {")
.contains("private transient Map<String, Object> additionalProperties;");
assertThat(output.resolve("src/main/java/xyz/abcdef/model/Person.java"))
.content().contains("private transient Map<String, Object> additionalProperties;");
}

@Test
public void allOfWithSeveralRefsAndRefAsParentInAllOfNormalizationIsTrue() {
final Path output = newTempFolder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public void setArrayOfStrings(@javax.annotation.Nonnull List<String> arrayOfStri
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ public void setColor(@javax.annotation.Nullable String color) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ public void setRefArrayPrefixItems(@javax.annotation.Nullable List<Object> refAr
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ public void setArrayFooThree(@javax.annotation.Nullable List<Tag> arrayFooThree)
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ public void setDeclawed(@javax.annotation.Nullable Boolean declawed) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public void setName(@javax.annotation.Nullable String name) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ public void setProp1(@javax.annotation.Nullable CircularReference2 prop1) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ public void setProp1(@javax.annotation.Nullable CircularReference3 prop1) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ public void setProp1(@javax.annotation.Nullable CircularReference1 prop1) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ public void setBreed(@javax.annotation.Nullable String breed) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ public void setEvent(@javax.annotation.Nonnull FakeWebhooksSourcesDeletedPostReq
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ public void setEventId(@javax.annotation.Nonnull String eventId) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ public void setMessage(@javax.annotation.Nullable String message) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ public void setComplete(@javax.annotation.Nullable Boolean complete) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ public void setStatus(@javax.annotation.Nullable StatusEnum status) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ public void setSecondProperty(@javax.annotation.Nullable Object secondProperty)
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ public void setDummy(@javax.annotation.Nullable String dummy) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public void setArrayOfStrings(@javax.annotation.Nonnull List<String> arrayOfStri
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public void setName(@javax.annotation.Nullable String name) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,12 @@ public void setUserStatus(@javax.annotation.Nullable Integer userStatus) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public void setName(@javax.annotation.Nullable String name) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ public void setMessage(@javax.annotation.Nullable String message) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ public void setComplete(@javax.annotation.Nullable Boolean complete) {
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*
* Transient: the bag is read and written by this model's TypeAdapterFactory, and hiding
* it from gson's reflection keeps an allOf child (which also inherits the field from its
* parent) from declaring two JSON fields of one name.
*/
private Map<String, Object> additionalProperties;
private transient Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand Down
Loading
Loading