Skip to content

feat: add Python types publishing workflow for type-safe API consumption#2093

Open
rainer-friederich wants to merge 4 commits intomainfrom
feat/publish-python-types
Open

feat: add Python types publishing workflow for type-safe API consumption#2093
rainer-friederich wants to merge 4 commits intomainfrom
feat/publish-python-types

Conversation

@rainer-friederich
Copy link
Copy Markdown
Contributor

Summary

  • Add docs:bundle script using existing @redocly/cli to produce a single-file openapi.json
  • Add publish-types CD workflow that triggers on GitHub releases, bundles the spec, runs datamodel-codegen to generate Pydantic v2 models, and publishes to a types-py orphan branch with version tags
  • Add Python package skeleton (clients/python/) for the spacecat-api-types package

Follows the same orphan-branch pattern as mysticat-data-service (cd.yml publish-types job). No existing code, tests, or CI workflows are modified — all changes are additive.

Why

DRS calls the SpaceCat API via spacecat_client.py (~1900 lines) with all responses typed as Dict[str, Any] — no type safety. Bugs like adobe-rnd/llmo-data-retrieval-service#1155 (sending {"prompts": prompts} instead of the raw prompts array) only surface at runtime during live onboarding. With generated Pydantic models and mypy coverage, these shape mismatches get caught at PR time instead.

This PR is the API service's contribution: publish the spec as installable Python types so DRS can consume them. The DRS side (replacing Dict[str, Any] with typed models, extending mypy scope) is tracked in adobe-rnd/llmo-data-retrieval-service#1164.

How it works

On each GitHub release (created by semantic-release):

  1. Bundle the multi-file OpenAPI spec into a single JSON
  2. Run datamodel-codegen --snake-case-field to generate Pydantic v2 models
  3. Push to types-py orphan branch + create version tag

DRS installs via:

spacecat-api-types @ git+https://github.com/adobe/spacecat-api-service.git@types-py-v1.393.0

Generated models use snake_case fields with camelCase aliases:

site.base_url          # Python access (snake_case)
Field(alias='baseURL') # Matches API response (camelCase)

Changes

File Change
package.json Add docs:bundle script
.gitignore Add docs/openapi/dist/ and generated models.py
clients/python/ New — package skeleton (pyproject.toml, init.py, README)
.github/workflows/publish-types.yaml New — CD workflow

Test plan

  • npm run docs:lint — passes
  • npm run docs:bundle — produces valid bundled openapi.json
  • datamodel-codegen on bundled spec — generates valid Python with correct field names/aliases
  • npm test — all 7005 tests pass, no regressions
  • Verify publish-types.yaml workflow runs on next release

🤖 Generated with Claude Code

Add a publish-types CD workflow that generates Pydantic v2 models from
the OpenAPI spec on each release, enabling DRS to consume type-safe
models instead of Dict[str, Any] for SpaceCat API responses.

- Add docs:bundle script to produce single-file openapi.json
- Add publish-types.yaml workflow (triggers on GitHub release)
- Add clients/python/ package skeleton for spacecat-api-types
- Uses datamodel-codegen with --snake-case-field for Pythonic access

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

This PR will trigger a minor release when merged.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Add npm ci step so npx uses the pinned @redocly/cli@2.25.2 from
  devDependencies instead of downloading an unpinned version
- Update actions/checkout and actions/setup-node from v4 to v5,
  matching the convention in e2e-tests.yaml

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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