1
1
import json
2
2
import logging
3
3
from pathlib import Path
4
- from typing import Any , Generator , Optional , Union
4
+ from typing import Any , Dict , Generator , List , Optional , Union
5
5
6
6
from kubernetes import client , config
7
7
from pydantic import BaseModel , Field
8
8
9
9
logger = logging .getLogger (__name__ )
10
10
11
11
12
- API_PATH_BY_TITLE : dict [str , Path ] = {
12
+ API_PATH_BY_TITLE : Dict [str , Path ] = {
13
13
"Kubernetes" : Path ("k8s" ), # Kubernetes API
14
14
"Kubernetes CRD Swagger" : Path ("crd" ), # CustomResourceDefinition API
15
15
}
@@ -29,7 +29,7 @@ def path(self) -> Path:
29
29
return API_PATH_BY_TITLE .get (self .title , Path ("" ))
30
30
31
31
@classmethod
32
- def from_spec (cls , spec : dict [str , Any ]) -> "SchemaMetadata" :
32
+ def from_spec (cls , spec : Dict [str , Any ]) -> "SchemaMetadata" :
33
33
return cls (
34
34
openapi = spec ["openapi" ],
35
35
title = spec ["info" ]["title" ],
@@ -38,10 +38,10 @@ def from_spec(cls, spec: dict[str, Any]) -> "SchemaMetadata":
38
38
39
39
40
40
class Schema (BaseModel ):
41
- openapi_schema : dict [str , Any ] = Field (default_factory = dict )
41
+ openapi_schema : Dict [str , Any ] = Field (default_factory = dict )
42
42
metadata : SchemaMetadata
43
43
44
- def to_openapi (self ) -> dict [str , Any ]:
44
+ def to_openapi (self ) -> Dict [str , Any ]:
45
45
return {
46
46
"openapi" : self .metadata .openapi ,
47
47
"info" : {"title" : self .metadata .title , "version" : self .metadata .version },
@@ -66,7 +66,7 @@ def _should_skip_path(self, path: str) -> bool:
66
66
stem = Path (path .split ("?" )[0 ]).stem
67
67
return not stem .startswith ("v" ) or stem == "version"
68
68
69
- def _add_to_schema_by_path (self , spec : dict [str , Any ]):
69
+ def _add_to_schema_by_path (self , spec : Dict [str , Any ]):
70
70
spec_metadata = SchemaMetadata .from_spec (spec )
71
71
72
72
if not spec_metadata .is_supported :
@@ -129,7 +129,7 @@ def _load_specs(self) -> Generator[Path, None, None]:
129
129
for path , schemas in self .schema_by_path .items ()
130
130
)
131
131
132
- def extract (self ) -> list [Path ]:
132
+ def extract (self ) -> List [Path ]:
133
133
"""
134
134
Extracts the Kubernetes OpenAPI specs and writes them to the output path.
135
135
0 commit comments