File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -319,6 +319,10 @@ blueprint action from the generated Swagger. See example in [OldPet.js](api/mode
319
319
Individual model attributes may be excluded from the generated Swagger by setting
320
320
` meta.swagger.exclude ` to ` true ` . See example in [ Pet.js] ( api/models/Pet.js ) .
321
321
322
+ OpenAPI 3 specifies the *** Any Type*** by the absence of the ` type ` property in a schema;
323
+ this may be achieved by setting a model attribute's ` meta.swagger.type ` value to ` null ` .
324
+ See example in [ User.js] ( api/models/User.js ) .
325
+
322
326
The Swagger definition for each action is merged in the order above to form the final
323
327
definition, with ` config/routes.js ` taking highest precendence and ** earlier** definitions
324
328
above taking precedence over later.
Original file line number Diff line number Diff line change @@ -39,7 +39,10 @@ export const generateAttributeSchema = (attribute: Sails.AttributeDefinition): O
39
39
return ret . join ( ' ' ) ;
40
40
}
41
41
42
- if ( ai . model ) {
42
+ if ( ai . meta ?. swagger && 'type' in ai . meta . swagger ) {
43
+ // OpenAPI 3 stipulates NO type as 'any', allow this by 'type' present but null to achieve this
44
+ if ( ai . meta . swagger . type ) schema . type = ai . meta . swagger . type ;
45
+ } else if ( ai . model ) {
43
46
assign ( schema , {
44
47
description : formatDesc ( `JSON dictionary representing the **${ ai . model } ** instance or FK when creating / updating / not populated` ) ,
45
48
// '$ref': '#/components/schemas/' + ai.model,
@@ -146,7 +149,8 @@ export const generateAttributeSchema = (attribute: Sails.AttributeDefinition): O
146
149
147
150
// finally, overwrite in custom swagger
148
151
if ( ai . meta ?. swagger ) {
149
- assign ( schema , omit ( ai . meta . swagger , 'exclude' ) ) ;
152
+ // note: 'type' handled above
153
+ assign ( schema , omit ( ai . meta . swagger , 'exclude' , 'type' ) ) ;
150
154
}
151
155
152
156
return schema ;
You can’t perform that action at this time.
0 commit comments