Skip to content

Commit 1894d84

Browse files
committed
test(openapi_3.1): ensure that an API with webhooks and no routes is supported
1 parent 4f2ceaa commit 1894d84

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

test/openapi_3.1/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Open API 3.1 tests
2+
3+
This folder, and its subfolders, contain tests for OpenAPI specification 3.1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# From https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml
2+
openapi: 3.1.0
3+
info:
4+
title: Webhook Example
5+
version: 1.0.0
6+
# Since OAS 3.1.0 the paths element isn't necessary. Now a valid OpenAPI Document can describe only paths, webhooks, or even only reusable components
7+
webhooks:
8+
# Each webhook needs a name
9+
newPet:
10+
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
11+
post:
12+
requestBody:
13+
description: Information about a new pet in the system
14+
content:
15+
application/json:
16+
schema:
17+
$ref: "#/components/schemas/Pet"
18+
responses:
19+
"200":
20+
description: Return a 200 status to indicate that the data was received successfully
21+
22+
components:
23+
schemas:
24+
Pet:
25+
required:
26+
- id
27+
- name
28+
properties:
29+
id:
30+
type: integer
31+
format: int64
32+
name:
33+
type: string
34+
tag:
35+
type: string

test/openapi_3.1/webhook.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect } from "chai";
2+
import * as request from 'supertest';
3+
import { createApp } from "../common/app";
4+
import { join } from "path";
5+
6+
describe('webhook support - OpenAPI 3.1', () => {
7+
let app;
8+
9+
before(async () => {
10+
const apiSpec = join('test', 'openapi_3.1', 'resources', 'webhook.yaml');
11+
app = await createApp(
12+
{ apiSpec, validateRequests: true },
13+
3005,
14+
undefined,
15+
false,
16+
);
17+
});
18+
19+
after(() => {
20+
app.server.close();
21+
});
22+
23+
it('should support an API that only has webhooks defined, but provides no routes', () => {
24+
// The webhook is not made available by the provider API, so the request will return 404
25+
// This test ensures that the request flow happens normally without any interruptions due to being a webhook
26+
return request(app)
27+
.get(`${app.basePath}/webhook`)
28+
.expect(404);
29+
});
30+
31+
})

0 commit comments

Comments
 (0)