Skip to content

Commit c389d10

Browse files
danielsharveytheoomoregbee
authored andcommitted
feat: Merge model attribute schemas to enable overrides by user
1 parent 66db3dd commit c389d10

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/generators.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,23 @@ export const generateSchemas = (models: NameKeyMap<SwaggerSailsModel>): NameKeyM
295295

296296
const schema: OpenApi.UpdatedSchema = {
297297
description: model.swagger.modelSchema?.description || `Sails ORM Model **${model.globalId}**`,
298+
properties: {},
298299
required: [],
299300
...omit(model.swagger?.modelSchema || {}, 'exclude', 'description', 'tags'),
300301
}
301302

302303
const attributes = model.attributes || {}
303-
schema.properties = Object.keys(attributes).reduce((props, attributeName) => {
304-
const attribute = model.attributes[attributeName];
305-
if(attribute.meta?.swagger?.exclude !== true) {
306-
props[attributeName] = generateAttributeSchema(attribute);
307-
if (attribute.required) schema.required!.push(attributeName);
308-
}
309-
return props
310-
}, {} as NameKeyMap<OpenApi.UpdatedSchema>)
304+
defaults(
305+
schema.properties,
306+
Object.keys(attributes).reduce((props, attributeName) => {
307+
const attribute = model.attributes[attributeName];
308+
if (attribute.meta?.swagger?.exclude !== true) {
309+
props[attributeName] = generateAttributeSchema(attribute);
310+
if (attribute.required) schema.required!.push(attributeName);
311+
}
312+
return props
313+
}, {} as NameKeyMap<OpenApi.UpdatedSchema>)
314+
);
311315

312316
if (schema.required!.length <= 0) delete schema.required;
313317

0 commit comments

Comments
 (0)