Skip to content

Select the service and shapes to generate - #814

Open
jonathan343 wants to merge 3 commits into
python-codegen-modelfrom
feat/codegen-selection-arena
Open

jonathan343 wants to merge 3 commits into
python-codegen-modelfrom
feat/codegen-selection-arena

Conversation

@jonathan343

@jonathan343 jonathan343 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

This PR is stacked on #795 and targets python-codegen-model so it contains only service and shape selection. I will retarget to develop after #795 merges.

Summary

This PR adds --service to both native generator commands. An explicit ID must identify a non-mixin service; otherwise the sole non-mixin service is selected automatically. Client generation requires a service, while standalone types can operate without one.

Selection follows the service's structural relationships, including resources, operation inputs/outputs/errors, and member targets. It preserves model order, handles cyclic and deep graphs, and excludes prelude shapes, mixins, trait definitions, and service/operation/resource shapes. Without a service, conflicting case-insensitive data-shape names are reported. The CLI reports how many eligible shapes lie outside the selected service closure.

The selection API and behavior are documented in designs/codegen/selection.md.

Usage

# Automatically select the model's sole service
smithy-python generate client --model weather.json --output ./build

# Select a service explicitly when the model contains several
smithy-python generate client --model services.json \
  --service example.weather#Weather --output ./build

# Select standalone data shapes from a model without a service
smithy-python generate types --model types.json --output ./build

Both commands limit selection to the resolved service's reachable data shapes. When no service exists, types selects all eligible data shapes and rejects case-insensitive name conflicts.

When the model contains multiple non-mixin services, omitting --service fails for both commands and lists the candidates. For example:

smithy-python generate types --model services.json --output ./build
smithy-python: error: Multiple services found; select one with --service: example.weather#Weather, example.inventory#Inventory

The command exits with code 2. Pass --service example.weather#Weather to select that service's reachable data shapes.

Additional Testing

All 434 models in aws/api-models-aws passed an independent raw-AST traversal comparison: 119,385 selected shapes, exact ordering and exclusion counts, and matching explicit/automatic service selection. Both CLI artifacts were exercised for every service, totaling 868 invocations. This is local validation, not an external CI dependency.

These models contain no mixins, apply, or service renames, and each has only one service; those selection scenarios are covered by targeted tests. Additional local probes checked structural relationships, ordering, cycles, and deep graphs.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Resolve the target service and select its reachable data shapes in model order. Support standalone types with name-conflict checks, expose selection through the CLI, and report excluded shapes without claiming generation is implemented.
@jonathan343
jonathan343 requested a review from a team as a code owner September 27, 2026 06:52
@jonathan343
jonathan343 added this pull request to stack #796 September 27, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant