Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
(PC-5752) : fix OpenAPI 3.0.3 schema
Browse files Browse the repository at this point in the history
Spectree has a small imcompatibility with the OpenAPI 3.0.3:
Nested models are generated as `/definitions/{model}` while
no such path exists within OpenAPI 3.0.x
All models should be under `/components/schemas/`.
While this has been reported and fixed upstream with PR:
0b01001001/spectree#91
we need to fix it while waiting the proper solution.
  • Loading branch information
xordoquy committed Dec 11, 2020
1 parent 776ce14 commit 8c1429a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/pcapi/routes/native/v1/blueprint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
from flask import Blueprint
import pydantic.schema
from spectree import SpecTree

from pcapi.serialization.utils import before_handler


native_v1 = Blueprint("native_v1", __name__)

api = SpecTree("flask", MODE="strict", before=before_handler, PATH="/")

# TODO: Remove PassSpecTree and pydantic patch whenever
# https://github.com/0b01001001/spectree/pull/91 is released
class PassSpecTree(SpecTree):
def _generate_spec(self) -> dict:
spec = super()._generate_spec()
spec["components"]["schemas"].update(spec.pop("definitions", {}))
return spec


pydantic.schema.default_prefix = "#/components/schemas/"


api = PassSpecTree("flask", MODE="strict", before=before_handler, PATH="/")
api.register(native_v1)

0 comments on commit 8c1429a

Please sign in to comment.