From d1fc3b33241dc43f554c60df4dca43ce778dbfd7 Mon Sep 17 00:00:00 2001 From: Roberto Prevato Date: Sat, 7 Mar 2026 10:52:33 +0100 Subject: [PATCH 1/3] Fix enum without explicit type rendering as null (issue #64) When a schema uses 'enum' without a 'type' field (valid JSON Schema), get_example_from_schema fell through to 'return None' because there was no type to dispatch to a ScalarExampleHandler. The enum check in ScalarExampleHandler.get_example was never reached. Fix: add an early enum check in get_example_from_schema itself, after the 'examples' check and before the type dispatch, so typeless enums also return their first value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- openapidocs/mk/v3/examples.py | 5 +++++ tests/test_oas31.py | 3 +++ 2 files changed, 8 insertions(+) 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): From f3112c6e3fd477f8080a8a0e9d73504277a8cbfb Mon Sep 17 00:00:00 2001 From: Roberto Prevato Date: Sat, 7 Mar 2026 10:55:35 +0100 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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. From bc24e667e536336dc1d798071faed11862d644b5 Mon Sep 17 00:00:00 2001 From: Roberto Prevato Date: Sat, 7 Mar 2026 10:55:45 +0100 Subject: [PATCH 3/3] Update __init__.py --- openapidocs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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__