Skip to content

Commit

Permalink
adds support to externalDocs per route when using OAS 2.0 and updates…
Browse files Browse the repository at this point in the history
… FastifySchema interface (#527)

* fix(types): adds externalDocs option to route schema

* feat(swagger): adds support to externalDocs per route
  • Loading branch information
riquenunes committed Jan 20, 2022
1 parent 05fbc97 commit 0e26517
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare module 'fastify' {
summary?: string;
consumes?: string[];
produces?: string[];
externalDocs?: OpenAPIV2.ExternalDocumentationObject | OpenAPIV3.ExternalDocumentationObject;
security?: Array<{ [securityLabel: string]: string[] }>;
/**
* OpenAPI operation unique identifier
Expand Down
1 change: 1 addition & 0 deletions lib/spec/swagger/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ function prepareSwaggerMethod (schema, ref, swaggerObject) {
if (schema.operationId) swaggerMethod.operationId = schema.operationId
if (schema.summary) swaggerMethod.summary = schema.summary
if (schema.description) swaggerMethod.description = schema.description
if (schema.externalDocs) swaggerMethod.externalDocs = schema.externalDocs
if (schema.tags) swaggerMethod.tags = schema.tags
if (schema.produces) swaggerMethod.produces = schema.produces
if (schema.consumes) swaggerMethod.consumes = schema.consumes
Expand Down
9 changes: 7 additions & 2 deletions test/spec/swagger/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ test('route options - deprecated', t => {
})

test('route options - meta', t => {
t.plan(8)
t.plan(9)
const fastify = Fastify()

fastify.register(fastifySwagger, swaggerOption)
Expand All @@ -132,7 +132,11 @@ test('route options - meta', t => {
tags: ['tag'],
description: 'Route description',
produces: ['application/octet-stream'],
consumes: ['application/x-www-form-urlencoded']
consumes: ['application/x-www-form-urlencoded'],
externalDocs: {
description: 'Find more info here',
url: 'https://swagger.io'
}
}
}

Expand All @@ -152,6 +156,7 @@ test('route options - meta', t => {
t.equal(opts.schema.description, definedPath.description)
t.same(opts.schema.produces, definedPath.produces)
t.same(opts.schema.consumes, definedPath.consumes)
t.equal(opts.schema.externalDocs, definedPath.externalDocs)
})
.catch(function (err) {
t.fail(err)
Expand Down
4 changes: 4 additions & 0 deletions test/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ app.put('/some-route/:id', {
consumes: ['application/json', 'multipart/form-data'],
security: [{ apiKey: []}],
operationId: 'opeId',
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
}
}, (req, reply) => {});

Expand Down

0 comments on commit 0e26517

Please sign in to comment.