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

feat(rest): implement query parameter validation (issue 1573) #2307

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
72594eb
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
0e04254
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
8e3248c
Merge branch 'master' into issue-1573
YaelGit Jan 30, 2019
a4c2086
chore: fix test cases to be compatible with [email protected]
raymondfeng Jan 30, 2019
066d525
build(testlab): move test files to `src/__tests__`
bajtos Jan 24, 2019
4c6b176
docs: fix instructions for verifying TypeScript setup
bajtos Jan 25, 2019
f946d48
docs(testlab): describe test fixture directories
bajtos Jan 29, 2019
0121c10
fix: remove unused juggler import
nabdelgadir Jan 31, 2019
181e1f1
chore(context): add more unit tests for binding filters
raymondfeng Jan 31, 2019
0710055
chore: upgrade dependencies for build
raymondfeng Jan 31, 2019
91a37dc
build: move test files to `src/__tests__` in example apps
bajtos Jan 31, 2019
a624b95
docs(cli): use a custom repository base class
gczobel-f5 Jan 31, 2019
0e92b88
docs(cli): use a custom repository base class
gczobel-f5 Feb 3, 2019
edbbe88
feat(cli): use a custom repository base class
gczobel-f5 Jan 9, 2019
4695e3a
chore: add required config for greenkeeper integration
raymondfeng Jan 31, 2019
857868e
chore: update dependencies proposed by greenkeeper
raymondfeng Jan 31, 2019
bfe8c27
chore: whitelist greenkeeper branches
raymondfeng Jan 31, 2019
a8a409c
chore: add Greenkeeper badge
raymondfeng Jan 31, 2019
84c6a88
chore: add dominique to maintainers
nabdelgadir Feb 4, 2019
1a6ac91
build: move test files to `src/__tests__` in packages
bajtos Feb 4, 2019
89340b0
docs: how to update target model in hasmany relation
ludohenin Jan 26, 2019
d3a3bea
feat(cli): scaffold test files to `src/__tests__`
bajtos Feb 5, 2019
51cba45
fix(benchmark): set TypeScript's rootDir to src
bajtos Feb 5, 2019
a3da024
feat(build): use `dist/__tests__` in code examples and tests
bajtos Feb 5, 2019
a54fbf1
fix(example-todo): "npm run migration" script path
bajtos Feb 5, 2019
bf26cc3
fix(example-todo-list): "npm run migration" script path
bajtos Feb 5, 2019
75731f9
fix(docs): update test paths to `src/__tests__`
bajtos Feb 5, 2019
5042698
fix(rest): sanitize json for JSON.parse()
raymondfeng Feb 6, 2019
b5f12be
chore: update @types/debug to version 4.1.0
raymondfeng Feb 7, 2019
6ef5d85
chore: exclude "good first issue" from stalebot
bajtos Feb 8, 2019
65ee865
fix: update to the most recent lodash version
jannyHou Feb 7, 2019
596a143
chore: publish release
dhmlau Feb 8, 2019
95e919e
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
112847b
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
f14bd93
Merge branch 'issue-1573' of github.com:YaelGit/loopback-next into is…
YaelGit Feb 11, 2019
7707fa5
fix(docs): broken link in Crafting in LB
dhmlau Feb 10, 2019
bf22e5c
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
131ccd9
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
1fe7f9c
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
14d7909
feat(rest): validate query parameters against their schema
YaelGit Jan 30, 2019
c2c1c07
Merge branch 'issue-1573' of github.com:YaelGit/loopback-next into is…
YaelGit Feb 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exemptLabels:
- critical
- p1
- major
- good first issue
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
Expand Down
4 changes: 2 additions & 2 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"examples/*/dist"
],
"exclude": [
"packages/*/dist/test/",
"packages/*/dist/__tests__/",
"packages/cli/test/",
"examples/*/dist/test/",
"examples/*/dist/__tests__/",
"**/.sandbox/"
],
"extension": [
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ matrix:
branches:
only:
- master
- /^greenkeeper/.*$/
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"args": [
"--opts",
"${workspaceRoot}/test/mocha.opts",
"packages/*/dist/test/**/*.js",
"packages/*/dist/__tests__/**/*.js",
"-t",
"0"
]
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Travis Build Status](https://travis-ci.org/strongloop/loopback-next.svg?branch=master)](https://travis-ci.org/strongloop/loopback-next)
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/q8vp7wrdn2ak6801/branch/master?svg=true)](https://ci.appveyor.com/project/strongloop/loopback-next/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/strongloop/loopback-next/badge.svg?branch=master)](https://coveralls.io/github/strongloop/loopback-next?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/strongloop/loopback-next.svg)](https://greenkeeper.io/)

LoopBack makes it easy to build modern applications that require complex
integrations.
Expand Down Expand Up @@ -92,8 +93,8 @@ You can join the team by posting a comment to
| [![b-admike]](http://github.com/b-admike) | [![dhmlau]](http://github.com/dhmlau) | [![jannyhou]](http://github.com/jannyHou) |
| Hage Yaapa | Nora Abdelgadir | Mario Estrada |
| [![hacksparrow]](https://github.com/hacksparrow) | [![nabdelgadir]](https://github.com/nabdelgadir) | [![marioestradarosa]](https://github.com/marioestradarosa) |
| Hugo Da Roit | | |
| [![yaty]](https://github.com/yaty) | | |
| Hugo Da Roit | Dominique Emond | |
| [![yaty]](https://github.com/yaty) | [![emonddr]](https://github.com/emonddr) | |

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).
Expand All @@ -112,3 +113,4 @@ See
[nabdelgadir]: https://avatars0.githubusercontent.com/u/42985749?v=3&s=60
[marioestradarosa]: https://avatars2.githubusercontent.com/u/4633823?v=3&s=60
[yaty]: https://avatars3.githubusercontent.com/u/11981803?v=3&s=60
[emonddr]: https://avatars0.githubusercontent.com/u/6864736??v=3&s=60
11 changes: 11 additions & 0 deletions benchmark/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.10](https://github.com/strongloop/loopback-next/compare/@loopback/[email protected]...@loopback/[email protected]) (2019-02-08)


### Bug Fixes

* **benchmark:** set TypeScript's rootDir to src ([51cba45](https://github.com/strongloop/loopback-next/commit/51cba45))





## [1.1.9](https://github.com/strongloop/loopback-next/compare/@loopback/[email protected]...@loopback/[email protected]) (2019-01-28)

**Note:** Version bump only for package @loopback/benchmark
Expand Down
26 changes: 13 additions & 13 deletions benchmark/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loopback/benchmark",
"version": "1.1.9",
"version": "1.1.10",
"private": true,
"description": "Benchmarks measuring performance of our framework.",
"keywords": [
Expand All @@ -16,9 +16,9 @@
"build": "lb-tsc es2017 --outDir dist",
"clean": "lb-clean dist",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha \"dist/test\"",
"test": "lb-mocha \"dist/__tests__\"",
"prestart": "npm run build",
"benchmark:routing": "node ./dist/src/rest-routing/routing-table",
"benchmark:routing": "node ./dist/rest-routing/routing-table",
"start": "node ."
},
"repository": {
Expand All @@ -30,28 +30,28 @@
"README.md",
"index.js",
"index.d.ts",
"dist/src",
"dist/index*",
"src"
"dist",
"src",
"!*/__tests__"
],
"dependencies": {
"@loopback/example-todo": "^1.4.2",
"@loopback/openapi-spec-builder": "^1.0.5",
"@loopback/rest": "^1.5.4",
"@loopback/example-todo": "^1.4.3",
"@loopback/openapi-spec-builder": "^1.0.6",
"@loopback/rest": "^1.5.5",
"@types/byline": "^4.2.31",
"@types/debug": "0.0.31",
"@types/debug": "^4.1.0",
"@types/p-event": "^1.3.0",
"@types/request-promise-native": "^1.0.15",
"autocannon": "^3.0.0",
"byline": "^5.0.0",
"debug": "^4.0.1",
"path-to-regexp": "^2.4.0",
"path-to-regexp": "^3.0.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.5"
},
"devDependencies": {
"@loopback/build": "^1.2.1",
"@loopback/testlab": "^1.0.5",
"@loopback/build": "^1.3.0",
"@loopback/testlab": "^1.0.6",
"@types/mocha": "^5.0.0",
"@types/node": "^10.11.2",
"mocha": "^5.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {expect} from '@loopback/testlab';
import * as request from 'request-promise-native';
import {Benchmark} from '..';
import {Autocannon, EndpointStats} from '../src/autocannon';
import {Autocannon, EndpointStats} from '../autocannon';

const debug = require('debug')('test');

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions benchmark/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "."
"rootDir": "src"
},
"include": ["index.ts", "src", "test"]
"include": ["src"]
}
102 changes: 102 additions & 0 deletions bin/update-greenkeeper-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback-next
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/**
* This is an internal script to update `greenkeeper.json` with lerna packages.
*/
'use strict';

const path = require('path');
const fs = require('fs');

const Project = require('@lerna/project');

async function updateGreenKeeperJson() {
const project = new Project(process.cwd());
const packages = await project.getPackages();
const rootPath = project.rootPath;
const packageJsonPaths = packages.map(p =>
path.relative(rootPath, p.manifestLocation),
);
const greenKeeperJson = {
groups: {
default: {
packages: ['package.json'],
},
},
};

for (const p of packageJsonPaths) {
greenKeeperJson.groups.default.packages.push(p);
}

const greenKeeperJsonFile = path.join(rootPath, 'greenkeeper.json');
let currentConfig = {};
if (fs.existsSync(greenKeeperJsonFile)) {
currentConfig = readJsonFile(greenKeeperJsonFile);
}

let updateRequired = false;
if (
!(
currentConfig.groups &&
currentConfig.groups.default &&
Array.isArray(currentConfig.groups.default.packages)
)
) {
// Current config does not exist
updateRequired = true;
}

if (!updateRequired) {
// Check if packages are the same
updateRequired = !arraysContainSameElements(
currentConfig.groups.default.packages,
greenKeeperJson.groups.default.packages,
);
}

if (!updateRequired) {
console.log('%s is up to date.', 'greenkeeper.json');
return;
}

if (process.argv[2] === '-f') {
// Update `greenkeeper.json`
writeJsonFile(greenKeeperJsonFile, greenKeeperJson);
} else {
// Print out `greenkeeper.json`
console.error('%s is out of date.', 'greenkeeper.json');
console.log(JSON.stringify(greenKeeperJson, null, 2));
}
}

if (require.main === module) updateGreenKeeperJson();

/**
* Test if two arrays contain the same set of elements
* @param {Array} actual
* @param {Array} expected
*/
function arraysContainSameElements(actual, expected) {
return (
// Same size
actual.length == expected.length &&
// `expected` contains all elements of `actual`
actual.every(e => expected.includes(e)) &&
// `actual` contains all elements of `expected`
expected.every(e => actual.includes(e))
);
}

function readJsonFile(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
}

function writeJsonFile(filePath, data) {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
console.log('%s has been updated.', filePath);
}
13 changes: 13 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.7.3](https://github.com/strongloop/loopback-next/compare/@loopback/[email protected]...@loopback/[email protected]) (2019-02-08)


### Bug Fixes

* **docs:** remove .ts from imports ([c601c4c](https://github.com/strongloop/loopback-next/commit/c601c4c))
* **docs:** update link in todo-tutorial-geocoding-service ([e6a8d73](https://github.com/strongloop/loopback-next/commit/e6a8d73))
* **docs:** update test paths to `src/__tests__` ([75731f9](https://github.com/strongloop/loopback-next/commit/75731f9))





## [1.7.2](https://github.com/strongloop/loopback-next/compare/@loopback/[email protected]...@loopback/[email protected]) (2019-01-28)

**Note:** Version bump only for package @loopback/docs
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loopback/docs",
"version": "1.7.2",
"version": "1.7.3",
"description": "Documentation for LoopBack 4",
"homepage": "https://github.com/strongloop/loopback-next/tree/master/docs",
"author": {
Expand All @@ -22,7 +22,7 @@
"clean": "lb-clean loopback-docs*.tgz package api-docs site/readmes"
},
"devDependencies": {
"@loopback/build": "^1.2.1"
"@loopback/build": "^1.3.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Application-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ the following files and directories:
```text
.
├── src/
| ├── __tests__/
| ├── controllers/
| | └── ping.controller.ts
| ├── datasources/
Expand All @@ -84,7 +85,6 @@ the following files and directories:
| ├── application.ts
| ├── index.ts
| └── sequence.ts
├── test/
└── package.json
```

Expand Down
6 changes: 3 additions & 3 deletions docs/site/Controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ codes is found
The example below shows the previous controller revamped with `HttpErrors` along
with a test to verify that the error is thrown properly.

{% include code-caption.html content="test/integration/controllers/hello.controller.integration.ts" %}
{% include code-caption.html content="src/__tests__/integration/controllers/hello.controller.integration.ts" %}

```ts
import {HelloController} from '../../../src/controllers';
import {HelloRepository} from '../../../src/repositories';
import {HelloController} from '../../../controllers';
import {HelloRepository} from '../../../repositories';
import {testdb} from '../../fixtures/datasources/testdb.datasource';
import {expect} from '@loopback/testlab';
import {HttpErrors} from '@loopback/rest';
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Crafting-LoopBack-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ There are several key pillars to make extensibility a reality for LoopBack 4.
- [Context](Context.md), the IoC container to manage services
- [Dependency injection](Dependency-injection.md) to facilitate composition
- [Decorators](Decorators.md) to supply metadata using annotations
- [Component](Component.md) as the packaging model to bundle extensions
- [Component](Using-components.md) as the packaging model to bundle extensions

Please check out [Extending LoopBack 4](Extending-LoopBack-4.md).

Expand Down
12 changes: 4 additions & 8 deletions docs/site/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ tests (unit, acceptance and integration), with the convention
Examples are:

```
test/acceptance/application.acceptance.ts
test/integration/user.controller.integration.ts
test/unit/application.unit.ts
src/__tests__/acceptance/application.acceptance.ts
src/__tests__/integration/user.controller.integration.ts
src/__tests__/unit/application.unit.ts
```

## API Documentation
Expand Down Expand Up @@ -466,7 +466,7 @@ configuration, it's important to verify that all usage scenarios keep working.

### Verify TypeScript setup

1. Open any existing TypeScript file, e.g. `packages/src/index.ts`
1. Open any existing TypeScript file, e.g. `packages/core/src/index.ts`

2. Add a small bit of code to break TypeScript's type checks, for example:

Expand All @@ -479,10 +479,6 @@ configuration, it's important to verify that all usage scenarios keep working.
4. Verify that the build failed and the compiler error message shows a path
relative to monorepo root, e.g. `packages/src/index.ts`.

_(This is does not work now, `tsc` is reporting paths relative to individual
package directories. See
<https://github.com/strongloop/loopback-next/issues/1010>)_

5. Test integration with supported IDEs:
- [VS Code](./VSCODE.md#how-to-verify-typescript-setup)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ module provides a helper function for checking whether a specification conforms
to OpenAPI Spec. Just add a new Mocha test that calls this helper function to
the test suite:

{% include code-caption.html content="test/acceptance/api-spec.acceptance.ts" %}
{% include code-caption.html content="src/__tests__/acceptance/api-spec.acceptance.ts" %}

```ts
import {validateApiSpec} from '@loopback/testlab';
Expand Down
8 changes: 8 additions & 0 deletions docs/site/HasMany-relation.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ factory `orders` for instances of `customerRepository`:
instance
([API Docs](https://apidocs.strongloop.com/@loopback%2fdocs/repository.html#HasManyRepository.prototype.patch))

For **updating** (full replace of all properties on a `PUT` endpoint for
instance) a target model you have to directly use this model repository. In this
case, the caller must provide both the foreignKey value and the primary key
(id). Since the caller already has access to the primary key of the target
model, there is no need to go through the relation repository and the operation
can be performed directly on `DefaultCrudRepository` for the target model
(`OrderRepository` in our example).

## Using hasMany constrained repository in a controller

The same pattern used for ordinary repositories to expose their CRUD APIs via
Expand Down
Loading