File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ from apispec .ext .marshmallow import (
2+ MarshmallowPlugin as _MarshmallowPlugin ,
3+ OpenAPIConverter ,
4+ )
5+ from labthings .server .fields import Bytes as BytesField
6+
7+
8+ class ExtendedOpenAPIConverter (OpenAPIConverter ):
9+ field_mapping = OpenAPIConverter .field_mapping
10+ field_mapping .update ({BytesField : ("string" , None )})
11+
12+ def init_attribute_functions (self , * args , ** kwargs ):
13+ OpenAPIConverter .init_attribute_functions (self , * args , ** kwargs )
14+ self .attribute_functions .append (self .bytes2json )
15+
16+ def bytes2json (self , field , ** kwargs ):
17+ ret = {}
18+ if isinstance (field , BytesField ):
19+ ret .update ({"contentEncoding" : "base64" })
20+ return ret
21+
22+
23+ class MarshmallowPlugin (_MarshmallowPlugin ):
24+ Converter = ExtendedOpenAPIConverter
You can’t perform that action at this time.
0 commit comments