Skip to content

Fix/endpoints response fields - #1

Merged
tempont merged 21 commits into
mainfrom
fix/endpoints-response-fields
Sep 29, 2026
Merged

tempont merged 21 commits into
mainfrom
fix/endpoints-response-fields

Conversation

@tempont

@tempont tempont commented Sep 29, 2026

Copy link
Copy Markdown
Owner

No description provided.

Real Bling payloads often send only "link" in midia.imagens.internas[],
while the vendored OpenAPI spec marks 6 fields as required, making
produtos.obter() raise BlingAPIError (ValidationError) on most products.

Relax link_miniatura, validade, ordem, anexo and anexo_vinculo via
generator overrides (Bug 6, following the Bug 4/5 pattern in
scripts/generate_models.py); link intentionally stays required.

Add real-world-shaped fixture for GET /produtos/{idProduto} and model
parse tests covering link-only, complete and imagensURL entries, plus a
regression test pinning link as required.
make codegen at HEAD emitted ~100 files of drift unrelated to any change:
12 re-export stubs (nfce, usuarios, logisticas_*) that were never committed,
+909 lines of Nfce/Logisticas operation metadata missing from
_operation_models.py, contracts formatting that relied on pre-commit's ruff
format instead of the generator, and docs EOF whitespace fixed only by
pre-commit hooks.

Root causes fixed in the generators:
- generate_openapi_contracts.py now runs ruff format over contracts and
  writes docs with final-newline/no-trailing-whitespace (mirroring
  generate_models.py, which already self-normalized)
- generate_models.py template now preserves the manual TODO docstring in
  models/generated/resources/__init__.py verbatim

After this, make codegen-check is meaningful as a drift gate (CI gate added
separately).
make codegen-check now fails on untracked files in generated directories,
both before and after regeneration (generate_models.py wipes and rewrites
models/generated, so a post-only check would miss strays the wipe removed).

Adds a codegen-drift job to GitHub Actions and a local pre-commit hook that
only triggers when generation-relevant files change (spec, generators,
generated artifacts, generated docs).
…ions

Raw datamodel-codegen output spells aliases as alias="<BlingName>", but
the clone gate only looked for validation_alias/serialization_alias —
keywords that exist only after _rewrite_field_aliases, which never runs
on inserted redeclarations. Every parent-alive insert therefore fell
back to a bare None, and the first future override on an inherited
camelCase field would silently emit a redeclaration without aliases,
making to_json_object() serialize the wrong wire key.

Extend the gate to the raw alias form and normalize the clone into the
repo-standard validation_alias=AliasChoices(...) + serialization_alias
pair. Alias-less parents keep the bare None fallback, so the 12 live
override keys' output stays byte-identical (verified with a clean
generator run and git diff --exit-code).
@tempont-bot

tempont-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Mira PR Walkthrough

This PR aligns the generated model schemas and operation contracts so API endpoints return correctly-typed response fields — primarily fixing product (produtos) and sales order (pedidos_vendas) field definitions via updated overrides in the code generation pipeline. It also significantly enhances generate_models.py, adds a new authentication example script, expands unit test coverage for products/sales orders/overrides (with new JSON fixtures), updates resource serialization paths in sales_orders.py, bumps the package version, and refreshes CI/pre-commit/docs configuration plus changelog and contributor docs. Overall it's a consistency-and-correctness release for endpoint responses combined with substantial developer-tooling improvements.

24 files reviewed


Comment @tempont-bot help to get the list of available commands and usage tips.

@tempont
tempont merged commit 1267cc1 into main Sep 29, 2026
3 checks passed
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