Skip to content

Python: added operationid validation in openapi spec #12551

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def create_rest_api_operations(

paths = parsed_document.get("paths", {})
request_objects = {}
unique_operation_ids_registered: set[str] = set()

servers = parsed_document.get("servers", [])

Expand All @@ -230,7 +231,15 @@ def create_rest_api_operations(
for path, methods in paths.items():
for method, details in methods.items():
request_method = method.lower()
operationId = details.get("operationId", path + "_" + request_method)
# Validate that operationId exists
if "operationId" not in details:
raise PluginInitializationError(f"operationId missing, path: '{path}', method: '{method}'")
operationId = details["operationId"]
if operationId in unique_operation_ids_registered:
raise PluginInitializationError(
f"Duplicate operationId: '{operationId}', path: '{path}', method: '{method}'"
)
unique_operation_ids_registered.add(operationId)

summary = details.get("summary", None)
description = details.get("description", None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.3
info:
title: Simple HTTPBin API
version: 1.0.0

servers:
- url: https://httpbin.org

paths:
/get:
get:
operationId: duplicateId
summary: Simple GET request to httpbin.org
responses:
'200':
description: Successful response from httpbin
content:
application/json:
schema:
type: object

/ip:
get:
operationId: duplicateId
summary: Get client IP address from httpbin
responses:
'200':
description: Successful response with IP
content:
application/json:
schema:
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.3
info:
title: Simple HTTPBin API
version: 1.0.0
servers:
- url: https://httpbin.org
paths:
/get:
get:
summary: Simple GET request to httpbin.org
responses:
'200':
description: Successful response from httpbin
content:
application/json:
schema:
type: object
Loading