15
15
import io .swagger .oas .models .links .Link ;
16
16
import io .swagger .oas .models .media .ArraySchema ;
17
17
import io .swagger .oas .models .media .Content ;
18
+ import io .swagger .oas .models .media .Encoding ;
19
+ import io .swagger .oas .models .media .Encoding .StyleEnum ;
18
20
import io .swagger .oas .models .media .MediaType ;
19
21
import io .swagger .oas .models .media .Schema ;
20
22
import io .swagger .oas .models .parameters .Parameter ;
@@ -429,6 +431,10 @@ public static Optional<Content> getContent(io.swagger.oas.annotations.media.Cont
429
431
for (ExampleObject example : examples ) {
430
432
ParameterProcessor .getExample (example ).ifPresent (exampleObject -> mediaType .addExamples (example .name (), exampleObject ));
431
433
}
434
+ io .swagger .oas .annotations .media .Encoding [] encodings = annotationContent .encoding ();
435
+ for (io .swagger .oas .annotations .media .Encoding encoding : encodings ) {
436
+ addEncodingToMediaType (mediaType , encoding , components );
437
+ }
432
438
if (StringUtils .isNotBlank (annotationContent .mediaType ())) {
433
439
content .addMediaType (annotationContent .mediaType (), mediaType );
434
440
} else {
@@ -504,6 +510,36 @@ public static Optional<Header> getHeader(io.swagger.oas.annotations.headers.Head
504
510
return Optional .of (headerObject );
505
511
}
506
512
513
+ public static void addEncodingToMediaType (MediaType mediaType , io .swagger .oas .annotations .media .Encoding encoding , Components components ) {
514
+ if (encoding == null ) {
515
+ return ;
516
+ }
517
+ if (StringUtils .isNotBlank (encoding .name ())) {
518
+
519
+ Encoding encodingObject = new Encoding ();
520
+
521
+ if (StringUtils .isNotBlank (encoding .contentType ())) {
522
+ encodingObject .setContentType (encoding .contentType ());
523
+ }
524
+ if (StringUtils .isNotBlank (encoding .style ())) {
525
+ encodingObject .setStyle (StyleEnum .valueOf (encoding .style ()));
526
+ }
527
+ if (encoding .explode ()) {
528
+ encodingObject .setExplode (encoding .explode ());
529
+ }
530
+ if (encoding .allowReserved ()) {
531
+ encodingObject .setAllowReserved (encoding .allowReserved ());
532
+ }
533
+
534
+ if (encoding .headers () != null ) {
535
+ getHeaders (encoding .headers (), components ).ifPresent (encodingObject ::headers );
536
+ }
537
+
538
+ mediaType .addEncoding (encoding .name (), encodingObject );
539
+ }
540
+
541
+ }
542
+
507
543
public static Optional <Schema > getSchema (io .swagger .oas .annotations .media .Content annotationContent , Components components ) {
508
544
Class <?> schemaImplementation = annotationContent .schema ().implementation ();
509
545
Map <String , Schema > schemaMap ;
@@ -676,4 +712,4 @@ public static Map<String, String> getLinkParameters(LinkParameter[]
676
712
677
713
return linkParametersMap ;
678
714
}
679
- }
715
+ }
0 commit comments