-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deepObject default value support #287
- Loading branch information
Carmine DiMascio
committed
May 7, 2020
1 parent
60c2abd
commit e548b9a
Showing
8 changed files
with
194 additions
and
19 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 |
---|---|---|
|
@@ -10,4 +10,5 @@ dist | |
secrets.zip | ||
jest | ||
junk | ||
/a_reference | ||
/a_reference | ||
/sample2 |
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
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
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
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
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
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,58 @@ | ||
components: | ||
schemas: | ||
PageSort: | ||
allOf: | ||
- $ref: "#/components/schemas/Paging" | ||
- $ref: "#/components/schemas/Sorting" | ||
Paging: | ||
properties: | ||
page: | ||
default: 1 | ||
minimum: 1 | ||
type: integer | ||
perPage: | ||
default: 25 | ||
type: integer | ||
type: object | ||
Sorting: | ||
properties: | ||
field: | ||
default: id | ||
enum: | ||
- id | ||
- name | ||
type: string | ||
order: | ||
default: ASC | ||
enum: | ||
- ASC | ||
- DESC | ||
type: string | ||
type: object | ||
info: | ||
description: API | ||
title: API | ||
version: 1.0.0 | ||
openapi: 3.0.0 | ||
servers: | ||
- url: /v1/ | ||
paths: | ||
/deep_object: | ||
get: | ||
operationId: getDeepObject | ||
parameters: | ||
- explode: true | ||
in: query | ||
name: pagesort | ||
schema: | ||
$ref: "#/components/schemas/PageSort" | ||
style: deepObject | ||
responses: | ||
"200": | ||
description: description | ||
content: | ||
application/json: | ||
schema: | ||
items: | ||
type: number | ||
type: array |
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,51 @@ | ||
import * as path from 'path'; | ||
import * as express from 'express'; | ||
import * as request from 'supertest'; | ||
import * as packageJson from '../package.json'; | ||
import { expect } from 'chai'; | ||
import { createApp } from './common/app'; | ||
|
||
describe(packageJson.name, () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
// Set up the express app | ||
const apiSpec = path.join( | ||
'test', | ||
'resources', | ||
'serialized.objects.defaults.yaml', | ||
); | ||
app = await createApp({ apiSpec }, 3005, (app) => | ||
app.use( | ||
`${app.basePath}`, | ||
express.Router().get(`/deep_object`, (req, res) => res.json(req.query)), | ||
), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should use defaults when empty', async () => | ||
request(app) | ||
.get(`${app.basePath}/deep_object`) | ||
.expect(200) | ||
.then((r) => { | ||
console.log(r.body); | ||
expect(r.body).to.deep.equals({ | ||
pagesort: { page: 1, perPage: 25, field: 'id', order: 'ASC' }, | ||
}); | ||
})); | ||
|
||
it('should use defaults for values not provided', async () => | ||
request(app) | ||
.get(`${app.basePath}/deep_object?pagesort[field]=name`) | ||
.expect(200) | ||
.then((r) => { | ||
console.log(r.body); | ||
expect(r.body).to.deep.equals({ | ||
pagesort: { page: 1, perPage: 25, field: 'name', order: 'ASC' }, | ||
}); | ||
})); | ||
}); |