Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove allowedDefaultRefs #255

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions docs/custom-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,46 @@ app.use('some', new SomeService(options), {

<!-- tabs:end -->

<!-- tabs:start -->
### **How to document custom methods**

`feathers-swagger` allows you to pass a `Request` and `Response` schema to document what your custom method expects and returns.

```typescript
export const userApproveRequest = Type.Object(
{
userMessage: Type.String({
description: 'A message by the user'
})
},
{
$id: 'userApproveRequest',
additionalProperties: false
}
)

export const userApproveResponse = Type.Object(
{
successMessage: Type.String()
},
{
$id: 'userApproveResponse',
additionalProperties: false
}
)
```

In `createSwaggerServiceOptions` you can pass these new schemas

```typescript
docs: createSwaggerServiceOptions({
schemas: {..., userApproveRequest, userApproveResponse},
...
})
```

<!-- tabs:end -->

## Example

Check out the [example](/examples/custom_methods.md) to see it in action.
Expand Down
26 changes: 1 addition & 25 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,6 @@ exports.idPathParameters = function idPathParameters (idName, idSeparator) {
return `{${Array.isArray(idName) ? idName.join(`}${idSeparator}{`) : idName}}`;
};

const allowedDefaultRefs = [
'findResponse',
'getResponse',
'createRequest',
'createResponse',
'createMultiRequest',
'createMultiResponse',
'updateRequest',
'updateResponse',
'updateMultiRequest',
'updateMultiResponse',
'patchRequest',
'patchResponse',
'patchMultiRequest',
'patchMultiResponse',
'removeResponse',
'removeMultiResponse',
'filterParameter',
'sortParameter',
'queryParameters'
];

exports.defaultTransformSchema = function defaultTransformSchema (schema) {
const allowedProperties = pick(schema, [
'title',
Expand Down Expand Up @@ -235,9 +213,7 @@ exports.createSwaggerServiceOptions = function createSwaggerServiceOptions ({ sc
const schemaName = schema.$id;
if (schemaName) {
serviceDocs.schemas[schemaName] = transformSchemaFn(schema);
if (allowedDefaultRefs.includes(key)) {
serviceDocs.refs[key] = schemaName;
}
serviceDocs.refs[key] = schemaName;
}
});

Expand Down
Loading