diff --git a/files/OCI_API_Gateway_Automation_files.zip b/files/OCI_API_Gateway_Automation_files.zip index 13355e1..214e17e 100644 Binary files a/files/OCI_API_Gateway_Automation_files.zip and b/files/OCI_API_Gateway_Automation_files.zip differ diff --git a/files/applyValidationApi/func.py b/files/applyValidationApi/func.py index 8d6487d..c912d29 100644 --- a/files/applyValidationApi/func.py +++ b/files/applyValidationApi/func.py @@ -516,7 +516,12 @@ def process_api_spec(api_id, compartmentId, environment, swagger, functionId, ho API_NAME = fullSpec["info"]["title"] if (version == "3"): try: - SCHEMA_BODY_VALIDATION = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"]) + try: + reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"]["schema"]["$ref"]).replace("#/components/schemas/", "") + SCHEMA_BODY_VALIDATION = reference + "," + api_id + except: + reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"]) + SCHEMA_BODY_VALIDATION = reference CONTENT_TYPE = "application/json" except: SCHEMA_BODY_VALIDATION = "" diff --git a/files/authApi/func.py b/files/authApi/func.py index 2324bae..5039d4e 100644 --- a/files/authApi/func.py +++ b/files/authApi/func.py @@ -124,7 +124,7 @@ def handler(ctx, data: io.BytesIO = None): # Validate API spec if (body_schema_validation != None): if (".apigatewayapi." not in header["body_schema_validation"]): - # Version OpenAPI 3 + # Com validacao direto por propriedades (sem schemas e referencias) try: validate(body, body_schema_validation["schema"]) return response.Response( @@ -162,7 +162,7 @@ def handler(ctx, data: io.BytesIO = None): response_data=rdata ) else: - # Version Swagger 2 + # Com schema de validação - Tanto swagger como Open API 3 try: bravado_config = { 'validate_swagger_spec': False, @@ -175,7 +175,10 @@ def handler(ctx, data: io.BytesIO = None): api_spec = apigateway_client.get_api_content(contents[1]) spec_dict = json.loads(api_spec.data.content) spec = Spec.from_dict(spec_dict, config=bravado_config) - schema = spec_dict["definitions"][contents[0]] + try: + schema = spec_dict["definitions"][contents[0]] + except: + schema = spec_dict["components"]["schemas"][contents[0]] validate_object(spec, schema, body) except (Exception) as ex3: error_msg = beautify_str(str(ex3))