diff --git a/CHANGELOG.md b/CHANGELOG.md index 877b04b..6ceb8fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.4.1] - 2026-03-?? + +- Fix handling of `enum` without declared `type`, like reported in [#64](https://github.com/Neoteroi/essentials-openapi/issues/64) by @jan-ldwg. + ## [1.4.0] - 2026-03-07 :copilot: - Add OAS 3.1 support, cross-version warnings, and fix nullable spacing, by @dcode. diff --git a/openapidocs/__init__.py b/openapidocs/__init__.py index 39b806b..eb00ce3 100644 --- a/openapidocs/__init__.py +++ b/openapidocs/__init__.py @@ -1,2 +1,2 @@ -__version__ = "1.4.0" +__version__ = "1.4.1" VERSION = __version__ diff --git a/openapidocs/mk/v3/examples.py b/openapidocs/mk/v3/examples.py index 97463aa..8e44276 100644 --- a/openapidocs/mk/v3/examples.py +++ b/openapidocs/mk/v3/examples.py @@ -140,6 +140,11 @@ def get_example_from_schema(schema) -> Any: if isinstance(examples, list) and examples: return examples[0] + # enum without explicit type - return the first value directly + enum = schema.get("enum") + if isinstance(enum, list) and enum: + return enum[0] + # does it have a type? handlers_types: List[Type[SchemaExampleHandler]] = list( get_subclasses(SchemaExampleHandler) diff --git a/tests/test_oas31.py b/tests/test_oas31.py index 09268ca..0378633 100644 --- a/tests/test_oas31.py +++ b/tests/test_oas31.py @@ -187,6 +187,9 @@ class TestGetExampleFromSchemaAnnotations: ({"type": "boolean", "enum": [False]}, False), # enum on string (pre-existing behaviour still works) ({"type": "string", "enum": ["active", "inactive"]}, "active"), + # enum without explicit type (valid JSON Schema) + ({"enum": ["active", "inactive"]}, "active"), + ({"enum": [1, 2, 3]}, 1), ], ) def test_examples_and_enum(self, schema, expected):