At least solving 2 of your questions:
- How many resource-URIs (paths) ?
- Which HTTP-methods per path (operations) ?
From the docs on Paths and Operations:
In Swagger terms, paths are endpoints (resources) that your API exposes, such as /users or /reports/summary, and operations are the HTTP methods used to manipulate these paths, such as GET, POST or DELETE.
from swagger_parser import SwaggerParser
# condensed format (all operations in line with the path)
def operations_per_path(specification):
base = specification['basePath']
paths = specification['paths']
ops = []
for p in paths:
methods = paths[p].keys() # methods are keys inside a single path-dict
ops.append(f"{'|'.join(methods).upper()} {base}{p}")
return ops
def count_operations(specification):
paths = specification['paths']
return sum([len(paths[p].keys()) for p in paths])
parser = SwaggerParser(swagger_path='Downloads/swagger-sample.json') # Init with file
spec = parser.specification
print("Operations in swagger (resource-URIs with their HTTP-methods):")
ops_count = count_operations(spec)
paths = operations_per_path(spec)
print(f"\t{ops_count} operations, {len(paths)} paths")
print("\n".join(paths))
Applied to the Petstore example-swagger it prints:
Operations in swagger (resource-URIs with their HTTP-methods):
20 operations, 14 paths
POST|PUT /v2/pet
GET /v2/pet/findByStatus
GET /v2/pet/findByTags
GET|POST|DELETE /v2/pet/{petId}
POST /v2/pet/{petId}/uploadImage
GET /v2/store/inventory
POST /v2/store/order
GET|DELETE /v2/store/order/{orderId}
POST /v2/user
POST /v2/user/createWithArray
POST /v2/user/createWithList
GET /v2/user/login
GET /v2/user/logout
GET|PUT|DELETE /v2/user/{username}
Neither the third question for each method's request and response, nor the puzzle to find the related request (method, URI) to a given response part is solved yet.