Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ packages/example-hello-world/* @b-admike
packages/example-log-extension/* @virkt25
packages/example-rpc-server/* @kjdelisle
packages/metadata/* @raymondfeng
packages/openapi-spec/* @bajtos @jannyHou
packages/openapi-spec/* @bajtos @jannyHou
packages/openapi-spec-builder/* @bajtos @raymondfeng
packages/openapi-v2/* @jannyHou
packages/openapi-v3/* @jannyHou
packages/openapi-v3-types/* @jannyHou
packages/openapi-v2/* @bajtos @jannyHou
packages/openapi-v3/* @bajtos @jannyHou
packages/openapi-v3-types/* @bajtos @jannyHou
packages/repository/* @raymondfeng @kjdelisle
packages/repository-json-schema/* @shimks
packages/rest/* @bajtos @kjdelisle
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@loopback/context": "^0.2.0",
"@loopback/core": "^0.2.0",
"@loopback/openapi-v2": "^0.2.0",
"@loopback/openapi-v3": "^0.2.0",
"@loopback/rest": "^0.2.0",
"passport": "^0.4.0",
"passport-strategy": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/test/acceptance/basic-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RestServer,
RestComponent,
} from '@loopback/rest';
import {api, get} from '@loopback/openapi-v2';
import {api, get} from '@loopback/openapi-v3';
import {Client, createClientForHandler} from '@loopback/testlab';
import {anOpenApiSpec} from '@loopback/openapi-spec-builder';
import {inject, Provider, ValueOrPromise} from '@loopback/context';
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"devDependencies": {
"@loopback/build": "^0.2.0",
"@loopback/openapi-v2": "^0.2.0",
"@loopback/openapi-v3": "^0.2.0",
"@loopback/rest": "^0.2.0",
"@loopback/testlab": "^0.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/fixtures/multiple.artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {get} from '@loopback/openapi-v2';
import {get} from '@loopback/openapi-v3';

export class ArtifactOne {
@get('/one')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ServerRequest} from '@loopback/rest';
import {get} from '@loopback/openapi-v2';
import {get} from '@loopback/openapi-v3';
import {inject} from '@loopback/context';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Filter, Where} from '@loopback/repository';
import {post, param, get, put, patch, del} from '@loopback/openapi-v2';
import {post, param, get, put, patch, del} from '@loopback/openapi-v3';
import {inject} from '@loopback/context';
import {<%= modelName %>} from '../models';
import {<%= repositoryName %>} from '../repositories';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generators/project/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<% if (project.projectType === 'application') { -%>
"@loopback/core": "<%= project.dependencies['@loopback/core'] -%>",
"@loopback/rest": "<%= project.dependencies['@loopback/rest'] -%>",
"@loopback/openapi-v2": "<%= project.dependencies['@loopback/openapi-v2'] -%>"
"@loopback/openapi-v3": "<%= project.dependencies['@loopback/openapi-v3'] -%>"
<% } else { -%>
"@loopback/core": "<%= project.dependencies['@loopback/core'] -%>"
<% } -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<% if (project.projectType === 'application') { -%>
"@loopback/core": "<%= project.dependencies['@loopback/core'] -%>",
"@loopback/rest": "<%= project.dependencies['@loopback/rest'] -%>",
"@loopback/openapi-v2": "<%= project.dependencies['@loopback/openapi-v2'] -%>"
"@loopback/openapi-v3": "<%= project.dependencies['@loopback/openapi-v3'] -%>"
<% } else { -%>
"@loopback/core": "<%= project.dependencies['@loopback/core'] -%>"
<% } -%>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@loopback/boot": "^0.2.0",
"@loopback/core": "^0.2.0",
"@loopback/rest": "^0.2.0",
"@loopback/openapi-v2": "^0.2.0",
"@loopback/openapi-v3": "^0.2.0",
"@loopback/build": "^0.2.0",
"@loopback/testlab": "^0.2.0",
"@types/mocha": "^2.2.43",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('app-generator specfic files', () => {
assert.fileContent('src/controllers/ping.controller.ts', /ping\(\)/);
assert.fileContent(
'src/controllers/ping.controller.ts',
/\'\@loopback\/openapi\-v2\'/
/\'\@loopback\/openapi\-v3\'/
);

assert.file;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ module.exports = function(projGenerator, props, projectType) {
);
assert.fileContent(
'package.json',
`"@loopback/openapi-v2": "${deps['@loopback/openapi-v2']}"`
`"@loopback/openapi-v3": "${deps['@loopback/openapi-v3']}"`
);
assert.jsonFileContent('package.json', {
scripts: {
Expand All @@ -249,7 +249,7 @@ module.exports = function(projGenerator, props, projectType) {
`"@loopback/context": "${deps['@loopback/context']}"`
);
assert.noFileContent('package.json', '"@loopback/rest"');
assert.noFileContent('package.json', '"@loopback/openapi-v2"');
assert.noFileContent('package.json', '"@loopback/openapi-v3"');
assert.noJsonFileContent('package.json', {
start: 'npm run build && node .',
});
Expand Down
37 changes: 17 additions & 20 deletions packages/example-getting-started/docs/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Now that we have the repository wireup, let's create our first handler function.

#### src/controllers/todo.controller.ts
```ts
import {post, param} from '@loopback/openapi-v2';
import {post, param} from '@loopback/openapi-v3';
import {HttpErrors} from '@loopback/rest';
import {TodoSchema, Todo} from '../models';
import {Todo} from '../models';
import {repository} from '@loopback/repository';
import {TodoRepository} from '../repositories/index';

Expand All @@ -63,8 +63,7 @@ export class TodoController {
) {}

@post('/todo')
@param.body('todo', TodoSchema)
async createTodo(todo: Todo) {
async createTodo(@requestBody() todo: Todo) {
if (!todo.title) {
return Promise.reject(new HttpErrors.BadRequest('title is required'));
}
Expand All @@ -78,7 +77,7 @@ metadata about the route, verb and the format of the incoming request body:

- `@post('/todo')` creates metadata for LoopBack's [RestServer]() so that it can
redirect requests to this function when the path and verb match.
- `@param.body('todo', TodoSchema)` associates the OpenAPI schema for a Todo
- `@requestBody()` associates the OpenAPI schema for a Todo
with the body of the request so that LoopBack can validate the format of an
incoming request (**Note**: As of this writing, schematic validation is not yet
functional).
Expand All @@ -95,9 +94,9 @@ verbs:

#### src/controllers/todo.controller.ts
```ts
import {post, param, get, put, patch, del} from '@loopback/openapi-v2';
import {post, param, requestBody, get, put, patch, del} from '@loopback/openapi-v3';
import {HttpErrors} from '@loopback/rest';
import {TodoSchema, Todo} from '../models';
import {Todo} from '../models';
import {repository} from '@loopback/repository';
import {TodoRepository} from '../repositories/index';

Expand All @@ -107,18 +106,17 @@ export class TodoController {
) {}

@post('/todo')
@param.body('todo', TodoSchema)
async createTodo(todo: Todo) {
async createTodo(@requestBody()todo: Todo) {
if (!todo.title) {
return Promise.reject(new HttpErrors.BadRequest('title is required'));
}
return await this.todoRepo.create(todo);
}

@get('/todo/{id}')
@param.path.number('id')
@param.query.boolean('items')
async findTodoById(id: number, items?: boolean): Promise<Todo> {
async findTodoById(
@param.path.number('id') id: number,
@param.query.boolean('items') items?: boolean): Promise<Todo> {
return await this.todoRepo.findById(id);
}

Expand All @@ -128,22 +126,21 @@ export class TodoController {
}

@put('/todo/{id}')
@param.path.number('id')
@param.body('todo', TodoSchema)
async replaceTodo(id: number, todo: Todo): Promise<boolean> {
async replaceTodo(
@param.path.number('id') id: number,
@requestBody() todo: Todo): Promise<boolean> {
return await this.todoRepo.replaceById(id, todo);
}

@patch('/todo/{id}')
@param.path.number('id')
@param.body('todo', TodoSchema)
async updateTodo(id: number, todo: Todo): Promise<boolean> {
async updateTodo(
@param.path.number('id') id: number,
@param.body() todo: Todo): Promise<boolean> {
return await this.todoRepo.updateById(id, todo);
}

@del('/todo/{id}')
@param.path.number('id')
async deleteTodo(id: number): Promise<boolean> {
async deleteTodo(@param.path.number('id') id: number): Promise<boolean> {
return await this.todoRepo.deleteById(id);
}
}
Expand Down
40 changes: 1 addition & 39 deletions packages/example-getting-started/docs/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ the `getId` function, so that it can retrieve a Todo model's ID as needed.
#### src/models/todo.model.ts
```ts
import {Entity, property, model} from '@loopback/repository';
import {SchemaObject} from '@loopback/openapi-spec';

@model()
export class Todo extends Entity {
Expand Down Expand Up @@ -95,44 +94,7 @@ export class Todo extends Entity {
}
```

<!--
TODO: Remove this section once v3 is live; ideally, this won't be required
any longer!
-->
Additionally, we'll define a `SchemaObject` that represents our Todo model
as an [OpenAPI Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schema-object).
This will give the OpenAPI spec builder the information it needs to describe the
Todo model on your app's OpenAPI endpoints.

#### src/models/todo.model.ts
```ts
// Note: This is in the same file as the Todo model class.
// This should come *after* the model class definition!
export const TodoSchema: SchemaObject = {
title: 'todoItem',
properties: {
id: {
type: 'number',
description: 'ID number of the Todo entry.'
},
title: {
type: 'string',
description: 'Title of the Todo entry.'
},
desc: {
type: 'number',
description: 'ID number of the Todo entry.'
},
isComplete: {
type: 'boolean',
description: 'Whether or not the Todo entry is complete.'
}
},
required: ['title'],
};
```

Now that we have our model and schema, it's time to add a
Now that we have our model, it's time to add a
[datasource](datasource.md) so we can perform real CRUD operations!

### Navigation
Expand Down
4 changes: 2 additions & 2 deletions packages/example-getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@loopback/boot": "^0.2.0",
"@loopback/context": "^0.2.0",
"@loopback/core": "^0.2.0",
"@loopback/openapi-spec": "^0.2.0",
"@loopback/openapi-v2": "^0.2.0",
"@loopback/openapi-v3-types": "^0.2.0",
"@loopback/openapi-v3": "^0.2.0",
"@loopback/repository": "^0.2.0",
"@loopback/rest": "^0.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {post, param, get, put, patch, del} from '@loopback/openapi-v2';
import {
post,
param,
get,
put,
patch,
del,
requestBody,
} from '@loopback/openapi-v3';
import {HttpErrors} from '@loopback/rest';
import {TodoSchema, Todo} from '../models';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of TodoSchema definition if it is not used for anything else?

Copy link
Contributor Author

@jannyHou jannyHou Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-admike ah, answered ^ in the last part of comment #1067 (comment)

import {Todo} from '../models';
import {repository} from '@loopback/repository';
import {TodoRepository} from '../repositories';

Expand All @@ -11,11 +19,9 @@ export class TodoController {
constructor(
@repository(TodoRepository.name) protected todoRepo: TodoRepository,
) {}

@post('/todo')
async createTodo(
@param.body('todo', TodoSchema)
todo: Todo,
) {
async createTodo(@requestBody() todo: Todo) {
// TODO(bajtos) This should be handled by the framework
// See https://github.com/strongloop/loopback-next/issues/118
if (!todo.title) {
Expand All @@ -40,8 +46,7 @@ export class TodoController {
@put('/todo/{id}')
async replaceTodo(
@param.path.number('id') id: number,
@param.body('todo', TodoSchema)
todo: Todo,
@requestBody() todo: Todo,
): Promise<boolean> {
// REST adapter does not coerce parameter values coming from string sources
// like path & query. As a workaround, we have to cast the value to a number
Expand All @@ -55,8 +60,7 @@ export class TodoController {
@patch('/todo/{id}')
async updateTodo(
@param.path.number('id') id: number,
@param.body('todo', TodoSchema)
todo: Todo,
@requestBody() todo: Todo,
): Promise<boolean> {
// REST adapter does not coerce parameter values coming from string sources
// like path & query. As a workaround, we have to cast the value to a number
Expand Down
27 changes: 0 additions & 27 deletions packages/example-getting-started/src/models/todo.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Entity, property, model} from '@loopback/repository';
import {SchemaObject} from '@loopback/openapi-spec';

@model()
export class Todo extends Entity {
Expand Down Expand Up @@ -29,29 +28,3 @@ export class Todo extends Entity {
return this.id;
}
}

// TODO(bajtos) The schema should be generated from model definition
// See https://github.com/strongloop/loopback-next/issues/700
// export const TodoSchema = createSchemaFromModel(Todo);
export const TodoSchema: SchemaObject = {
title: 'todoItem',
properties: {
id: {
type: 'number',
description: 'ID number of the Todo entry.',
},
title: {
type: 'string',
description: 'Title of the Todo entry.',
},
desc: {
type: 'number',
description: 'ID number of the Todo entry.',
},
isComplete: {
type: 'boolean',
description: 'Whether or not the Todo entry is complete.',
},
},
required: ['title'],
};
1 change: 1 addition & 0 deletions packages/example-log-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"@loopback/context": "^0.2.0",
"@loopback/core": "^0.2.0",
"@loopback/openapi-v3": "^0.2.0",
"@loopback/rest": "^0.2.0",
"chalk": "^2.3.0",
"debug": "^3.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import {
RestApplication,
RestServer,
get,
param,
SequenceHandler,
RestBindings,
FindRoute,
Expand All @@ -18,6 +16,7 @@ import {
ParsedRequest,
ServerResponse,
} from '@loopback/rest';
import {get, param} from '@loopback/openapi-v3';
import {
LogComponent,
LogLevelMixin,
Expand Down
Loading