Skip to content

Commit

Permalink
docs: fix compile errors; rename variables to match impl
Browse files Browse the repository at this point in the history
- exported the controller class
- the `schema:` prop was missing
- the variable names were mismatched with types declared and
  exposed through openapi/swagger/explorer thingie
  • Loading branch information
activedecay authored and raymondfeng committed Oct 30, 2018
1 parent 57c694e commit 14d9419
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions docs/site/Decorators_openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class MyModel {
name: string;
}

class MyController {
export class MyController {
@get('/', {
responses: {
'200': {
Expand All @@ -351,7 +351,7 @@ class MyController {
@post('/')
greet(
@requestBody({
content: {'application/json': {{'x-ts-type': MyModel}}},
content: {'application/json': {schema: {'x-ts-type': MyModel}}},
})
body: MyModel,
) {
Expand All @@ -363,7 +363,14 @@ class MyController {
The `x-ts-type` can be used for array and object properties too:

```ts
const schemaWithArray = {
const schemaWithArrayOfMyModel = {
type: 'array',
items: {
'x-ts-type': MyModel,
},
};

const schemaDeepArrayOfMyModel = {
type: 'array',
items: {
type: 'array',
Expand All @@ -373,14 +380,48 @@ const schemaWithArray = {
},
};

const schema = {
const schemaWithObjectPropOfMyModel = {
type: 'object',
properties: {
myModel: {
'x-ts-type': MyModel,
},
},
};

export class SomeController {
@post('/my-controller')
greetObjectProperty(@requestBody({
content: {'application/json': {schema: schemaWithObjectPropOfMyModel}},
})
body: {
myModel: MyModel;
}): string {
return `hello ${body.myModel.name}!`;
}

@get('/my-controllers', {
responses: {
'200': {
description: 'hello world',
content: {'application/json': {schema: schemaWithArrayOfMyModel}},
},
},
})
everyone(): MyModel[] {
return [{name: 'blue'}, {name: 'red'}];
}

@post('/my-controllers')
greetEveryone(
@requestBody({
content: {'application/json': {schema: schemaDeepArrayOfMyModel}},
})
body: MyModel[][],
): string {
return `hello ${body.map(objs => objs.map(m => m.name))}`;
}
}
```

When the OpenAPI spec is generated, the `xs-ts-type` is mapped to
Expand Down

0 comments on commit 14d9419

Please sign in to comment.