Open Chiheb-Nexus opened 1 year ago
Hi, @Chiheb-Nexus
I saw you take one or more ideas from my pull request at PR 489, which is good, so please consider to refer to it into your PR.
Hi, @Chiheb-Nexus
I saw you take one or more ideas from my pull request at PR 489, which is good, so please consider to refer to it into your PR.
Hello @selobu.
Honestly i've hesitated to mention your PR because we both trying to solve the same issue but with a different manners. However you're right there is some common points in our both approaches. I'll update my PR description.
Best regards.
Hello.
This PR will allow developers to automate the creation of API models while keeping customization possible.
PS: There is already an open PR that attempts to solve the same problem #489
Current behaviour (minimal example)
Developers need to manually create API models like this example:
New feature (minimal example)
Customization
The helper function definition:
Args meaning:
api
: Your Flask RestX API instance objectmodel
: YourSQLAlchemy/Flask SQLALchemy
model objectforce_camel_case
: By default JSON schemas fields are written incamelCase
format and developers can switch this feature off by settingsforce_camel_case=False
ignore_attributes
: By default none of your model's attributes are ignored, but in need you can manually add themfields
: List of the model's fields to be mapped (See below for more customizations); by default all your model's attributes are mapped (another way to add/exclude model's attributes; seeignore_attributes
)Foreigneys
are mapped by default in their respective nested formats (even for multi level relations between database tables) only iffields
argument is empty otherwise onlyfields
will be mapped.More customization
Developers can add a
Meta
class in their models definitions in order to control which attributes should be in their finalJSON schemas
or adding them to theArg: fields
.Example:
Is equivalent to:
For more details and customizations, See the
tests/test_auto_gen_api_model.py
.New package added during tests:
Flask-SQLAlchemy==3.0.2
is added totest.pip
requirement fileBest regards.