File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ def __get_pydantic_json_schema__(
186
186
) -> _t .Any :
187
187
# until https://github.com/pydantic/pydantic/issues/8413 is fixed
188
188
json_schema = handler (core_schema )
189
- json_schema [ 'required' ] .append ('links' )
189
+ json_schema . setdefault ( 'required' , []) .append ('links' )
190
190
return json_schema
191
191
192
192
Original file line number Diff line number Diff line change 1
1
from dirty_equals import IsPartialDict
2
- from fastui import FastUI
2
+ from fastapi import FastAPI
3
+ from fastui import FastUI , components
3
4
from fastui .generate_typescript import generate_json_schema
5
+ from httpx import AsyncClient
4
6
5
7
6
8
async def test_json_schema ():
@@ -12,3 +14,25 @@ async def test_json_schema():
12
14
'type' : 'array' ,
13
15
}
14
16
# TODO test more specific cases
17
+
18
+
19
+ async def test_openapi ():
20
+ app = FastAPI ()
21
+
22
+ @app .get ('/api/' , response_model = FastUI , response_model_exclude_none = True )
23
+ def test_endpoint ():
24
+ return [components .Text (text = 'hello' )]
25
+
26
+ async with AsyncClient (app = app , base_url = 'http://test' ) as client :
27
+ r = await client .get ('/openapi.json' )
28
+ assert r .status_code == 200
29
+ assert r .headers ['content-type' ] == 'application/json'
30
+ assert r .json () == {
31
+ 'openapi' : '3.1.0' ,
32
+ 'info' : {
33
+ 'title' : 'FastAPI' ,
34
+ 'version' : '0.1.0' ,
35
+ },
36
+ 'paths' : IsPartialDict (),
37
+ 'components' : IsPartialDict (),
38
+ }
You can’t perform that action at this time.
0 commit comments