Skip to content

Helpers for building JSON/OpenAPI schema referencing shared definitions#2971

Merged
bajtos merged 1 commit intomasterfrom
feat/getModelSchemaRef
May 30, 2019
Merged

Helpers for building JSON/OpenAPI schema referencing shared definitions#2971
bajtos merged 1 commit intomasterfrom
feat/getModelSchemaRef

Conversation

@bajtos
Copy link
Member

@bajtos bajtos commented May 27, 2019

Introduce the following helpers:

  • getModelSchemaRef returning OpenAPI spec
  • getJsonSchemaRef returning JSON Schema

Example usage in controllers:

class MyController {
  @get('/my', {
    responses: {
      '200': {
        description: 'Array of MyModel model instances',
        content: {
          'application/json': {
            schema: getModelSchemaRef(MyModel),
          },
        },
      },
    },
  })
  async find(): Promise<MyModel[]> {
    // etc.
  }
}

Resolve #2631.

See also #1352, #2652 and #2653.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@bajtos bajtos added this to the May 2019 milestone milestone May 27, 2019
@bajtos bajtos self-assigned this May 27, 2019
@bajtos bajtos force-pushed the feat/getModelSchemaRef branch from f10a806 to 6a41e9e Compare May 27, 2019 09:10
Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

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

👍

* ```
*
* @param modelCtor The model constructor (e.g. `Product`)
* @param options Additional options
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use @param modelCtor - The model ... and @param options - Additional options

Copy link
Member Author

@bajtos bajtos May 30, 2019

Choose a reason for hiding this comment

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

Will do.

It's annoying that VSCode is generating tsdoc comments in a format that's not recognized by api-extractor :(

Copy link
Member Author

Choose a reason for hiding this comment

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

@raymondfeng How can we automate this part of review process, so that npm test fails when there are any tsdoc comments violating api-extractor requirements?

…initions

Introduce the following helpers:

- `getModelSchemaRef` returning OpenAPI spec
- `getJsonSchemaRef` returning JSON Schema

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
@bajtos bajtos force-pushed the feat/getModelSchemaRef branch from 6a41e9e to 808da4f Compare May 30, 2019 07:23
@bajtos bajtos merged commit bf07ff9 into master May 30, 2019
@bajtos bajtos deleted the feat/getModelSchemaRef branch May 30, 2019 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement getJsonSchemaRef and getModelSchemaRef helpers

3 participants