Skip to content

Commit

Permalink
fix: Ensure that Operation ID is an optional value (#178)
Browse files Browse the repository at this point in the history
Previously on fixing spec operations *rororo* assumes that operation ID
is always present, but due to specification `operationId` should be
treat as an optional value and may be missed for some, not yet
implemented operations.

This commit fixes the assumption by treating `operationId` as an
optional value.
  • Loading branch information
playpauseandstop committed May 9, 2021
1 parent da3565b commit 1279714
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
rev: "5.8.0"
hooks:
- id: "isort"
name: "Format backend code (isort)"
name: "Format code (isort)"
exclude: ^docs/.*$

- repo: "https://github.com/psf/black"
Expand Down
24 changes: 24 additions & 0 deletions examples/hobotnica/src/hobotnica/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ paths:
schema:
$ref: "#/components/schemas/AnyObject"

"/webhooks/{webhook_uid}":
parameters:
- $ref: "#/components/parameters/WebhookUID"

post:
tags: ["webhook"]
summary: "React on GitHub webhook payload by running registered job (not yet implemented)"
responses:
<<: *default_responses
"200":
description: "Build details"
content:
application/json:
schema:
$ref: "#/components/schemas/AnyObject"

components:
parameters:
GitHubUsername:
Expand Down Expand Up @@ -202,6 +218,14 @@ components:
schema:
$ref: "#/components/schemas/RepositoryName"

WebhookUID:
name: "webhook_uid"
in: "path"
required: true
schema:
type: "string"
format: "uuid"

responses:
DefaultResponse:
description: "Default error response"
Expand Down
11 changes: 8 additions & 3 deletions src/rororo/openapi/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,20 @@ def fix_spec_operations(spec: Spec, schema: DictStrAny) -> Spec:
if not isinstance(maybe_operation_data, dict):
continue

mapping[
maybe_operation_data["operationId"]
] = maybe_operation_data.get("security")
operation_id = maybe_operation_data.get("operationId")
if operation_id is None:
continue

mapping[operation_id] = maybe_operation_data.get("security")

for path in spec.paths.values():
for operation in path.operations.values():
if operation.security != []:
continue

if operation.operation_id is None:
continue

operation.security = mapping[operation.operation_id]

return spec
Expand Down

0 comments on commit 1279714

Please sign in to comment.