Coverage for nexios\openapi\config.py: 92%
12 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-21 20:31 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-21 20:31 +0100
1from .models import Contact, License, Server, OpenAPI, Info, SecurityScheme, Components
2from typing import Dict, List, Optional
5class OpenAPIConfig:
6 def __init__(
7 self,
8 title: str = "API Documentation",
9 version: str = "1.0.0",
10 description: str = "",
11 servers: Optional[List[Server]] = None,
12 contact: Optional[Contact] = None,
13 license: Optional[License] = None,
14 ):
15 self.openapi_spec = OpenAPI(
16 openapi="3.0.0",
17 info=Info(
18 title=title,
19 version=version,
20 description=description,
21 contact=contact,
22 license=license,
23 ),
24 paths={},
25 servers=servers or [Server(url="/")],
26 components=Components(),
27 )
28 self.security_schemes: Dict[str, SecurityScheme] = {}
30 def add_security_scheme(self, name: str, scheme: SecurityScheme):
31 """Add a security scheme to the OpenAPI specification"""
32 if not self.openapi_spec.components:
33 self.openapi_spec.components = Components()
35 if not self.openapi_spec.components.securitySchemes:
36 self.openapi_spec.components.securitySchemes = {}
38 self.openapi_spec.components.securitySchemes[name] = scheme