From d7df6bdb15a095d7fdc18c7fae06c085b78662be Mon Sep 17 00:00:00 2001 From: Jeet Shah Date: Thu, 12 Nov 2026 17:17:42 +0530 Subject: [PATCH] fix: support PostgreSQL OpenAPI generation locally --- Makefile | 3 +++ README.md | 11 +++++++++++ config/local_postgres.py | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 config/local_postgres.py diff --git a/Makefile b/Makefile index 72ee1aeb8..b9db40b0b 100755 --- a/Makefile +++ b/Makefile @@ -59,6 +59,9 @@ shell: check-uv # Load a shell openapi-generate: check-uv uv run manage.py spectacular --color --file openapi.yml ${local_config} +openapi-generate-postgres: check-uv # Generate OpenAPI schema using the local PostgreSQL database + uv run manage.py spectacular --color --file openapi.yml --settings=config.local_postgres + docker-up: # (Docker) Create services/volumes/networks docker compose up -d diff --git a/README.md b/README.md index 8c1255ab7..495680d81 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,17 @@ make migrate Run `make help` to see all tasks. +When regenerating `openapi.yml`, use the PostgreSQL-backed settings to keep +database-derived integer bounds consistent with the checked-in schema: + +```sh +make openapi-generate-postgres +``` + +This expects a local PostgreSQL database. Set `POSTGRES_DB`, `POSTGRES_USER`, +`POSTGRES_PASSWORD`, `POSTGRES_HOST`, and `POSTGRES_PORT` to override the +defaults (`pokeapi`, `ash`, `pokemon`, `localhost`, and `5432`). + ## Docker and Compose   [![docker hub](https://img.shields.io/docker/v/pokeapi/pokeapi?label=tag&sort=semver)](https://hub.docker.com/r/pokeapi/pokeapi) There is also a multi-container setup, managed by [Docker Compose V2](https://docs.docker.com/compose/). This setup allows you to deploy a production-like environment, with separate containers for each service, and is recommended if you need to simply spin up PokéAPI. diff --git a/config/local_postgres.py b/config/local_postgres.py new file mode 100644 index 000000000..9b8ad6ac5 --- /dev/null +++ b/config/local_postgres.py @@ -0,0 +1,16 @@ +"""Local development settings for generating the schema against PostgreSQL.""" + +import os + +from .local import * # noqa: F403 + +DATABASES: dict[str, DatabaseSettings] = { # noqa: F405 + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ.get("POSTGRES_DB", "pokeapi"), + "USER": os.environ.get("POSTGRES_USER", "ash"), + "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "pokemon"), + "HOST": os.environ.get("POSTGRES_HOST", "localhost"), + "PORT": os.environ.get("POSTGRES_PORT", "5432"), + } +}