feat: add Python types publishing workflow for type-safe API consumption#2093
Open
rainer-friederich wants to merge 4 commits intomainfrom
Open
feat: add Python types publishing workflow for type-safe API consumption#2093rainer-friederich wants to merge 4 commits intomainfrom
rainer-friederich wants to merge 4 commits intomainfrom
Conversation
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>
5 tasks
|
This PR will trigger a minor release when merged. |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docs:bundlescript using existing@redocly/clito produce a single-fileopenapi.jsonpublish-typesCD workflow that triggers on GitHub releases, bundles the spec, runsdatamodel-codegento generate Pydantic v2 models, and publishes to atypes-pyorphan branch with version tagsclients/python/) for thespacecat-api-typespackageFollows the same orphan-branch pattern as
mysticat-data-service(cd.ymlpublish-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 asDict[str, Any]— no type safety. Bugs like adobe-rnd/llmo-data-retrieval-service#1155 (sending{"prompts": prompts}instead of the rawpromptsarray) 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):
datamodel-codegen --snake-case-fieldto generate Pydantic v2 modelstypes-pyorphan branch + create version tagDRS installs via:
Generated models use snake_case fields with camelCase aliases:
Changes
package.jsondocs:bundlescript.gitignoredocs/openapi/dist/and generatedmodels.pyclients/python/.github/workflows/publish-types.yamlTest plan
npm run docs:lint— passesnpm run docs:bundle— produces valid bundledopenapi.jsondatamodel-codegenon bundled spec — generates valid Python with correct field names/aliasesnpm test— all 7005 tests pass, no regressionspublish-types.yamlworkflow runs on next release🤖 Generated with Claude Code