Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate uniqueness by identity #54

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tomreitz
Copy link
Collaborator

@tomreitz tomreitz commented Oct 7, 2024

lightbeam validate payload uniqueness previously (and incorrectly) checked uniqueness by required properties; this PR makes it check uniqueness by properties with x-Ed-Fi-isIdentity=true in Swagger.

Tom Reitz added 3 commits October 7, 2024 11:46
…uniqueness by required properties; this update makes it check uniqueness by properies with x-Ed-Fi-isIdentity in Swagger
return "#/components/schemas/" + camel_case(namespace) + "_" + singularize_endpoint(endpoint)

def resolve_swagger_ref(swagger, ref):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abstracts Swagger $ref resolution logic, which varies by Ed-Fi version.

@@ -166,7 +166,8 @@ def write_structured_output(self, command):
# failures.line_numbers are split each on their own line; here we remove those line breaks
content = re.sub(r'"line_numbers": \[(\d|,|\s|\n)*\]', self.replace_linebreaks, content)
fp.write(content)
self.logger.info(f"results written to {self.results_file}")

self.logger.info(f"results written to {self.results_file}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Added an indent here so it's only printed if a results-file was actually created.)

lightbeam/api.py Outdated
sub_schema = util.resolve_swagger_ref(swagger, sub_definition)
for sub_prop in sub_schema["required"]:
params[f"{prop}.{sub_prop}"] = sub_prop
elif "$ref" in schema["properties"][prop].keys():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recurse into $ref properties

lightbeam/api.py Outdated
for k,v in sub_params.items():
params[k] = v
elif schema["properties"][requiredProperty]["type"]!="array":
params[requiredProperty] = prefix + requiredProperty
elif schema["properties"][prop]["type"]!="array" and "x-Ed-Fi-isIdentity" in schema["properties"][prop].keys():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

properties with x-Ed-Fi-isIdentity=true are part of identity

@@ -331,33 +331,52 @@ async def load_descriptors_values(self):
# }
# (The first element is a required attribute of the assessmentItem; the other two are required elements
# of the required nested assessmentReference.)
def get_params_for_endpoint(self, endpoint):
def get_params_for_endpoint(self, endpoint, type='required'):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default type here ensures non-breaking functionality for any other lightbeam functions that use this function

lightbeam/api.py Outdated
self.logger.critical(f"Swagger contains neither `definitions` nor `components.schemas` - check that the Swagger is valid.")

for prop in schema["properties"]:
if prop.endswith("Reference") and "required" in schema.keys() and prop in schema['required']:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required properties of a *Reference are part of the identity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant