File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414from log import get_logger , setup_logging
1515from runners .quota_scheduler import start_quota_scheduler
1616from runners .uvicorn import start_uvicorn
17- from utils import models_dumper , schema_dumper
17+ from utils import config_dumper , models_dumper
1818
1919setup_logging ()
2020logger = get_logger (__name__ )
@@ -195,7 +195,7 @@ def main() -> None:
195195 # into a JSON file that is compatible with OpenAPI schema specification
196196 if args .dump_schema :
197197 try :
198- schema_dumper .dump_schema ("schema.json" )
198+ config_dumper .dump_schema ("schema.json" )
199199 logger .info ("Configuration schema dumped to schema.json" )
200200 except Exception as e :
201201 logger .error ("Failed to dump configuration schema: %s" , e )
Original file line number Diff line number Diff line change 1+ """Function to dump the configuration schema into OpenAPI-compatible format."""
2+
3+ from models .config import Configuration
4+ from utils .openapi_schema_dumper import dump_openapi_schema
5+
6+
7+ def dump_schema (filename : str ) -> None :
8+ """Dump the configuration schema into OpenAPI-compatible JSON file.
9+
10+ Parameters:
11+ ----------
12+ - filename: str - name of file to export the schema to
13+
14+ Returns:
15+ -------
16+ - None
17+
18+ Raises:
19+ ------
20+ IOError: If the file cannot be written.
21+ """
22+ models = [Configuration ]
23+ dump_openapi_schema (models , filename )
Original file line number Diff line number Diff line change 11"""Function to dump the schema of all data models into OpenAPI-compatible format."""
22
3- import json
4-
5- from pydantic .json_schema import models_json_schema
6-
73import models .compaction as models_compaction
8- from utils .json_schema_updater import recursive_update
4+ from utils .openapi_schema_dumper import dump_openapi_schema
95
106
117def dump_models (filename : str ) -> None :
@@ -23,29 +19,5 @@ def dump_models(filename: str) -> None:
2319 ------
2420 IOError: If the file cannot be written.
2521 """
26- with open (filename , "w" , encoding = "utf-8" ) as fout :
27- # retrieve the schema
28- _ , schemas = models_json_schema (
29- [
30- (model , "validation" )
31- for model in [models_compaction .ConversationSummary ]
32- ],
33- ref_template = "#/components/schemas/{model}" ,
34- )
35-
36- # fix the schema
37- schemas = recursive_update (schemas )
38-
39- # add all required metadata
40- openapi_schema = {
41- "openapi" : "3.0.0" ,
42- "info" : {
43- "title" : "Lightspeed Core Stack" ,
44- "version" : "0.3.0" ,
45- },
46- "components" : {
47- "schemas" : schemas .get ("$defs" , {}),
48- },
49- "paths" : {},
50- }
51- json .dump (openapi_schema , fout , indent = 4 )
22+ models = [models_compaction .ConversationSummary ]
23+ dump_openapi_schema (models , filename )
Original file line number Diff line number Diff line change 1- """Function to dump the configuration schema into OpenAPI-compatible format."""
1+ """Utility function to dump schema with list of models into OpenAPI-compatible JSON format."""
22
33import json
44
55from pydantic .json_schema import models_json_schema
66
7- from models .config import Configuration
87from utils .json_schema_updater import recursive_update
98
109
11- def dump_schema ( filename : str ) -> None :
12- """Dump the configuration schema into OpenAPI-compatible JSON file.
10+ def dump_openapi_schema ( models : list , filename : str ) -> None :
11+ """Write an OpenAPI-compatible JSON schema for the given models to a file.
1312
1413 Parameters:
1514 ----------
15+ - models: list - Pydantic model classes to include in the schema
1616 - filename: str - name of file to export the schema to
1717
18- Returns:
19- -------
20- - None
21-
2218 Raises:
2319 ------
2420 IOError: If the file cannot be written.
2521 """
2622 with open (filename , "w" , encoding = "utf-8" ) as fout :
27- # retrieve the schema
2823 _ , schemas = models_json_schema (
29- [(model , "validation" ) for model in [ Configuration ] ],
30- ref_template = "#/components/schemas/{model}" ,
24+ [(model , "validation" ) for model in models ],
25+ ref_template = "` #/components/schemas/` {model}" ,
3126 )
32-
33- # fix the schema
3427 schemas = recursive_update (schemas )
35-
36- # add all required metadata
3728 openapi_schema = {
3829 "openapi" : "3.0.0" ,
3930 "info" : {
Original file line number Diff line number Diff line change 1- """Unit tests for utils/schema_dumper module."""
1+ """Unit tests for utils/config_dumper module."""
22
33from json import load
44from pathlib import Path
55
6- from utils .schema_dumper import dump_schema
6+ from utils .config_dumper import dump_schema
77
88
99def test_dump_schema (tmpdir : Path ) -> None :
You can’t perform that action at this time.
0 commit comments