Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -4,7 +4,7 @@
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, {{{.}}}> additionalProperties;
private {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand All @@ -27,7 +27,7 @@
* @return the additional (undeclared) properties
*/
@com.fasterxml.jackson.annotation.JsonAnyGetter
public Map<String, {{{.}}}> getAdditionalProperties() {
public {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> getAdditionalProperties() {
return additionalProperties;
}

Expand All @@ -36,7 +36,7 @@
* @param key the name of the property
* @return the additional (undeclared) property with the specified name
*/
public {{{.}}} getAdditionalProperty(String key) {
public {{#useJspecify}}{{#lambda.jSpecifyNullable}}@{{javaxPackage}}.annotation.Nullable {{/lambda.jSpecifyNullable}}{{/useJspecify}}{{#lambda.jSpecifyDatatype}}{{{.}}}{{/lambda.jSpecifyDatatype}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@Override
public boolean equals(Object o) {
public boolean equals({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
{{#useReflectionEqualsHashCode}}
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
{{/useReflectionEqualsHashCode}}
Expand Down Expand Up @@ -62,6 +62,6 @@
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private static String toIndentedString(Object o) {
private static String toIndentedString({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, {{{.}}}> additionalProperties;
private {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand All @@ -27,7 +27,7 @@
* @return the additional (undeclared) properties
*/
@JsonAnyGetter
public Map<String, {{{.}}}> getAdditionalProperties() {
public {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> getAdditionalProperties() {
return additionalProperties;
}

Expand All @@ -36,7 +36,7 @@
* @param key the name of the property
* @return the additional (undeclared) property with the specified name
*/
public {{{.}}} getAdditionalProperty(String key) {
public {{#useJspecify}}{{#lambda.jSpecifyNullable}}@{{javaxPackage}}.annotation.Nullable {{/lambda.jSpecifyNullable}}{{/useJspecify}}{{#lambda.jSpecifyDatatype}}{{{.}}}{{/lambda.jSpecifyDatatype}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
* Return true if this {{name}} object is equal to o.
*/
@Override
public boolean equals(Object o) {
public boolean equals({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
{{#useReflectionEqualsHashCode}}
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
{{/useReflectionEqualsHashCode}}
Expand Down Expand Up @@ -341,7 +341,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
private String toIndentedString({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
{{#supportUrlQuery}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, {{{.}}}> additionalProperties;
private {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand All @@ -27,7 +27,7 @@
* @return the additional (undeclared) properties
*/
@JsonAnyGetter
public Map<String, {{{.}}}> getAdditionalProperties() {
public {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> getAdditionalProperties() {
return additionalProperties;
}

Expand All @@ -36,7 +36,7 @@
* @param key the name of the property
* @return the additional (undeclared) property with the specified name
*/
public {{{.}}} getAdditionalProperty(String key) {
public {{#useJspecify}}{{#lambda.jSpecifyNullable}}@{{javaxPackage}}.annotation.Nullable {{/lambda.jSpecifyNullable}}{{/useJspecify}}{{#lambda.jSpecifyDatatype}}{{{.}}}{{/lambda.jSpecifyDatatype}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
{{/readWriteVars}}
{{/parent}}
@Override
public boolean equals(Object o) {
public boolean equals({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
{{#useReflectionEqualsHashCode}}
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
{{/useReflectionEqualsHashCode}}
Expand Down Expand Up @@ -363,7 +363,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private{{#jsonb}} static{{/jsonb}} String toIndentedString(Object o) {
private{{#jsonb}} static{{/jsonb}} String toIndentedString({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
{{#supportUrlQuery}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, {{{.}}}> additionalProperties;
private {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand All @@ -27,7 +27,7 @@
* @return the additional (undeclared) properties
*/
@JsonAnyGetter
public Map<String, {{{.}}}> getAdditionalProperties() {
public {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> getAdditionalProperties() {
return additionalProperties;
}

Expand All @@ -36,7 +36,7 @@
* @param key the name of the property
* @return the additional (undeclared) property with the specified name
*/
public {{{.}}} getAdditionalProperty(String key) {
public {{#useJspecify}}{{#lambda.jSpecifyNullable}}@{{javaxPackage}}.annotation.Nullable {{/lambda.jSpecifyNullable}}{{/useJspecify}}{{#lambda.jSpecifyDatatype}}{{{.}}}{{/lambda.jSpecifyDatatype}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{/readWriteVars}}
{{/parent}}
@Override
public boolean equals(Object o) {
public boolean equals({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
{{#useReflectionEqualsHashCode}}
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
{{/useReflectionEqualsHashCode}}
Expand Down Expand Up @@ -363,7 +363,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private{{#jsonb}} static{{/jsonb}} String toIndentedString(Object o) {
private{{#jsonb}} static{{/jsonb}} String toIndentedString({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
{{#supportUrlQuery}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, {{{.}}}> additionalProperties;
private {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
Expand All @@ -27,7 +27,7 @@
* @return the additional (undeclared) properties
*/
@JsonAnyGetter
public Map<String, {{{.}}}> getAdditionalProperties() {
public {{#useJspecify}}@Nullable {{/useJspecify}}Map<String, {{{.}}}> getAdditionalProperties() {
return additionalProperties;
}

Expand All @@ -36,7 +36,7 @@
* @param key the name of the property
* @return the additional (undeclared) property with the specified name
*/
public {{{.}}} getAdditionalProperty(String key) {
public {{#useJspecify}}{{#lambda.jSpecifyNullable}}@{{javaxPackage}}.annotation.Nullable {{/lambda.jSpecifyNullable}}{{/useJspecify}}{{#lambda.jSpecifyDatatype}}{{{.}}}{{/lambda.jSpecifyDatatype}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
{{/readWriteVars}}
{{/parent}}
@Override
public boolean equals(Object o) {
public boolean equals({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
{{#useReflectionEqualsHashCode}}
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
{{/useReflectionEqualsHashCode}}
Expand Down Expand Up @@ -363,7 +363,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private{{#jsonb}} static{{/jsonb}} String toIndentedString(Object o) {
private{{#jsonb}} static{{/jsonb}} String toIndentedString({{#useJspecify}}@Nullable {{/useJspecify}}Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
{{#supportUrlQuery}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5362,6 +5362,47 @@ public Object[][] jspecifyLibraries() {
};
}

@DataProvider(name = "jspecifyAdditionalPropertiesLibraries")
public Object[][] jspecifyAdditionalPropertiesLibraries() {
return new Object[][]{{RESTCLIENT}, {WEBCLIENT}, {RESTTEMPLATE}, {NATIVE}, {MICROPROFILE}};
}

@Test(dataProvider = "jspecifyAdditionalPropertiesLibraries")
public void testJspecifyNullableAdditionalPropertiesAndObjectParameters(String library) {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/jspecify-additional-properties.yaml", library,
Map.of(USE_JSPECIFY, true,
CodegenConstants.SERIALIZATION_LIBRARY, "jackson",
ANNOTATION_LIBRARY, "none"),
codegenConfigurator -> codegenConfigurator.addTypeMapping("DateTime", "java.time.Instant"));

JavaFileAssert.assertThat(files.get("Extensible.java"))
.fileContains(
"import org.jspecify.annotations.Nullable;",
"private @Nullable Map<String, String> additionalProperties;",
"public @Nullable Map<String, String> getAdditionalProperties()",
"public @Nullable String getAdditionalProperty(String key)",
"public boolean equals(@Nullable Object o)",
"String toIndentedString(@Nullable Object o)");
// a qualified type takes the annotation on its simple name
JavaFileAssert.assertThat(files.get("ExtensibleWithTimestamps.java"))
.fileContains("public java.time.@Nullable Instant getAdditionalProperty(String key)");
}

@Test(dataProvider = "jspecifyAdditionalPropertiesLibraries")
public void testNullableAdditionalPropertiesOnlyWithJspecify(String library) {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/jspecify-additional-properties.yaml", library,
Map.of(CodegenConstants.SERIALIZATION_LIBRARY, "jackson",
ANNOTATION_LIBRARY, "none"));

JavaFileAssert.assertThat(files.get("Extensible.java"))
.fileContains(
"private Map<String, String> additionalProperties;",
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
"public Map<String, String> getAdditionalProperties()",
"public String getAdditionalProperty(String key)",
"public boolean equals(Object o)",
"String toIndentedString(Object o)");
}

@Test(dataProvider = "jspecifyLibraries")
public void testJspecify(String library, int springBootVersion, boolean hasJspecifyDependency) throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/jspecify.yaml", library,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.3
info:
title: jspecify additionalProperties
version: 1.0.0
paths:
/extensible:
get:
operationId: getExtensible
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Extensible'
components:
schemas:
Extensible:
type: object
properties:
name:
type: string
additionalProperties:
type: string
ExtensibleWithTimestamps:
type: object
properties:
name:
type: string
additionalProperties:
type: string
format: date-time
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public String getName() {


@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public String toString() {
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private static String toIndentedString(Object o) {
private static String toIndentedString(@Nullable Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public Foo nullableColor(@Nullable String nullableColor) {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
}

Expand Down Expand Up @@ -479,7 +479,7 @@ public String toString() {
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private static String toIndentedString(Object o) {
private static String toIndentedString(@Nullable Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public RequiredAndNullable addListItem(String _listItem) {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
}

Expand Down Expand Up @@ -221,7 +221,7 @@ public String toString() {
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private static String toIndentedString(Object o) {
private static String toIndentedString(@Nullable Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public String getName() {
* Return true if this FileContent object is equal to o.
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
}

Expand All @@ -173,7 +173,7 @@ public String toString() {
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
private String toIndentedString(@Nullable Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void setNullableColor(@Nullable String nullableColor) {
* Return true if this Foo object is equal to o.
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
}

Expand Down Expand Up @@ -485,7 +485,7 @@ public String toString() {
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
private String toIndentedString(@Nullable Object o) {
return o == null ? "null" : o.toString().replace("\n", "\n ");
}

Expand Down
Loading
Loading