MCPcopy Create free account
hub / github.com/apolloconfig/apollo / parse_spec

Function parse_spec

scripts/openapi/check_openapi_compatibility.py:301–347  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

299
300
301def parse_spec(text: str) -> OpenApiSnapshot:
302 snapshot = OpenApiSnapshot()
303 spec = yaml.safe_load(text) or {}
304 if not isinstance(spec, dict):
305 return snapshot
306
307 paths = spec.get("paths") or {}
308 if isinstance(paths, dict):
309 for path, path_item in paths.items():
310 if not isinstance(path_item, dict):
311 continue
312 for method, operation in path_item.items():
313 method = str(method).lower()
314 if method not in HTTP_METHODS or not isinstance(operation, dict):
315 continue
316 snapshot.operations[(str(path), method)] = Operation(
317 operation_id=operation.get("operationId"),
318 request_schema=extract_request_schema(operation),
319 response_schemas=extract_response_schemas(operation),
320 )
321
322 schemas = ((spec.get("components") or {}).get("schemas") or {})
323 if isinstance(schemas, dict):
324 for schema_name, schema in schemas.items():
325 schema_name = str(schema_name)
326 snapshot.schemas.add(schema_name)
327 snapshot.schema_required.setdefault(schema_name, set())
328 snapshot.schema_properties.setdefault(schema_name, {})
329 if not isinstance(schema, dict):
330 continue
331
332 signature = schema_signature(schema)
333 if signature:
334 snapshot.schema_signatures[schema_name] = signature
335
336 required = schema.get("required") or []
337 if isinstance(required, list):
338 snapshot.schema_required[schema_name].update(str(field_name) for field_name in required)
339
340 properties = schema.get("properties") or {}
341 if isinstance(properties, dict):
342 for property_name, property_schema in properties.items():
343 signature = schema_signature(property_schema)
344 if signature:
345 snapshot.schema_properties[schema_name][str(property_name)] = signature
346
347 return snapshot
348
349
350def operation_key(path: str, method: str) -> str:

Calls 7

OpenApiSnapshotClass · 0.85
OperationClass · 0.85
extract_request_schemaFunction · 0.85
extract_response_schemasFunction · 0.85
schema_signatureFunction · 0.85
getMethod · 0.45
updateMethod · 0.45