22import os
33from enum import StrEnum
44from pathlib import Path
5- from typing import Annotated
65
76import uvicorn
8- from fastapi import FastAPI , Header , HTTPException
7+ from fastapi import FastAPI , HTTPException , Request
98from fastapi .middleware .cors import CORSMiddleware
109from fastapi .responses import JSONResponse , Response
1110
@@ -34,10 +33,39 @@ class ValidAcceptHeaders(StrEnum):
3433 RAW_BYTES = "application/octet-stream"
3534
3635
37- @app .get (ENDPOINTS .CONFIG + "/{file_path:path}" )
36+ @app .get (
37+ ENDPOINTS .CONFIG + "/{file_path:path}" ,
38+ responses = {
39+ 200 : {
40+ "description" : "Returns JSON, plain text, or binary file." ,
41+ "content" : {
42+ "application/json" : {
43+ "schema" : {
44+ "type" : "object" ,
45+ "additionalProperties" : True ,
46+ "example" : {
47+ "key" : "value" ,
48+ "list" : [1 , 2 , 3 ],
49+ "nested" : {"a" : 1 },
50+ },
51+ }
52+ },
53+ "text/plain" : {
54+ "schema" : {
55+ "type" : "string" ,
56+ "example" : "This is a plain text response" ,
57+ }
58+ },
59+ "application/octet-stream" : {
60+ "schema" : {"type" : "string" , "format" : "binary" },
61+ },
62+ },
63+ },
64+ },
65+ )
3866def get_configuration (
3967 file_path : Path ,
40- accept : Annotated [ ValidAcceptHeaders , Header ()] = ValidAcceptHeaders . PLAIN_TEXT ,
68+ request : Request ,
4169):
4270 """
4371 Read a file and return its contents in a format specified by the accept header.
@@ -46,6 +74,7 @@ def get_configuration(
4674 raise HTTPException (status_code = 404 , detail = f"File { file_path } cannot be found" )
4775
4876 file_name = os .path .basename (file_path )
77+ accept = request .headers .get ("accept" , ValidAcceptHeaders .PLAIN_TEXT )
4978
5079 try :
5180 match accept :
0 commit comments