2020-09-17 22:22:24 -04:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from ruamel.yaml import YAML
|
|
|
|
|
2021-10-28 19:03:09 -04:00
|
|
|
from fresnel_lens.resources._shared import FresnelResource
|
2021-10-28 23:07:13 -04:00
|
|
|
from fresnel_lens.resources._shared import ResponseTuple
|
2020-09-21 19:36:07 -04:00
|
|
|
|
2020-09-17 22:22:24 -04:00
|
|
|
yaml = YAML(typ="safe")
|
|
|
|
|
|
|
|
|
2021-10-28 19:03:09 -04:00
|
|
|
class OpenAPI(FresnelResource):
|
2021-10-28 23:07:13 -04:00
|
|
|
"""Handle requests for the OpenAPI specification resource"""
|
2020-09-21 19:36:07 -04:00
|
|
|
|
|
|
|
routes = ("/openapi.json",)
|
|
|
|
|
2021-10-28 23:07:13 -04:00
|
|
|
def get(self) -> ResponseTuple:
|
|
|
|
"""Retrieve the OpenAPI specification document"""
|
|
|
|
with (Path(__file__).parent / "openapi.yaml").open() as infile:
|
2020-09-17 22:22:24 -04:00
|
|
|
data = yaml.load(infile)
|
|
|
|
|
2021-10-28 23:07:13 -04:00
|
|
|
return self.make_response(data)
|
|
|
|
|
|
|
|
def head(self) -> ResponseTuple:
|
|
|
|
"""Alias of GET with no response body"""
|
|
|
|
return self._head(self.get())
|