Skip to content

Commit

Permalink
feat : add openapi 3 support (#333)
Browse files Browse the repository at this point in the history
* refactor: better file structure
- reduce the number of files in root folder

* refactor: extract common function
- hook
- formatParamUrl
- consumesFormOnly
- plainJsonObjectToSwagger2
- localRefResolve

* refactor: split dynamic handle to swagger and openapi

* feat: add openapi 3 support

* test: add openapi 3 test case

* feat: update openapi from 3.0.0 to 3.0.3

* refactor: typo

- properyName to propertyName

* refactor: more clear argument

- h to headers

* refactor: use map instead of reduce

* refactor: use done instead of next

* refactor: group functions

- remove getQueryParams, getPathParams, getHeaderParams, getFormParams
- add getParams

* refactor: genResponse  to generateResponse

* chore: remove invalid comment

* refactor: better structure

- split util to dynamicUtil, OpenapiUtil, swaggerUtil
- extract inline function from openapi and swagger

* feat: generate response according to produces

* feat: use package json as default info

* refactor: better cache name

* chore: add comment to address different issue

* feat: add oneOf, allOf, anyOf support in query, header, path, formData

* Fix type of StaticDocumentSpec.document (#328)

* refactor: better file structure
- reduce the number of files in root folder

* refactor: extract common function
- hook
- formatParamUrl
- consumesFormOnly
- plainJsonObjectToSwagger2
- localRefResolve

* refactor: split dynamic handle to swagger and openapi

* feat: add openapi 3 support

* test: add openapi 3 test case

* feat: update openapi from 3.0.0 to 3.0.3

* refactor: typo

- properyName to propertyName

* refactor: more clear argument

- h to headers

* refactor: use map instead of reduce

* refactor: use done instead of next

* refactor: group functions

- remove getQueryParams, getPathParams, getHeaderParams, getFormParams
- add getParams

* refactor: genResponse  to generateResponse

* chore: remove invalid comment

* refactor: better structure

- split util to dynamicUtil, OpenapiUtil, swaggerUtil
- extract inline function from openapi and swagger

* feat: generate response according to produces

* feat: use package json as default info

* refactor: better cache name

* chore: add comment to address different issue

* feat: add oneOf, allOf, anyOf support in query, header, path, formData

* refactor: better argument name

* feat: add cookies schema support for openapi 3

* fix: typo

* chore: add openapi typings

* docs: add openapi support docs

* docs: update as suggestion

* fix: openapi

Co-authored-by: radzom <[email protected]>
  • Loading branch information
climba03003 and radzom authored Jan 26, 2021
1 parent f1c441b commit 8ba3652
Show file tree
Hide file tree
Showing 19 changed files with 1,831 additions and 446 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fastify.ready(err => {
`dynamic` mode is the default one, if you use the plugin this way - swagger specification would be gathered from your routes definitions.
```js
{
// swagger 2.0 options
swagger: {
info: {
title: String,
Expand All @@ -136,14 +137,29 @@ fastify.ready(err => {
produces: [ String ],
tags: [ Object ],
securityDefinitions: Object
}
},
// openapi 3.0.3 options
// openapi: {
// info: {
// title: String,
// description: String,
// version: String,
// },
// externalDocs: Object,
// servers: [ Object ],
// components: Object,
// security: [ Object ],
// tags: [ Object ]
// }
}
```

*All the above parameters are optional.*
You can use all the properties of the [swagger specification](https://swagger.io/specification/), if you find anything missing, please open an issue or a pr!
You can use all the properties of the [swagger specification](https://swagger.io/specification/v2/) and [openapi specification](https://swagger.io/specification/), if you find anything missing, please open an issue or a pr!

fastify-swagger will generate Swagger v2 by default. If you pass the `opeanapi` option it will generate OpenAPI instead.

Example of the `fastify-swagger` usage in the `dynamic` mode is available [here](examples/dynamic.js).
Example of the `fastify-swagger` usage in the `dynamic` mode, `swagger` option is available [here](examples/dynamic-swagger.js) and `openapi` option is avaiable [here](examples/dynamic-openapi.js).
<a name="mode.static"></a>

##### options
Expand All @@ -154,6 +170,7 @@ fastify.ready(err => {
| hiddenTag | X-HIDDEN | Tag to control hiding of routes. |
| stripBasePath | true | Strips base path from routes in docs. |
| swagger | {} | Swagger configuration. |
| openapi | {} | Openapi configuration. |
| transform | null | Transform method for schema. |

##### static
Expand Down
Loading

0 comments on commit 8ba3652

Please sign in to comment.