MCPcopy Create free account
hub / github.com/aws-samples/personalization-apis / OpenApiGenerator

Class OpenApiGenerator

src/config_validator_function/openapi.py:24–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24class OpenApiGenerator:
25 def _get_openapi_template_filename(self) -> str:
26 return OPENAPI_TEMPLATE_FILE
27
28 def _get_openapi_template(self) -> Dict:
29 shell_filename = self._get_openapi_template_filename()
30 logger.info('Loading openapi shell from %s', shell_filename)
31 with open(shell_filename) as file:
32 return json.loads(file.read())
33
34 def generate(self, apis_config: Dict, apigw_host: str, cloudfront_host: str, auth_scheme: str) -> Dict:
35 openapi = self._get_openapi_template()
36
37 if "title" in apis_config:
38 openapi["info"]["title"] = apis_config["title"]
39 if "description" in apis_config:
40 openapi["info"]["description"] = apis_config["description"]
41 if "version" in apis_config:
42 openapi["info"]["version"] = apis_config["version"]
43
44 if cloudfront_host:
45 openapi["servers"].append({ "url": cloudfront_host })
46 openapi["servers"].append({ "url": apigw_host })
47
48 if auth_scheme == AUTH_SCHEME_API_KEY:
49 openapi["security"] = [ { "ApiKeyAuth": [] } ]
50 openapi["components"]["securitySchemes"] = {
51 "ApiKeyAuth": {
52 "type": "apiKey",
53 "in": "header",
54 "name": "X-API-Key"
55 }
56 }
57 elif auth_scheme == AUTH_SCHEME_OAUTH2:
58 openapi["security"] = [ { "BearerAuth": [] } ]
59 openapi["components"]["securitySchemes"] = {
60 "BearerAuth": {
61 "type": "http",
62 "scheme": "bearer",
63 "bearerFormat": "JWT"
64 }#,
65 #"OAuth2Auth": {
66 # "type": "oauth2",
67 # "flows": {
68 # "authorizationCode": {
69 # "authorizationUrl": "https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/authorize",
70 # "tokenUrl": "https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/token",
71 # "refreshUrl": "https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/token"
72 # }
73 # }
74 #}
75 }
76 else:
77 openapi.pop("security", None)
78
79 tags = []
80 paths = {}
81

Callers 3

lambda_handlerFunction · 0.90
test_simple_noauthFunction · 0.90
test_simple_apikeyFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_simple_noauthFunction · 0.72
test_simple_apikeyFunction · 0.72