File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,7 @@ public function getProcessors(): array
191
191
new Processors \MergeXmlContent (),
192
192
new Processors \OperationId (),
193
193
new Processors \CleanUnmerged (),
194
+ new Processors \BackportConstants (),
194
195
];
195
196
}
196
197
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ /**
4
+ * @license Apache 2.0
5
+ */
6
+
7
+ namespace OpenApi \Processors ;
8
+
9
+ use OpenApi \Analysis ;
10
+ use OpenApi \Annotations \OpenApi ;
11
+ use OpenApi \Annotations \Property as AnnotationSchema ;
12
+ use OpenApi \Attributes \Property as AttributeSchema ;
13
+ use OpenApi \Generator ;
14
+
15
+ /**
16
+ * Transform const keywords to enum in OpenApi versions < 3.1.0.
17
+ */
18
+ class BackportConstants
19
+ {
20
+ public function __invoke (Analysis $ analysis )
21
+ {
22
+ /** @var AnnotationSchema[] $schemas */
23
+ $ schemas = $ analysis ->getAnnotationsOfType ([AnnotationSchema::class, AttributeSchema::class], true );
24
+
25
+ foreach ($ schemas as $ schema ) {
26
+ if (Generator::isDefault ($ schema ->const )) {
27
+ continue ;
28
+ }
29
+
30
+ if (version_compare ($ analysis ->context ->version , OpenApi::VERSION_3_1_0 , '< ' )) {
31
+ $ schema ->type = 'enum ' ;
32
+ $ schema ->enum = [$ schema ->const ];
33
+ $ schema ->const = Generator::UNDEFINED ;
34
+ }
35
+ }
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments