Skip to content

feat(api): OpenAPI Pydantic codegen + CI drift check (PLAN 3.5)#10

Merged
mcalthrop merged 8 commits intomainfrom
feat/plan-3.5-openapi-codegen
Apr 1, 2026
Merged

feat(api): OpenAPI Pydantic codegen + CI drift check (PLAN 3.5)#10
mcalthrop merged 8 commits intomainfrom
feat/plan-3.5-openapi-codegen

Conversation

@mcalthrop
Copy link
Copy Markdown
Owner

@mcalthrop mcalthrop commented Apr 1, 2026

Summary

Delivers PLAN §3.5: committed Pydantic models generated from the shared OpenAPI spec, CI that fails on drift, and supporting monorepo tooling so pnpm / Turborepo drive Python codegen and checks from the repository root.

OpenAPI → Pydantic

  • datamodel-code-generator is a normal dependency in apps/api/pyproject.toml.
  • recipes_api/openapi_codegen.py calls generate() programmatically (no reliance on a datamodel-codegen executable on PATH).
  • Generated output: recipes_api/generated/openapi_models.py (+ generated/__init__.py).

Recipe data layout

  • Static recipes.json lives under apps/api/data/ (moved out of recipes_api/).
  • recipes_api/data_paths.resolve_recipes_json_path() resolves the bundled file for editable installs vs wheel (force-include in pyproject.toml unchanged in effect).
  • StaticRecipeRepository now requires data_path; recipes_routes wires resolve_recipes_json_path().

Monorepo scripts (root)

  • pnpm openapi:generateturbo run openapi:generate (API runs python -m recipes_api.openapi_codegen).
  • pnpm openapi:validateturbo run openapi:validate (git drift check on generated output).
  • apps/web: placeholder openapi:generate / openapi:validate so Turbo has a consistent task graph.

**apps/api package scripts

  • build, dev, lint, test, openapi:generate use .venv/bin/python so they match postinstall (editable install + deps in the venv).
  • postinstall: create .venv if missing, then .venv/bin/python -m pip install -e . (bash -e -c '…').
  • openapi:validate: bash scripts/validate_openapi_generated.sh (shellcheck-friendly git status handling).

CI (.github/workflows/ci.yml)

  • Single workflow replaces the old separate OpenAPI / codegen workflows.
  • Order: actions/setup-python (3.12) before pnpm install so postinstall’s venv uses the intended Python.
  • Install API dev dependencies: .venv/bin/python -m pip install -e ".[dev]" (pytest, etc. in the same env as pnpm test).
  • Steps: pnpm lint, pnpm test, pnpm openapi:generate, pnpm openapi:validate.

Docs

  • Root README.md and apps/api/README.md updated for CI, pnpm scripts, venv, and data paths.

Other

  • PLAN.md: §3.5 marked complete as appropriate for this PR.

Add datamodel-code-generator, scripts/generate_openapi_models.py, and
committed recipes_api/generated/openapi_models.py from packages/openapi.

New workflow regenerates models and fails on git diff under generated/.
Document pnpm generate:openapi-models in apps/api README; mark PLAN 3.5 done.

Made-with: Cursor
Copilot AI review requested due to automatic review settings April 1, 2026 15:49
Comment thread .github/workflows/validate-openapi-python-codegen.yml Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements PLAN §3.5 by adding a reproducible OpenAPI→Pydantic code generation flow for the API package, committing the generated output, and introducing CI to detect spec/codegen drift.

Changes:

  • Add a Python script + pnpm script to generate Pydantic v2 models from packages/openapi/openapi.yaml using datamodel-code-generator.
  • Commit generated models under apps/api/recipes_api/generated/ and document regeneration steps.
  • Add a GitHub Actions workflow that regenerates models in CI and fails if the working tree differs from the committed generated output.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
PLAN.md Marks §3.5 as complete.
apps/api/scripts/generate_openapi_models.py Adds deterministic codegen script (stable flags, Python 3.12 target).
apps/api/recipes_api/generated/openapi_models.py Committed generated Pydantic models mirroring the OpenAPI schemas.
apps/api/recipes_api/generated/init.py Marks the generated package and discourages manual edits.
apps/api/README.md Documents how to regenerate and how CI enforces drift checks.
apps/api/pyproject.toml Adds datamodel-code-generator to API dev extras.
apps/api/package.json Adds generate:openapi-models script for workspace usage.
.github/workflows/validate-openapi-python-codegen.yml Adds CI job to regenerate + diff-check generated models.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/api/scripts/generate_openapi_models.py Outdated
Comment thread .github/workflows/validate-openapi-python-codegen.yml Outdated
- Pin actions/setup-python@v6.2.0; set permissions.contents: read.
- Fail on untracked/uncommitted files under recipes_api/generated/.
- generate_openapi_models: reuse resolve_openapi_spec_path(); derive output path from script location.

Made-with: Cursor
- Replace separate OpenAPI workflows with single ci.yml job
- Add validate_openapi_generated.sh and turbo/root openapi:validate
- Document pnpm lint, openapi:generate, openapi:validate in README

Made-with: Cursor
- Move static recipes to apps/api/data; resolve_recipes_json_path + required
  StaticRecipeRepository(data_path=...)
- Replace scripts/generate_openapi_models.py with recipes_api/openapi_codegen
- Use .venv/bin/python for api package scripts; postinstall via bash -e -c
- CI: setup-python before pnpm; pip install -e '.[dev]' into .venv
- Harden validate_openapi_generated.sh for shellcheck
- Web package: placeholder openapi:generate / openapi:validate for turbo

Made-with: Cursor
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 20 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

apps/api/pyproject.toml:16

  • PR description calls datamodel-code-generator a dev dependency, but it’s been added to the main project.dependencies (runtime) here. If the intent is tooling-only, consider moving it to an extra (e.g. [project.optional-dependencies].codegen or dev) and updating the postinstall / CI install step to install that extra; otherwise please align the PR description/docs with this being a runtime dependency.
requires-python = ">=3.12"
dependencies = [
  "datamodel-code-generator==0.26.5",
  "fastapi==0.115.12",
  "pyyaml==6.0.2",
  "uvicorn[standard]==0.34.3",
]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/api/scripts/validate_openapi_generated.sh Outdated
Comment thread apps/api/recipes_api/repository_test.py Outdated
Comment thread .github/workflows/ci.yml
- validate_openapi_generated: use git diff --quiet with actionable messages;
  PORCELAIN in UPPER_SNAKE_CASE
- Rename bundled recipes test to test_resolve_recipes_json_path_loads_recipes

Made-with: Cursor
@mcalthrop mcalthrop merged commit 5638778 into main Apr 1, 2026
4 checks passed
@mcalthrop mcalthrop deleted the feat/plan-3.5-openapi-codegen branch April 1, 2026 20:46
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.

3 participants