-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(open_api3.1): ensure that methods with non-explicit semantics al…
…low request body
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as request from 'supertest'; | ||
import * as express from 'express'; | ||
import { createApp } from "../common/app"; | ||
import { join } from "path"; | ||
|
||
describe('type null support - OpenAPI 3.1', () => { | ||
let app; | ||
|
||
before(async () => { | ||
const apiSpec = join('test', 'openapi_3.1', 'resources', 'get_with_request_body.yaml'); | ||
app = await createApp( | ||
{ apiSpec, validateRequests: true, validateResponses: true }, | ||
3005, | ||
(app) => app.use( | ||
express | ||
.Router() | ||
.get(`/v1/entity`, (req, res) => | ||
res.status(200).json({ | ||
property: null | ||
}), | ||
), | ||
) | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
// In OpenAPI 3.0, methods that RFC7231 does not have explicitly defined semantics for request body (GET, HEAD, DELETE) do not allow request body | ||
// In OpenAPI 3.1, request body is allowed for these methods. This test ensures that it is correctly handled | ||
it('should support an API with types set to null', async () => { | ||
return request(app) | ||
.get(`${app.basePath}/entity`) | ||
.set('Content-Type', 'application/json') | ||
.send({request: 123}) | ||
.expect(400); | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: API | ||
version: 1.0.0 | ||
servers: | ||
- url: /v1 | ||
paths: | ||
/entity: | ||
get: | ||
summary: test | ||
description: GETS my entity | ||
requestBody: | ||
description: Request body for entity | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
title: EntityRequest | ||
type: object | ||
properties: | ||
request: | ||
type: ['string'] | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
title: Entity | ||
type: object | ||
properties: | ||
property: | ||
type: ['string', 'null'] | ||
|