Skip to content

Commit

Permalink
bring back fastapi openapi integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wkarwacki committed Aug 20, 2024
1 parent eb837e2 commit abf9063
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/lib/gen/python/server/templates/service.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ from typing import Any, Generator, Tuple

class {{to_pascal_case feature}}Service(ABC):
{{#each ops}}{{#each this}} {{#if (filterNonconst this.res.meta)}}class {{to_pascal_case this.name}}Headers(BaseModel):
@classmethod
def get(cls) -> '{{to_pascal_case this.name}}Headers':
return {{to_pascal_case ../../feature}}Service.{{to_pascal_case this.name}}Headers(
{{#each this.res.meta}}{{fmtName @key}}={{stubImpl this}}
{{/each}}
)

{{#each (filterNonconst this.res.meta)}}{{to_snake_case this.[0]}}: {{fmtType this.[1]}}
{{/each}}
def to_dict(self) -> dict[str, str]:
Expand All @@ -15,5 +22,5 @@ class {{to_pascal_case feature}}Service(ABC):

{{#unless ../../autoImpl}}@abstractmethod{{/unless}}
def {{to_snake_case this.name}}(self{{#if this.req}}, {{#if this.req.path}}{{fmtName this.req.path}}: {{>dtoName val=(fmtClass this.req.path)}}{{else}}{{#if (eq this.req.form "multipart/form-data")}}{{fmtName (add this.name "Req")}}: {{>dtoName val=(fmtClass (add this.name "Req"))}}{{else if (or (eq this.req.type "obj") (eq this.req.type "seq") (eq this.req.type "map"))}}{{fmtName (add this.name "Req")}}: {{fmtName (add this.name "Req")}}.{{>dtoName val=(fmtClass (add this.name "Req"))}}{{else}}request: {{fmtType this.req}}{{/if}}{{/if}}{{/if}}{{#each this.params}}, {{to_snake_case this.name}}: {{#if this.opt}}{{fmtOpt (fmtType this)}}{{else}}{{fmtType this}}{{/if}}{{/each}}) -> {{#if this.res}}{{#if (filterNonconst this.res.meta)}}Tuple[{{/if}}{{#if (eq this.res.carrier "stream")}}Generator[{{fmtType this.res}}, None, None]{{else}}{{#if this.res.path}}{{fmtType this.res (to_pascal_case this.name)}}{{else if (or (eq this.res.type "obj") (eq this.res.type "seq") (eq this.res.type "map"))}}{{>dtoName val=(fmtClass (add this.name "Res"))}}{{else}}{{fmtType this.res}}{{/if}}{{/if}}{{#if this.res.meta}}{{#if (filterNonconst this.res.meta)}}, {{to_pascal_case this.name}}Headers]{{/if}}{{/if}}{{else}}None{{/if}}:
{{#if ../../autoImpl}}{{#if this.res}}return {{>stubImpl val=this.res key=this.name}}{{else}}pass{{/if}}{{else}}raise NotImplementedError{{/if}}
{{#if ../../autoImpl}}{{#if this.res}}return {{#if (filterNonconst this.res.meta)}}({{/if}}{{>stubImpl val=this.res key=this.name}}{{#if (filterNonconst this.res.meta)}}, {{to_pascal_case ../../feature}}Service.{{to_pascal_case this.name}}Headers.get()){{/if}}{{else}}pass{{/if}}{{else}}raise NotImplementedError{{/if}}
{{/each}}{{/each}}
10 changes: 5 additions & 5 deletions test/integration/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class Spec(BaseModel):
name="openapi",
entrypoint="api.yml"
),
# Spec(
# name="openapi_fastapi",
# entrypoint="api.yml",
# params = ["-l=tag"]
# ),
Spec(
name="openapi_fastapi",
entrypoint="api.yml",
params = ["-l=tag"]
),
]

test_integration_path = pathlib.Path(__file__).parent.resolve()
Expand Down

0 comments on commit abf9063

Please sign in to comment.