Skip to content

Extract shared helper to eliminate duplication between dump_models and dump_schema #2099

Description

@coderabbitai

Summary

dump_models in src/utils/models_dumper.py duplicates the OpenAPI schema-writing logic already implemented in dump_schema in src/utils/schema_dumper.py. Both functions:

  • Build a schema via pydantic.json_schema.models_json_schema with the same ref_template.
  • Apply recursive_update post-processing.
  • Wrap the result in an identical OpenAPI 3.0 structure (openapi, info, components.schemas, paths).
  • Write the result to a file with the same json.dump(..., indent=4) call.

The only real differences are the list of models passed in and the docstring.

Rationale

This is a DRY violation that increases maintenance burden — any future change to the OpenAPI wrapping logic (e.g., metadata, formatting, error handling) needs to be duplicated in two places.

Affected areas

  • src/utils/models_dumper.py (dump_models)
  • src/utils/schema_dumper.py (dump_schema)

Suggested change

Extract a shared private helper, e.g. _dump_openapi_schema(models: list, filename: str) -> None, that accepts the list of Pydantic models and the output filename, performs the schema generation/post-processing/wrapping/write, and have both dump_models and dump_schema call it with their respective model lists.

Acceptance criteria

  • A shared helper function is introduced and used by both dump_models and dump_schema.
  • No behavioral change to the generated OpenAPI JSON output.
  • Existing unit tests (e.g. tests/unit/utils/test_models_dumper.py) continue to pass.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions