|
18 | 18 | Form, |
19 | 19 | Path, |
20 | 20 | Query, |
| 21 | + Request, |
21 | 22 | UploadFile, |
22 | 23 | ) |
| 24 | +from fastapi.params import Depends |
23 | 25 | from typing_extensions import Annotated |
24 | 26 |
|
25 | 27 | from galaxy import ( |
|
48 | 50 | ) |
49 | 51 |
|
50 | 52 |
|
| 53 | +def path_query_or_form( |
| 54 | + request: Request, |
| 55 | + path_query: Annotated[Optional[str], Query(alias="path", description="Path to file to create.")] = None, |
| 56 | + path_form: Annotated[Optional[str], Form(alias="path", description="Path to file to create.")] = None, |
| 57 | +): |
| 58 | + """ |
| 59 | + Accept `path` parameter both in query and form format. |
| 60 | +
|
| 61 | + This method does not force the client to provide the parameter, it could simply not submit the parameter in either |
| 62 | + format. To force the client to provide the parameter, coerce the output of the method to a string, i.e. |
| 63 | + `path: str = Depends(path_query_or_form)` so that FastAPI responds with status code 500 when the parameter is not |
| 64 | + provided. |
| 65 | + """ |
| 66 | + return path_query or path_form |
| 67 | + |
| 68 | + |
| 69 | +def job_key_query_or_form( |
| 70 | + request: Request, |
| 71 | + job_key_query: Annotated[ |
| 72 | + Optional[str], |
| 73 | + Query( |
| 74 | + alias="job_key", |
| 75 | + description=( |
| 76 | + "A key used to authenticate this request as acting on behalf or a job runner for the specified job." |
| 77 | + ), |
| 78 | + ), |
| 79 | + ] = None, |
| 80 | + job_key_form: Annotated[ |
| 81 | + Optional[str], |
| 82 | + Form( |
| 83 | + alias="job_key", |
| 84 | + description=( |
| 85 | + "A key used to authenticate this request as acting on behalf or a job runner for the specified job." |
| 86 | + ), |
| 87 | + ), |
| 88 | + ] = None, |
| 89 | +): |
| 90 | + """ |
| 91 | + Accept `job_key` parameter both in query and form format. |
| 92 | +
|
| 93 | + This method does not force the client to provide the parameter, it could simply not submit the parameter in either |
| 94 | + format. To force the client to provide the parameter, coerce the output of the method to a string, i.e. |
| 95 | + `job_key: str = Depends(job_key_query_or_form)` so that FastAPI responds with status code 500 when the parameter is |
| 96 | + not provided. |
| 97 | + """ |
| 98 | + return job_key_query or job_key_form |
| 99 | + |
| 100 | + |
51 | 101 | @router.cbv |
52 | 102 | class FastAPIJobFiles: |
53 | 103 | """ |
@@ -139,15 +189,8 @@ def index( |
139 | 189 | def create( |
140 | 190 | self, |
141 | 191 | job_id: Annotated[str, Path(description="Encoded id string of the job.")], |
142 | | - path: Annotated[str, Form(description="Path to file to create.")], |
143 | | - job_key: Annotated[ |
144 | | - str, |
145 | | - Form( |
146 | | - description=( |
147 | | - "A key used to authenticate this request as acting on behalf or a job runner for the specified job." |
148 | | - ) |
149 | | - ), |
150 | | - ], |
| 192 | + path: Annotated[str, Depends(path_query_or_form)], |
| 193 | + job_key: Annotated[str, Depends(job_key_query_or_form)], |
151 | 194 | file: UploadFile = File(None, description="Contents of the file to create."), |
152 | 195 | session_id: str = Form(None), |
153 | 196 | nginx_upload_module_file_path: str = Form( |
|
0 commit comments