Skip to content

Commit

Permalink
fix: fix callbacks type def
Browse files Browse the repository at this point in the history
fixes #171
  • Loading branch information
RomanHotsiy committed Jul 24, 2020
1 parent fa60482 commit f2ea7f9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/rules/common/path-not-include-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { UserContext } from '../../walk';

export const PathNotIncludeQuery: Oas3Rule | Oas2Rule = () => {
return {
PathItem(_operation: object, { report, key }: UserContext) {
if (key.toString().includes('?')) {
report({
message: `Don't put query string items in the path, they belong in parameters with \`in: query\`.`,
location: { reportOnKey: true },
});
}
},
PathMap: {
PathItem(_operation: object, { report, key }: UserContext) {
if (key.toString().includes('?')) {
report({
message: `Don't put query string items in the path, they belong in parameters with \`in: query\`.`,
location: { reportOnKey: true },
});
}
},
}
};
};
41 changes: 41 additions & 0 deletions src/rules/oas3/__tests__/spec/callbacks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { outdent } from 'outdent';
import { validateDoc } from './utils';

it('should not fail on valid callbacks object', async () => {
const source = outdent`
openapi: 3.0.2
info:
title: Test
version: '1.0'
servers:
- url: http://google.com
paths:
'/ping':
summary: test
get:
callbacks:
test:
'http://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}':
post:
requestBody:
description: Callback payload
content:
'application/json':
schema:
$ref: '#/components/schemas/SomePayload'
responses:
'200':
description: webhook successfully processed and no retries will be performed
responses:
'200':
description: example description
`;

expect(
await validateDoc(source, {
spec: 'error',
}),
).toMatchInlineSnapshot(`Array []`);
});
8 changes: 7 additions & 1 deletion src/types/oas3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ const Parameter: NodeType = {
required: ['name', 'in'],
};

const Callback = {
properties: {},
additionalProperties: 'PathItem'
}

const Operation: NodeType = {
properties: {
tags: {
Expand All @@ -207,7 +212,7 @@ const Operation: NodeType = {
deprecated: {
type: 'boolean',
},
callbacks: 'PathMap',
callbacks: mapOf('Callback'),
'x-codeSamples': listOf('XCodeSample'),
'x-code-samples': listOf('XCodeSample'), // deprecated
},
Expand Down Expand Up @@ -536,6 +541,7 @@ export const Oas3Types: Record<string, NodeType> = {
PathItem,
Parameter,
Operation,
Callback,
RequestBody,
MediaTypeMap,
MediaType,
Expand Down
1 change: 1 addition & 0 deletions src/visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type Oas3FlatVisitor = {
License?: VisitFunctionOrObject<Oas3License>;
PathMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
PathItem?: VisitFunctionOrObject<Oas3PathItem>;
Callback?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
Parameter?: VisitFunctionOrObject<Oas3Parameter>;
Operation?: VisitFunctionOrObject<Oas3Operation>;
RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;
Expand Down

0 comments on commit f2ea7f9

Please sign in to comment.