Correção. Não estava ocorrendo a validação de schema_body_validation para open api 3, pois estava validando somente quando a especificação estava configurada para propriedades diretamente. Caso as validações fossem declaradas em schema (requestBody/Content/application/json/schema/$ref/#components/schemas) a validação em authAPI não executava (simplesmente ignora a validação).

É necessário re-executar o applyValidationAPI para reimplantar as APIs pois precisa acertar o schema_body_validation dos headers.
This commit is contained in:
2024-05-18 10:55:28 -03:00
parent 91400737e2
commit 6b417d0151
3 changed files with 12 additions and 4 deletions

View File

@@ -516,7 +516,12 @@ def process_api_spec(api_id, compartmentId, environment, swagger, functionId, ho
API_NAME = fullSpec["info"]["title"] API_NAME = fullSpec["info"]["title"]
if (version == "3"): if (version == "3"):
try: 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" CONTENT_TYPE = "application/json"
except: except:
SCHEMA_BODY_VALIDATION = "" SCHEMA_BODY_VALIDATION = ""

View File

@@ -124,7 +124,7 @@ def handler(ctx, data: io.BytesIO = None):
# Validate API spec # Validate API spec
if (body_schema_validation != None): if (body_schema_validation != None):
if (".apigatewayapi." not in header["body_schema_validation"]): if (".apigatewayapi." not in header["body_schema_validation"]):
# Version OpenAPI 3 # Com validacao direto por propriedades (sem schemas e referencias)
try: try:
validate(body, body_schema_validation["schema"]) validate(body, body_schema_validation["schema"])
return response.Response( return response.Response(
@@ -162,7 +162,7 @@ def handler(ctx, data: io.BytesIO = None):
response_data=rdata response_data=rdata
) )
else: else:
# Version Swagger 2 # Com schema de validação - Tanto swagger como Open API 3
try: try:
bravado_config = { bravado_config = {
'validate_swagger_spec': False, 'validate_swagger_spec': False,
@@ -175,7 +175,10 @@ def handler(ctx, data: io.BytesIO = None):
api_spec = apigateway_client.get_api_content(contents[1]) api_spec = apigateway_client.get_api_content(contents[1])
spec_dict = json.loads(api_spec.data.content) spec_dict = json.loads(api_spec.data.content)
spec = Spec.from_dict(spec_dict, config=bravado_config) spec = Spec.from_dict(spec_dict, config=bravado_config)
try:
schema = spec_dict["definitions"][contents[0]] schema = spec_dict["definitions"][contents[0]]
except:
schema = spec_dict["components"]["schemas"][contents[0]]
validate_object(spec, schema, body) validate_object(spec, schema, body)
except (Exception) as ex3: except (Exception) as ex3:
error_msg = beautify_str(str(ex3)) error_msg = beautify_str(str(ex3))