OpenAPI 3.0 request schema generation#73
Open
Serbel97 wants to merge 3 commits into
Open
Conversation
Adds a dependency-free generate_form_schema() helper which converts any Form class into an OpenAPI 3.0 Schema Object describing its JSON request body: scalar type/format mapping, nested FormField/FormFieldList objects, FieldList arrays, EnumField/ChoiceField enums, DictionaryField additionalProperties, required propagation and Meta.mapping-aware property names. Unknown field types fall back to an untyped schema. Closes Sibyx#72 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #73 +/- ##
==========================================
+ Coverage 95.09% 96.23% +1.14%
==========================================
Files 9 10 +1
Lines 469 585 +116
==========================================
+ Hits 446 563 +117
+ Misses 23 22 -1
🚀 New features to boost your workflow:
|
Adds tests for non-string enums, grouped/boolean choices and FormFieldList maxItems, bringing openapi.py to 100% coverage. Introduces read-only properties (FieldList.field, min_length, max_length, DictionaryField.value_field) so schema generation no longer reaches into protected members. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <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.
Closes #72
What
Adds a dependency-free
generate_form_schema()helper (newdjango_api_forms.openapimodule, exported from the package root) that converts anyFormclass into an OpenAPI 3.0 Schema Object describing its JSON request body:How
{}(any type) instead of raisingtype/formatpairs (date-time,uuid,email,uri, ...) withminLength/maxLength/minimum/maximumconstraints where definedFormFieldrecurses into nested objects,FormFieldList/FieldListbecome arrays withminItems/maxItems,EnumField/ChoiceFieldbecomeenums,DictionaryFieldusesadditionalProperties,FileField/ImageFieldbecomestring/byte(Data URI payload)required=Truefields are collected into the object'srequiredarray;label/help_textare exported astitle/descriptionMeta.mappingis respected, so property names match the JSON keys clients actually send (e.g._nameinstead ofname)Scope
Deliberately schema-generation only — no bundled Swagger UI/ReDoc views and no new dependencies. The returned dict plugs into whatever documentation pipeline a project already uses;
docs/openapi.mdshows how to serve a complete OpenAPI document with Swagger UI/ReDoc from it.Testing
tests/test_openapi.pycovering every supported field type, nesting,requiredpropagation,Meta.mappingand the unknown-field fallbackflake8clean, full suite passes🤖 Generated with Claude Code