Skip to content

fix(java): generate named Java type for unknown type aliases#13445

Merged
jsklan merged 6 commits intomainfrom
devin/1773293640-java-unknown-type-alias
Mar 17, 2026
Merged

fix(java): generate named Java type for unknown type aliases#13445
jsklan merged 6 commits intomainfrom
devin/1773293640-java-unknown-type-alias

Conversation

@jsklan
Copy link
Contributor

@jsklan jsklan commented Mar 12, 2026

Description

Linear ticket: Closes FER-8937

When an OpenAPI schema has no type and no properties (representing an "any" type), the Java SDK generator was dropping the named type definition entirely and inlining Object wherever it was referenced. This PR fixes the generator to emit a named wrapper class for unknown type aliases, consistent with how other alias types are handled.

Link to Devin Session
Requested by: @jsklan

Changes Made

Java generator (3 files)

  1. SingleTypeGenerator.javavisitAlias() now also generates a wrapper class when the alias's underlying type is unknown (value.getAliasOf().isUnknown()), not only when wrappedAliases config is enabled or the alias comes from an error declaration.
  2. PoetTypeNameMapper.javavisitNamed() no longer resolves unknown aliases to their underlying Object type. Previously all aliases were transparently resolved when wrappedAliases was false, causing the named type reference to be lost.
  3. Cli.java (SDK) — The WrappedAlias interface is now also generated when any type declaration is an alias with an unknown aliasOf, since the generated wrapper class implements this interface.

Dynamic snippet generator (1 file)

  1. DynamicTypeLiteralMapper.tsconvertNamed() now wraps the converted value in Type.of() when the alias's inner type reference is unknown, producing e.g. DocumentedUnknownType.of(new HashMap<>() {{ ... }}) instead of passing the raw HashMap directly.

Note: DynamicTypeMapper.ts was intentionally not changed. Type annotations for unknown aliases still resolve through to Object to avoid breaking generic type parameters (e.g. Map<String, Object> must not become Map<String, DocumentedUnknownType>). Only the literal value mapper wraps with .of().

  • Updated generators/java/sdk/versions.yml with changelog entry
  • Updated README.md generator (not applicable)

Testing

  • Seed tests run for java-sdk / exhaustive fixture — all 14 configs pass
  • Verified DocumentedUnknownType.java generated correctly across all configs
  • Verified ObjectWithDocumentedUnknownType.java references DocumentedUnknownType (not Object)
  • Verified snippet.json wraps unknown alias values with DocumentedUnknownType.of(...)
  • All 295 CI checks passed including java-model and java-spring seed tests

Key review points

  • WrappedAlias.java is now generated for any API that has unknown type aliases, even without wrappedAliases: true config. This is a net-new file in SDK output for affected APIs. Verify this is acceptable.
  • The Cli.java change only covers the SDK generator. Verify whether java-model and java-spring generators (which share SingleTypeGenerator and PoetTypeNameMapper via generator-utils) need a similar WrappedAlias interface generation change in their own Cli classes.
  • The generated DocumentedUnknownType.equals() does not null-guard this.value — consistent with existing AliasGenerator output but worth noting.

Open with Devin

Co-Authored-By: judah <jsklan.development@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Contributor

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

@fern-api fern-api bot changed the title fix: generate named Java type for unknown type aliases fix(java): generate named Java type for unknown type aliases Mar 12, 2026
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@jsklan jsklan marked this pull request as ready for review March 17, 2026 01:25
@claude
Copy link

claude bot commented Mar 17, 2026

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, reopen this pull request to trigger a review.

@jsklan jsklan enabled auto-merge (squash) March 17, 2026 01:25
@jsklan jsklan disabled auto-merge March 17, 2026 01:54
devin-ai-integration bot and others added 3 commits March 17, 2026 02:20
Co-Authored-By: judah <jsklan.development@gmail.com>
Co-Authored-By: judah <jsklan.development@gmail.com>
Co-Authored-By: judah <jsklan.development@gmail.com>
@jsklan jsklan merged commit e82f51a into main Mar 17, 2026
310 checks passed
@jsklan jsklan deleted the devin/1773293640-java-unknown-type-alias branch March 17, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants