Skip to content

Commit 7b71157

Browse files
committed
using in web
1 parent 3f999c4 commit 7b71157

File tree

2 files changed

+2
-46
lines changed

2 files changed

+2
-46
lines changed

api/specs/web-server/_common.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
from pathlib import Path
88
from typing import Annotated, NamedTuple, Optional, Union, get_args, get_origin
99

10-
import yaml
1110
from common_library.json_serialization import json_dumps
1211
from common_library.pydantic_fields_extension import get_type
13-
from fastapi import FastAPI, Query
12+
from fastapi import Query
1413
from models_library.basic_types import LogLevel
1514
from pydantic import BaseModel, ConfigDict, Field, Json, create_model
1615
from pydantic.fields import FieldInfo
17-
from servicelib.fastapi.openapi import override_fastapi_openapi_method
1816

1917
CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
2018

@@ -119,48 +117,6 @@ class Error(BaseModel):
119117
status: int | None = Field(None, description="HTTP error code")
120118

121119

122-
def create_openapi_specs(
123-
app: FastAPI,
124-
*,
125-
drop_fastapi_default_422: bool = True,
126-
remove_main_sections: bool = True,
127-
):
128-
override_fastapi_openapi_method(app)
129-
openapi = app.openapi()
130-
131-
# Remove these sections
132-
if remove_main_sections:
133-
for section in ("info", "openapi"):
134-
openapi.pop(section, None)
135-
136-
schemas = openapi["components"]["schemas"]
137-
for section in ("HTTPValidationError", "ValidationError"):
138-
schemas.pop(section, None)
139-
140-
# Removes default response 422
141-
if drop_fastapi_default_422:
142-
for method_item in openapi.get("paths", {}).values():
143-
for param in method_item.values():
144-
# NOTE: If description is like this,
145-
# it assumes it is the default HTTPValidationError from fastapi
146-
if (e422 := param.get("responses", {}).get("422", None)) and e422.get(
147-
"description"
148-
) == "Validation Error":
149-
param.get("responses", {}).pop("422", None)
150-
return openapi
151-
152-
153-
def create_and_save_openapi_specs(
154-
app: FastAPI, file_path: Path, *, drop_fastapi_default_422: bool = True
155-
):
156-
openapi = create_openapi_specs(
157-
app=app, drop_fastapi_default_422=drop_fastapi_default_422
158-
)
159-
with file_path.open("wt") as fh:
160-
yaml.safe_dump(openapi, fh, indent=1, sort_keys=False)
161-
print("Saved OAS to", file_path) # noqa: T201
162-
163-
164120
class ParamSpec(NamedTuple):
165121
name: str
166122
annotated_type: type

api/specs/web-server/openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import importlib
77

88
import yaml
9-
from _common import create_openapi_specs
109
from fastapi import FastAPI
1110
from fastapi.routing import APIRoute
11+
from servicelib.fastapi.openapi import create_openapi_specs
1212
from simcore_service_webserver._meta import API_VERSION, PROJECT_NAME, SUMMARY
1313
from simcore_service_webserver._resources import webserver_resources
1414

0 commit comments

Comments
 (0)