Skip to content

Commit 36cbac5

Browse files
committed
fix bug where '#/components/schemas/' wasn't being removed
1 parent b88ae4c commit 36cbac5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lightbeam/validate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,23 @@ def load_references_structure(self, swagger, definition):
144144
self.logger.critical(f"Swagger contains neither `definitions` nor `components.schemas` - check that the Swagger is valid.")
145145
references = {}
146146
for k in schema["properties"].keys():
147+
prefixes_to_remove = (("#/definitions/", ""), ("#/components/schemas/", ""))
148+
147149
if k.endswith("Reference"):
148150
original_endpoint = util.pluralize_endpoint(k.replace("Reference", ""))
149151

150152
# this deals with the fact that an educationOrganizationReference may be to a school, LEA, etc.:
151153
endpoints_to_check = self.EDFI_GENERICS_TO_RESOURCES_MAPPING.get(original_endpoint, [original_endpoint])
152154

153155
for endpoint in endpoints_to_check:
154-
ref_definition = schema["properties"][k]["$ref"].replace("#/definitions/", "")
156+
ref_definition = schema["properties"][k]["$ref"].replace(*prefixes_to_remove)
155157
# look up (in swagger) the required fields for any reference
156158
ref_properties = self.load_reference(swagger, ref_definition)
157159
references[endpoint] = ref_properties
158160
elif "items" in schema["properties"][k].keys():
159161
# this deals with a property which is a list of items which themselves contain References
160162
# (example: studentAssessment.studentObjectiveAssessments contain an objectiveAssessmentReference)
161-
nested_definition = schema["properties"][k]["items"]["$ref"].replace("#/definitions/", "")
163+
nested_definition = schema["properties"][k]["items"]["$ref"].replace(*prefixes_to_remove)
162164
nested_references = self.load_references_structure(swagger, nested_definition)
163165
references.update(nested_references)
164166
return references

0 commit comments

Comments
 (0)