Skip to content

Commit

Permalink
feat(meta.swagger): Add support for swagger.exclude
Browse files Browse the repository at this point in the history
Improve support for excluding attributes based upon respective
`swagger.exclude` attributes (for blueprint select/omit examples).
  • Loading branch information
danielsharvey authored and theoomoregbee committed Jun 4, 2020
1 parent b6120a4 commit 2766182
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,15 @@ export const generatePaths = (routes: SwaggerRouteInfo[], templates: BlueprintAc

addSelectQueryParam: () => {
if (isParam('query', 'select')) return;
const attributes = route.model!.attributes || {};
const csv = reduce(attributes, (acc, a, n) => ((a.meta?.swagger?.exclude === true) ? acc : [...acc, n]), [] as string[]);
pathEntry.parameters.push({
in: 'query',
name: 'select',
required: false,
schema: {
type: 'string',
example: [...keys(route.model!.attributes || {})].join(','),
example: csv.join(','),
},
description: 'The attributes to include in the result, specified as a comma-delimited list.'
+ ' By default, all attributes are selected.'
Expand All @@ -358,13 +360,15 @@ export const generatePaths = (routes: SwaggerRouteInfo[], templates: BlueprintAc

addOmitQueryParam: () => {
if (isParam('query', 'omit')) return;
const attributes = route.model!.attributes || {};
const csv = reduce(attributes, (acc, a, n) => ((a.meta?.swagger?.exclude === true) ? acc : [...acc, n]), [] as string[]);
pathEntry.parameters.push({
in: 'query',
name: 'omit',
required: false,
schema: {
type: 'string',
example: [...keys(route.model!.attributes || {})].join(','),
example: csv.join(','),
},
description: 'The attributes to exclude from the result, specified as a comma-delimited list.'
+ ' Cannot be used in conjuction with `select`.'
Expand Down

0 comments on commit 2766182

Please sign in to comment.