diff --git a/src/lib/gen/python/server/templates/service.hbs b/src/lib/gen/python/server/templates/service.hbs index 5fa2cc0..6da566a 100644 --- a/src/lib/gen/python/server/templates/service.hbs +++ b/src/lib/gen/python/server/templates/service.hbs @@ -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]: @@ -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}} diff --git a/test/integration/test.py b/test/integration/test.py index 93003f5..a6fe77e 100644 --- a/test/integration/test.py +++ b/test/integration/test.py @@ -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()