feat: allow disabling of methods from defaults by Mairu · Pull Request #234 · feathersjs-ecosystem/feathers-swagger · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
4 changes: 4 additions & 0 deletions lib/openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ class OpenApiGenerator {
defaults = generator(methodIdName ? { ...defaultArgumentObject, idName: methodIdName } : defaultArgumentObject);
}

if (defaults === false || this.config.defaults.operations[method] === false) {
return;
}

if (typeof this.config.defaults.operations[method] === 'object') {
assignWithSet(defaults, this.config.defaults.operations[method]);
}
Expand Down
6 changes: 6 additions & 0 deletions test/v3/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ describe('openopi v3 generator', function () {
description: 'Only description'
};
},
get (options) {
return false;
},
custom (options) {
return {
description: 'Only custom description'
Expand All @@ -524,6 +527,7 @@ describe('openopi v3 generator', function () {
tags: [],
security: []
});
expect(specs.paths['/message/{id}']).to.not.exist;
expect(specs.paths['/message/custom'].post).to.deep.equal({
parameters: [],
responses: {},
Expand All @@ -545,6 +549,7 @@ describe('openopi v3 generator', function () {
find: {
description: 'Other description for find'
},
get: false,
customMethod: {
description: 'Description for specific custom method'
}
Expand All @@ -555,6 +560,7 @@ describe('openopi v3 generator', function () {
gen.addService(service, 'message');

expect(specs.paths['/message'].get.description).to.equal('Other description for find');
expect(specs.paths['/message/{id}']).to.not.exist;
expect(specs.paths['/message/custom'].post.description).to.equal('Description for specific custom method');
});

Expand Down
46 changes: 24 additions & 22 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ type FnOperationSpecsGeneratorOptions = {
} & UnknownObject;

interface FnOperationSpecsGenerator {
(options: FnOperationSpecsGeneratorOptions): UnknownObject;
(options: FnOperationSpecsGeneratorOptions): OperationConfig;
}

interface FnCustomOperationSpecsGenerator {
(options: FnOperationSpecsGeneratorOptions, customMethodOptions: {
method: string,
httpMethod: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'connect' | 'trace',
withId: boolean,
}): UnknownObject;
}): OperationConfig;
}

interface ExternalDocs {
Expand All @@ -95,6 +95,8 @@ type SpecsObject = {

type OpenApiVersion = 2 | 3;

type OperationConfig = UnknownObject | false;

declare namespace feathersSwagger {
interface SwaggerInitOptions {
specs: SpecsObject;
Expand Down Expand Up @@ -131,17 +133,17 @@ declare namespace feathersSwagger {
custom?: FnCustomOperationSpecsGenerator;
}
operations?: {
find?: UnknownObject;
get?: UnknownObject;
create?: UnknownObject;
update?: UnknownObject;
patch?: UnknownObject;
remove?: UnknownObject;
updateMulti?: UnknownObject;
patchMulti?: UnknownObject;
removeMulti?: UnknownObject;
find?: OperationConfig;
get?: OperationConfig;
create?: OperationConfig;
update?: OperationConfig;
patch?: OperationConfig;
remove?: OperationConfig;
updateMulti?: OperationConfig;
patchMulti?: OperationConfig;
removeMulti?: OperationConfig;
all?: UnknownObject;
[customMethod: string]: UnknownObject | undefined;
[customMethod: string]: OperationConfig | undefined;
}
multi?: MultiOperations;
};
Expand Down Expand Up @@ -173,17 +175,17 @@ declare namespace feathersSwagger {
overwriteTagSpec?: boolean;
multi?: MultiOperations;
operations?: {
find?: UnknownObject | false;
get?: UnknownObject | false;
create?: UnknownObject | false;
update?: UnknownObject | false;
patch?: UnknownObject | false;
remove?: UnknownObject | false;
updateMulti?: UnknownObject | false;
patchMulti?: UnknownObject | false;
removeMulti?: UnknownObject | false;
find?: OperationConfig;
get?: OperationConfig;
create?: OperationConfig;
update?: OperationConfig;
patch?: OperationConfig;
remove?: OperationConfig;
updateMulti?: OperationConfig;
patchMulti?: OperationConfig;
removeMulti?: OperationConfig;
all?: UnknownObject;
[customOperation: string]: UnknownObject | false | undefined;
[customOperation: string]: OperationConfig | undefined;
};
}

Expand Down
46 changes: 44 additions & 2 deletions types/index.test-d.ts