From 71bd3cbb6a927dd6654164fe42023aa1a45c6ca2 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 15 Sep 2025 11:36:13 +0200 Subject: [PATCH] OpenAPI spec check improvements --- changedetectionio/api/__init__.py | 11 ++++++++--- docs/api-spec.yaml | 27 ++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/changedetectionio/api/__init__.py b/changedetectionio/api/__init__.py index c3c4fc945..94f234fb5 100644 --- a/changedetectionio/api/__init__.py +++ b/changedetectionio/api/__init__.py @@ -51,12 +51,17 @@ def validate_openapi_request(operation_id): openapi_request = FlaskOpenAPIRequest(request) result = spec.unmarshal_request(openapi_request) if result.errors: - abort(400, message=f"OpenAPI validation failed: {result.errors}") - return f(*args, **kwargs) + from flask import jsonify + from werkzeug.exceptions import BadRequest + error_details = [] + for error in result.errors: + error_details.append(str(error)) + raise BadRequest(f"OpenAPI validation failed: {error_details}") except Exception as e: - # If OpenAPI validation fails, log but don't break existing functionality + # If OpenAPI spec loading fails, log but don't break existing functionality logger.critical(f"OpenAPI validation warning for {operation_id}: {e}") abort(500) + return f(*args, **kwargs) return wrapper return decorator diff --git a/docs/api-spec.yaml b/docs/api-spec.yaml index 11584984f..6417cfddd 100644 --- a/docs/api-spec.yaml +++ b/docs/api-spec.yaml @@ -224,8 +224,6 @@ components: maxLength: 5000 required: [operation, selector, optional_value] description: Browser automation steps - required: - - url Watch: allOf: @@ -261,6 +259,16 @@ components: required: - url + UpdateWatch: + allOf: + - $ref: '#/components/schemas/WatchBase' + - type: object + properties: + last_viewed: + type: integer + description: Unix timestamp in seconds of the last time the watch was viewed. Setting it to a value higher than `last_changed` in the "Update watch" endpoint marks the watch as viewed. + minimum: 0 + Tag: type: object properties: @@ -281,8 +289,13 @@ components: notification_muted: type: boolean description: Whether notifications are muted for this tag - required: - - title + + CreateTag: + allOf: + - $ref: '#/components/schemas/Tag' + - type: object + required: + - title NotificationUrls: type: object @@ -572,7 +585,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Watch' + $ref: '#/components/schemas/UpdateWatch' responses: '200': description: Web page change monitor (watch) updated successfully @@ -815,7 +828,7 @@ paths: 'Content-Type': 'application/json' } data = {'title': 'Important Sites'} - response = requests.post('http://localhost:5000/api/v1/tag', + response = requests.post('http://localhost:5000/api/v1/tag', headers=headers, json=data) print(response.json()) requestBody: @@ -823,7 +836,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Tag' + $ref: '#/components/schemas/CreateTag' example: title: "Important Sites" responses: