mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-06 12:27:45 +00:00
This PR is a proposal to enforce defaults in json bodies. The standard JsonRequestBodyValidator does not adapt the body. Instead, I added a DefaultsJsonRequestBodyValidator which does. The user can easily activate enforcing default by passing this Validator in a validator_map. I would have liked connexion to have an enforce_defaults flag, but it would be hard to make this compatible with the validator_map argument.
21 lines
485 B
Python
Executable File
21 lines
485 B
Python
Executable File
from pathlib import Path
|
|
|
|
import connexion
|
|
from connexion.validators import DefaultsJSONRequestBodyValidator
|
|
|
|
|
|
def echo(data):
|
|
return data
|
|
|
|
|
|
validator_map = {"body": {"application/json": DefaultsJSONRequestBodyValidator}}
|
|
|
|
|
|
app = connexion.AsyncApp(__name__, specification_dir="spec")
|
|
app.add_api("openapi.yaml", validator_map=validator_map)
|
|
app.add_api("swagger.yaml", validator_map=validator_map)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(f"{Path(__file__).stem}:app", port=8080)
|