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

Callbacks #716

Merged
merged 43 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
de73c0e
feat: runtime expressions resolver
karol-maciaszek Oct 18, 2019
90df29c
Merge branch 'master' into feat/webhooks
XVincentX Oct 19, 2019
1c95e55
chore: bits of callback implementation
karol-maciaszek Oct 24, 2019
fadcd2d
Merge commit '08aeb8219150c8ed25dc22d6b75035d239222749' into feat/web…
karol-maciaszek Oct 25, 2019
24c64eb
chore: refactored forwarder
karol-maciaszek Oct 25, 2019
842fa30
chore: callback improvements
karol-maciaszek Oct 25, 2019
5b986d9
fix: linting
karol-maciaszek Oct 25, 2019
4456b8b
test: part of tests
karol-maciaszek Oct 28, 2019
aa5641d
test: mocker tests, various fixes
karol-maciaszek Oct 29, 2019
f719250
chore: improvements in runtime expressions
karol-maciaszek Oct 29, 2019
667f64d
fix: further runtimeExpressions improvements
karol-maciaszek Oct 29, 2019
fca776f
chore: more changes in runtimeExpressions
karol-maciaszek Oct 29, 2019
bb9a203
Merge branch 'master' into feat/webhooks
karol-maciaszek Oct 29, 2019
aeb8383
chore: renamed util/response to utils/parseResponse
karol-maciaszek Oct 31, 2019
7e08a94
fix: improved typing
karol-maciaszek Oct 31, 2019
8b86b96
fix: auto-generation of content-type for callback request
karol-maciaszek Nov 4, 2019
cf0a87e
fix: fixed generation of content-type header
karol-maciaszek Nov 4, 2019
3756d2f
feat: added callback example
karol-maciaszek Nov 4, 2019
63b64ea
Merge branch 'master' into feat/webhooks
XVincentX Nov 4, 2019
0071ba3
Merge branch 'master' into feat/webhooks
XVincentX Nov 4, 2019
7f3f0bd
docs: improved callbacks documentation
karol-maciaszek Nov 5, 2019
cbec5f3
docs: further docs improvements
karol-maciaszek Nov 5, 2019
61ca306
fix: test description fixes
karol-maciaszek Nov 5, 2019
9429b8a
fix: added comment to runtime expressions
karol-maciaszek Nov 5, 2019
eaed708
chore: code style
karol-maciaszek Nov 5, 2019
8e0933b
fix: improvements on runtimeExpressions
karol-maciaszek Nov 5, 2019
e7f1cf4
fix: removed left-over
karol-maciaszek Nov 5, 2019
51c1ab3
fix: adjusted callbacks to recent validator refactor
karol-maciaszek Nov 5, 2019
9c3956c
fix: typing fix
karol-maciaszek Nov 5, 2019
76d92bb
fix: type fixes
karol-maciaszek Nov 5, 2019
28975cf
fix: improved test types
karol-maciaszek Nov 5, 2019
725f188
fix: more specific types
karol-maciaszek Nov 5, 2019
631560e
feat: introduced assertResolvesLeft and assertResolvesRight helper fu…
karol-maciaszek Nov 5, 2019
94f1396
chore: better den for fp assertion helpers
karol-maciaszek Nov 5, 2019
16dd64c
fix: improved fp usage
karol-maciaszek Nov 5, 2019
1acfa79
Merge branch 'master' into feat/webhooks
XVincentX Nov 5, 2019
511605d
Improve WebHooks calling chain (#772)
XVincentX Nov 6, 2019
7e18e19
docs: added callbacks limitations section
karol-maciaszek Nov 6, 2019
708ea09
fix: param generator input update
karol-maciaszek Nov 6, 2019
a5c7555
docs: docs improvements
karol-maciaszek Nov 6, 2019
b1de84e
docs: add comment
XVincentX Nov 6, 2019
a22024a
fix: more verbose error
karol-maciaszek Nov 6, 2019
80a92db
Merge branch 'feat/webhooks' of github.com:stoplightio/prism into fea…
karol-maciaszek Nov 6, 2019
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
2 changes: 1 addition & 1 deletion docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ prism mock https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.
● note DELETE http://127.0.0.1:4010/pets/10
```

The generated paths will have their parameters (query or path) bolded and in color.
The generated paths will have their parameters (query or path) bolded and in color.

Then in another tab, you can hit the HTTP server with your favorite HTTP client.

Expand Down
48 changes: 48 additions & 0 deletions examples/callbacks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Mocking Callbacks with Prism
karol-maciaszek marked this conversation as resolved.
Show resolved Hide resolved

This example shows how Prism mocks callbacks.
karol-maciaszek marked this conversation as resolved.
Show resolved Hide resolved

## Environment setup

Start service exposing `/subscribe` callback (referred as `4010`)

```bash
prism mock -p 4010 service.oas3.yaml
```

Start service exposing `/notify` operation used for receiving callback requests (referred as `4011`)

```bash
prism mock -p 4011 client.oas3.yaml
```
karol-maciaszek marked this conversation as resolved.
Show resolved Hide resolved

## Run!

Subscribe to callback

```bash
curl -v -H'Content-type: application/json' -d'{ "url": "http://localhost:4011/notify", "token": "ssecurre" }' http://127.0.0.1:4010/subscribe
```

Now, the console for `4010` service should show:
```$xslt
karol-maciaszek marked this conversation as resolved.
Show resolved Hide resolved
[HTTP SERVER] post /subscribe ℹ info Request received
[NEGOTIATOR] ℹ info Request contains an accept header: */*
[VALIDATOR] ✔ success The request passed the validation rules. Looking for the best response
[NEGOTIATOR] ✔ success Found a compatible content for */*
[NEGOTIATOR] ✔ success Responding with the requested status code 202
[CALLBACK] ℹ info actions: Making request to http://localhost:4011/notify?token=ssecurre...
[CALLBACK] ℹ info actions: Request finished
```

The console of `4011` service:

```
[HTTP SERVER] post /notify ℹ info Request received
[NEGOTIATOR] ℹ info Request contains an accept header: */*
[VALIDATOR] ✔ success The request passed the validation rules. Looking for the best response
[NEGOTIATOR] ✔ success Found a compatible content for */*
[NEGOTIATOR] ✔ success Responding with the requested status code 200
```

After subscribing via `/subscribe`, Prism successfully invoked `/notify` callback with mocked payload.
25 changes: 25 additions & 0 deletions examples/callbacks/client.oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
openapi: 3.0.0
paths:
/notify:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
action:
type: string
payload:
type: string
required:
- action
- payload
responses:
'200':
content:
text/plain:
examples:
ok:
value: 'ok'
52 changes: 52 additions & 0 deletions examples/callbacks/service.oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
openapi: 3.0.0
paths:
/subscribe:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
url:
type: string
format: uri
token:
type: string
required:
- url
- token
responses:
'202':
content:
text/plain:
examples:
ok:
value: 'ok'

callbacks:
actions:
'{$request.body#/url}?token={$request.body#/token}':
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
action:
type: string
payload:
type: string
required:
- action
- payload
responses:
200:
content:
text/plain:
examples:
ok:
value: 'ok'
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"bugs": "https://github.com/stoplightio/prism/issues",
"dependencies": {
"@stoplight/http-spec": "^2.2.3",
"@stoplight/prism-core": "^3.1.1",
"@stoplight/prism-http-server": "^3.1.1",
"chokidar": "^3.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/const/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const LOG_COLOR_MAP = {
'HTTP SERVER': { index: 0, color: chalk.bgYellowBright },
NEGOTIATOR: { index: 1, color: chalk.bgCyanBright },
VALIDATOR: { index: 1, color: chalk.bgGreenBright },
CALLBACK: { index: 1, color: chalk.bgBlue },
};
25 changes: 10 additions & 15 deletions packages/cli/src/util/__tests__/colorizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import {
PRE_PARAM_VALUE_TAG,
POST_PARAM_VALUE_TAG,
attachTagsToParamsValues,
transformPathParamsValues
transformPathParamsValues,
} from '../colorizer';

describe('colorizer', () => {

describe('transformPathParamsValues()', () => {
it('colorizes tagged values of query params', () => {
const path = `/no_auth/pets/findByStatus?status=${PRE_PARAM_VALUE_TAG}sold,pending${POST_PARAM_VALUE_TAG}`;

expect(transformPathParamsValues(path, chalk.bold.blue)).toBe(`/no_auth/pets/findByStatus?status=${chalk.bold.blue('sold,pending')}`);
expect(transformPathParamsValues(path, chalk.bold.blue)).toBe(
`/no_auth/pets/findByStatus?status=${chalk.bold.blue('sold,pending')}`
);
});

it('colorizes tagged values of path params', () => {
Expand All @@ -23,30 +24,25 @@ describe('colorizer', () => {
});

describe('attachTagsToParamsValues()', () => {

describe('adding tags', () => {
it('tags multiple values', () => {
const values = {
status: [
'available',
'pending',
'sold'
]
status: ['available', 'pending', 'sold'],
};

expect(attachTagsToParamsValues(values)).toStrictEqual({
status: [
`${PRE_PARAM_VALUE_TAG}available${POST_PARAM_VALUE_TAG}`,
`${PRE_PARAM_VALUE_TAG}pending${POST_PARAM_VALUE_TAG}`,
`${PRE_PARAM_VALUE_TAG}sold${POST_PARAM_VALUE_TAG}`
]
`${PRE_PARAM_VALUE_TAG}sold${POST_PARAM_VALUE_TAG}`,
],
});
});

describe('tagging single values', () => {
it('tags string values', () => {
const valuesOfParams = {
name: 'dignissimos'
name: 'dignissimos',
};

expect(attachTagsToParamsValues(valuesOfParams)).toStrictEqual({
Expand All @@ -56,11 +52,11 @@ describe('colorizer', () => {

it('tags numeric values', () => {
const valuesOfParams = {
petId: 170
petId: 170,
};

expect(attachTagsToParamsValues(valuesOfParams)).toStrictEqual({
petId: `${PRE_PARAM_VALUE_TAG}170${POST_PARAM_VALUE_TAG}`
petId: `${PRE_PARAM_VALUE_TAG}170${POST_PARAM_VALUE_TAG}`,
});
});
});
Expand All @@ -71,6 +67,5 @@ describe('colorizer', () => {

expect(attachTagsToParamsValues(values)).toStrictEqual({});
});

});
});
Loading