This section aims to be a cookbook of possible solutions for specific use cases of FireTail.
Path parameters cannot contain slashes by default, but sometimes it’s useful to have a path parameter that takes the full remainder of the HTTP path including slashes, for example to allow parsing “my/deep/path” from “/pages/my/deep/path”. FireTail supports parsing such path remainders by using format: path:
It is possible to define custom type formats that are going to be used by the FireTail payload validation on request parameters and response payloads of your API.
Let’s say your API deals with Products and you want to define a field price_label that has a “money” format value. You can create a format checker function and register that to be used to validate values of the “money” format.
Example of a possible schema of Product having an attribute with “money” format that would be defined in your OpenAPI specification:
Then we create a format checker function for that type of value:
The format checker function is expected to return True when the value matches the expected format and return False when it doesn’t. Also is important to verify if the type of the value you are trying to validate is compatible with the format. In our example, we check if the val is of type “string” before performing any further checking.
The final step to make it work is registering our is_money function to the format “money” in json_schema library. For that, we can use the draft4 format checker decorator.
This is all you need to have validation for that format in your FireTail application. Keep in mind that the format checkers should be defined and registered before you run your application server. A full example can be found at github.
CORS (Cross-origin resource sharing) is not built into FireTail, but you can use the flask-cors library to set CORS headers:
You can customize logging accessing the _flask-logger directly or configuring the logger via dictConfig. Remember that you should configure logging for your project as soon as possible when the program starts or you’ll get the default configuration.