Skip to content

Commit 264f83f

Browse files
committed
test(open_api3.1): ensure that methods with non-explicit semantics allow request body
1 parent 15d9049 commit 264f83f

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as request from 'supertest';
2+
import * as express from 'express';
3+
import { createApp } from "../common/app";
4+
import { join } from "path";
5+
6+
describe('type null support - OpenAPI 3.1', () => {
7+
let app;
8+
9+
before(async () => {
10+
const apiSpec = join('test', 'openapi_3.1', 'resources', 'get_with_request_body.yaml');
11+
app = await createApp(
12+
{ apiSpec, validateRequests: true, validateResponses: true },
13+
3005,
14+
(app) => app.use(
15+
express
16+
.Router()
17+
.get(`/v1/entity`, (req, res) =>
18+
res.status(200).json({
19+
property: null
20+
}),
21+
),
22+
)
23+
);
24+
});
25+
26+
after(() => {
27+
app.server.close();
28+
});
29+
30+
// In OpenAPI 3.0, methods that RFC7231 does not have explicitly defined semantics for request body (GET, HEAD, DELETE) do not allow request body
31+
// In OpenAPI 3.1, request body is allowed for these methods. This test ensures that it is correctly handled
32+
it('should support an API with types set to null', async () => {
33+
return request(app)
34+
.get(`${app.basePath}/entity`)
35+
.set('Content-Type', 'application/json')
36+
.send({request: 123})
37+
.expect(400);
38+
});
39+
40+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
openapi: 3.1.0
2+
info:
3+
title: API
4+
version: 1.0.0
5+
servers:
6+
- url: /v1
7+
paths:
8+
/entity:
9+
get:
10+
summary: test
11+
description: GETS my entity
12+
requestBody:
13+
description: Request body for entity
14+
required: true
15+
content:
16+
application/json:
17+
schema:
18+
title: EntityRequest
19+
type: object
20+
properties:
21+
request:
22+
type: ['string']
23+
responses:
24+
'200':
25+
description: OK
26+
content:
27+
application/json:
28+
schema:
29+
title: Entity
30+
type: object
31+
properties:
32+
property:
33+
type: ['string', 'null']
34+

0 commit comments

Comments
 (0)