Use Generated Python to Provide API Gateway Validation

Viewed 51

Since built-in AWS API Gateway validation is very limited (no pattern handling, etc), I'm working on manually validating beyond what build-in functionality provides. The AWS API is being generated from OpenAPI docs which include validation details that are subsequently represented in the generated Python code I'm generating from same OpenAPI docs. I'd like to use this generated validation logic rather than re-implementing the regexes/etc for manual validation.

The generated python code is designed to be a client of the API, so it makes sense there wouldn't be a straight-forward way to simply validate parameters and indeed the docs along with the generated code focus entirely on sending requests to the API, wity no mention of th validation code that exists in the generated code.

So the question is, is there a any reasonable way to leverage the validation logic within this generated python client? After spending some time poking around the generated code nothing jumps out and the documentation certainly doesn't provide anything on this front. The validation logic is all there, but I'm not seeing a good way to tap into it...

openapi_client.api.default_api: All of the parameter validation details appears to be located here, including validation for the query params I'm particularly interested in openapi_client.model_utils: All of the business logic used to apply validation defined in above appears to be here. The reachable functions of relevance I believe are check_allowed_values, check_validations, and validate_and_convert_types.

Currently working down path of creating a dummy instance of DefaultApi and using Endpoint instance therein to get validation details which I then manually pass into the model_utils functions mentioned above. It's not pretty, but looks like it's going toward something that'll work and allow me to re-use OpenAPI-defined validation.

0 Answers
Related