From e767c0ba237b7b1d1b66f01225f1de8b8b7fa21c Mon Sep 17 00:00:00 2001 From: Wouter Bohlken Date: Mon, 11 Dec 2023 17:15:51 +0100 Subject: [PATCH] Add option to generate objects as schemas instead of x-objects --- config/swagger-generator.php | 6 ++++++ src/Describer/CollectsClassReferences.php | 3 ++- src/RoutesParser.php | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config/swagger-generator.php b/config/swagger-generator.php index 9c40b23..b0775fb 100644 --- a/config/swagger-generator.php +++ b/config/swagger-generator.php @@ -77,6 +77,12 @@ 'ignoredAnnotationNames' => ['mixin'], /* |--------------------------------------------------------- + | Generate objects inside 'components.schemas' instead of 'components.x-objects' + |--------------------------------------------------------- + */ + 'generateObjectsAsSchemas' => false, + /* + |--------------------------------------------------------- | List of classes to additionally generate definitions |--------------------------------------------------------- | diff --git a/src/Describer/CollectsClassReferences.php b/src/Describer/CollectsClassReferences.php index fe7a03c..fac3043 100644 --- a/src/Describer/CollectsClassReferences.php +++ b/src/Describer/CollectsClassReferences.php @@ -122,7 +122,8 @@ private static function getCollectedClassReferenceName(string $className, array return static::$collectedClassReferencesKeys[$classNameWithAttributes]; } $classNameSafe = str_replace(['\\', '.'], '_', $classNameWithAttributes); - $keys = ['components', RoutesParser::COMPONENT_OBJECTS, $classNameSafe]; + $componentsKey = config('swagger-generator.generateObjectsAsSchemas', false) ? RoutesParser::COMPONENT_SCHEMAS : RoutesParser::COMPONENT_OBJECTS; + $keys = ['components', $componentsKey, $classNameSafe]; return static::$collectedClassReferencesKeys[$classNameWithAttributes] = '#/' . implode('/', $keys); } diff --git a/src/RoutesParser.php b/src/RoutesParser.php index 9c51336..7779094 100644 --- a/src/RoutesParser.php +++ b/src/RoutesParser.php @@ -34,6 +34,7 @@ class RoutesParser const COMPONENT_REQUESTS = 'requestBodies'; const COMPONENT_PARAMETER = 'parameters'; const COMPONENT_OBJECTS = 'x-objects'; + const COMPONENT_SCHEMAS = 'schemas'; const PROBLEM_NO_RESPONSE = 'no_response'; const PROBLEM_ROUTE_CLOSURE = 'route_closure';