Skip to content

useExternalTypes setting has no effect in unified java-codegen plugin (regression from #1057) #1079

@AgentKWang

Description

@AgentKWang

Description

The useExternalTypes setting in JavaCodegenSettings is parsed and stored but never checked in the unified DirectedJavaCodegen introduced in #1057. This means setting
"useExternalTypes": true in smithy-build.json has zero effect — all structures, errors, unions, enums, lists, maps, and resources are generated unconditionally, duplicating types
that should come from an external model package.

This is a regression from the old DirectedJavaClientCodegen (removed in #1057), which guarded every shape generation method with if (!directive.settings().useExternalTypes()).

Reproduction

smithy-build.json:

{
  "version": "1.0",
  "plugins": {
    "java-codegen": {
      "service": "com.example#MyService",
      "namespace": "com.example",
      "protocol": "aws.protocols#restJson1",
      "modes": ["client"],
      "useExternalTypes": true
    }
  }
}

Expected: Only client-specific classes are generated (client interface, client implementation, operation descriptors, service exception, API service). Model types (structures,
errors, unions, enums, etc.) are not generated because they come from an external types package.

Actual: All model types are generated as if useExternalTypes were false.

Root Cause

In DirectedJavaCodegen.java, none of the shape generation methods check settings.useExternalTypes():

// Current code — no guard
@Override
public void generateStructure(GenerateStructureDirective<...> directive) {
    if (!isSynthetic(directive.shape())) {
        new StructureGenerator<>().accept(directive);  // always runs
    }
}

The old DirectedJavaClientCodegen (in codegen/client/, removed in #1057) had:

// Old code — properly guarded
@Override
public void generateStructure(GenerateStructureDirective<...> directive) {
    if (!directive.settings().useExternalTypes()) {
        new StructureGenerator<>().accept(directive);
    }
}

The useExternalTypes() getter in JavaCodegenSettings is now dead code — it has no callers.

Proposed Fix

Add !directive.settings().useExternalTypes() guards to these methods in DirectedJavaCodegen:

  • generateStructure()
  • generateError()
  • generateUnion()
  • generateList()
  • generateMap()
  • generateEnumShape()
  • generateIntEnumShape()
  • generateResource()
  • customizeBeforeIntegrations() (Schemas, SharedSerde, SchemaIndex)

The following should not be guarded:

  • generateOperation() — operation descriptors are client/server-specific and referenced by the generated client implementation
  • generateService() — client interface, client implementation, and API service must always be generated

I've verified this fix locally by patching codegen-plugin-0.0.3.jar and confirming the generated client jar matches the output of the old java-client-codegen plugin exactly.

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions