Skip to content

Commit 31399da

Browse files
committed
feat: only generate docs for methods that are in the serviceOptions methods
1 parent 3cf6c6b commit 31399da

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

lib/openapi.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const utils = require('./utils');
33
const { assignWithSet } = require('./helpers');
44
const { getCustomMethods } = require('./custom-methods');
55

6+
const serviceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'];
7+
68
const defaultMethods = [
79
{ operation: 'find', method: 'find', id: false, httpMethod: 'get', multi: false },
810
{ operation: 'get', method: 'get', id: true, httpMethod: 'get', multi: false },
@@ -136,6 +138,16 @@ class OpenApiGenerator {
136138
if (doc.operations === undefined) {
137139
doc.operations = {};
138140
}
141+
142+
// disable methods that are not defined for feathers 5
143+
if (serviceOptions && Array.isArray(serviceOptions.methods)) {
144+
serviceMethods.forEach(serviceMethod => {
145+
if (!serviceOptions.methods.includes(serviceMethod)) {
146+
doc.operations[serviceMethod] = false;
147+
}
148+
});
149+
}
150+
139151
const idName = service.id || 'id';
140152
const idType = doc.idType || this.config.idType || 'integer';
141153
let version = this.config.versionPrefix ? path.match(this.config.versionPrefix) : null;

test/v3/generator.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,42 @@ describe('openopi v3 generator', function () {
12541254
});
12551255
});
12561256
});
1257+
1258+
describe('serviceOptions (v5)', () => {
1259+
it('should consume consume docs from serviceOptions', () => {
1260+
delete service.docs;
1261+
gen.addService(service, 'message', {
1262+
methods: ['find', 'get'],
1263+
events: [],
1264+
docs: {
1265+
description: 'my custom description'
1266+
}
1267+
});
1268+
1269+
expect(specs.tags).to.deep.equal([
1270+
{
1271+
description: 'my custom description',
1272+
name: 'message'
1273+
}
1274+
]);
1275+
expect(specs.paths['/message'].get).to.exist;
1276+
expect(specs.paths['/message/{id}'].get).to.exist;
1277+
});
1278+
1279+
it('should disable methods that are missing from methods array', () => {
1280+
delete service.docs;
1281+
gen.addService(service, 'message', {
1282+
methods: ['find'],
1283+
events: [],
1284+
docs: {
1285+
description: 'my custom description'
1286+
}
1287+
});
1288+
1289+
expect(specs.paths['/message'].get).to.exist;
1290+
expect(specs.paths['/message/{id}']).to.not.exist;
1291+
});
1292+
});
12571293
});
12581294

12591295
describe('custom methods', function () {

0 commit comments

Comments
 (0)