Skip to content

[JAVA] Correct generation of schema default values of type object #21278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 25, 2025

Conversation

DavidGrath
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

#21051
@martin-mfg , please help review

I think I've covered all the proper schema sub-types, here's what a newly generated sample looks like:

public class Test {
  public static final String SERIALIZED_NAME_TEST_EMPTY_INLINE_OBJECT = "testEmptyInlineObject";
  @SerializedName(SERIALIZED_NAME_TEST_EMPTY_INLINE_OBJECT)
  @javax.annotation.Nullable
  private Object testEmptyInlineObject = new Object();

  public static final String SERIALIZED_NAME_TEST_COMPLEX_INLINE_OBJECT = "testComplexInlineObject";
  @SerializedName(SERIALIZED_NAME_TEST_COMPLEX_INLINE_OBJECT)
  @javax.annotation.Nullable
  private TestTestComplexInlineObject testComplexInlineObject = new TestTestComplexInlineObject().foo("bar").fooInt(28).fooLong(5000000000l).fooBool(true).fooFloat(32.5f).fooDouble(3332.555d).fooNumber(new java.math.BigDecimal("120.6")).fooDateTime(java.time.OffsetDateTime.parse("2000-01-01T20:20:20+00:00", java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(java.time.ZoneId.systemDefault()))).fooUUID(java.util.UUID.fromString("a0ed70ec-5fe5-415a-be97-a7bf13db9fb6"))._void("empty");

  public static final String SERIALIZED_NAME_TEST_NULLABLE_EMPTY_INLINE_OBJECT = "testNullableEmptyInlineObject";
  @SerializedName(SERIALIZED_NAME_TEST_NULLABLE_EMPTY_INLINE_OBJECT)
  @javax.annotation.Nullable
  private Object testNullableEmptyInlineObject = new Object();

  public static final String SERIALIZED_NAME_TEST_NULLABLE_COMPLEX_INLINE_OBJECT = "testNullableComplexInlineObject";
  @SerializedName(SERIALIZED_NAME_TEST_NULLABLE_COMPLEX_INLINE_OBJECT)
  @javax.annotation.Nullable
  private TestTestNullableComplexInlineObject testNullableComplexInlineObject = new TestTestNullableComplexInlineObject().foo("bar");

  public static final String SERIALIZED_NAME_TEST_EMPTY_REFERENCE = "testEmptyReference";
  @SerializedName(SERIALIZED_NAME_TEST_EMPTY_REFERENCE)
  @javax.annotation.Nullable
  private Object testEmptyReference = new Object();

  public static final String SERIALIZED_NAME_TEST_COMPLEX_REFERENCE = "testComplexReference";
  @SerializedName(SERIALIZED_NAME_TEST_COMPLEX_REFERENCE)
  @javax.annotation.Nullable
  private ComplexReferenceObject testComplexReference = new ComplexReferenceObject().foo("bar");

  public static final String SERIALIZED_NAME_TEST_NULLABLE_EMPTY_REFERENCE = "testNullableEmptyReference";
  @SerializedName(SERIALIZED_NAME_TEST_NULLABLE_EMPTY_REFERENCE)
  @javax.annotation.Nullable
  private Object testNullableEmptyReference = new Object();

  public static final String SERIALIZED_NAME_TEST_NULLABLE_COMPLEX_REFERENCE = "testNullableComplexReference";
  @SerializedName(SERIALIZED_NAME_TEST_NULLABLE_COMPLEX_REFERENCE)
  @javax.annotation.Nullable
  private NullableComplexReferenceObject testNullableComplexReference = new NullableComplexReferenceObject().foo("bar");
...
}

This is probably a non-issue, but testComplexInlineObject has a very long line, do you have any ideas on how I can break it apart neatly, or should I leave it as-is?

@DavidGrath
Copy link
Contributor Author

Oh, yeah, I suspected and confirmed that the same thing happens in Kotlin, should I modify AbstractKotlinCodegen in a similar way and make a separate PR for that?

@DavidGrath DavidGrath changed the title Fix Issue #21051 [JAVA] Correct generation of schema default values of type object (issue #21051) May 18, 2025
@DavidGrath
Copy link
Contributor Author

My bad. Forgot to update the test case, too

@wing328 wing328 merged commit c6a88ea into OpenAPITools:master May 25, 2025
14 checks passed
@wing328 wing328 changed the title [JAVA] Correct generation of schema default values of type object (issue #21051) [JAVA] Correct generation of schema default values of type object May 25, 2025
@wing328 wing328 added this to the 7.14.0 milestone May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants