diff --git a/cog_safe_push/schema.py b/cog_safe_push/schema.py index 924a14d..0bcd722 100644 --- a/cog_safe_push/schema.py +++ b/cog_safe_push/schema.py @@ -13,6 +13,8 @@ def lint(model: Model, train: bool): schema = get_openapi_schema(model) properties = schema["components"]["schemas"][input_name]["properties"] for name, spec in properties.items(): + if spec.get("deprecated", False): + continue description = spec.get("description") if not description: errors.append(f"{name}: Missing description") diff --git a/test/test_schema.py b/test/test_schema.py index 73ced9d..037d645 100644 --- a/test/test_schema.py +++ b/test/test_schema.py @@ -1,6 +1,13 @@ +from unittest.mock import Mock + import pytest -from cog_safe_push.schema import IncompatibleSchemaError, check_backwards_compatible +from cog_safe_push.schema import ( + IncompatibleSchemaError, + SchemaLintError, + check_backwards_compatible, + lint, +) def test_identical_schemas(): @@ -193,3 +200,59 @@ def test_multiple_incompatibilities(): assert "Input choice is missing choices: 'C'" in error_message assert "Input new_required is new and is required" in error_message assert "Output has changed type" in error_message + + +def test_lint_deprecated_input_without_description(): + mock_model = Mock() + mock_model.versions.list.return_value = [ + Mock( + openapi_schema={ + "components": { + "schemas": { + "Input": { + "properties": { + "steps": { + "type": "integer", + "minimum": 1, + "maximum": 50, + "default": 25, + "deprecated": True, + }, + "prompt": { + "type": "string", + "description": "The prompt to use", + }, + } + } + } + } + } + ) + ] + lint(mock_model, train=False) + + +def test_lint_non_deprecated_input_without_description(): + mock_model = Mock() + mock_model.versions.list.return_value = [ + Mock( + openapi_schema={ + "components": { + "schemas": { + "Input": { + "properties": { + "steps": { + "type": "integer", + "minimum": 1, + "maximum": 50, + "default": 25, + }, + } + } + } + } + } + ) + ] + with pytest.raises(SchemaLintError, match="steps: Missing description"): + lint(mock_model, train=False)