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
3 changes: 3 additions & 0 deletions lib/spec/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
CUSTOM_HEADER: 'x-'
}
7 changes: 4 additions & 3 deletions lib/spec/openapi/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { xResponseDescription, xConsume, xExamples } = require('../../constants')
const { rawRequired } = require('../../symbols')
const { generateParamsSchema } = require('../../util/generate-params-schema')
const { hasParams } = require('../../util/match-params')
const { CUSTOM_HEADER } = require('../constants')

function prepareDefaultOptions (opts) {
const openapi = opts.openapi
Expand All @@ -26,7 +27,7 @@ function prepareDefaultOptions (opts) {
const convertConstToEnum = opts.convertConstToEnum

for (const [key, value] of Object.entries(opts.openapi)) {
if (key.startsWith('x-')) {
if (key.startsWith(CUSTOM_HEADER)) {
extensions.push([key, value])
}
}
Expand Down Expand Up @@ -82,7 +83,7 @@ function prepareOpenapiObject (opts) {
function normalizeUrl (url, serverUrls, stripBasePath) {
if (!stripBasePath) return formatParamUrl(url)
serverUrls.forEach(function (serverUrl) {
const basePath = serverUrl.startsWith('/') ? serverUrl : new URL(serverUrl).pathname
const basePath = serverUrl[0] === '/' ? serverUrl : new URL(serverUrl).pathname
if (url.startsWith(basePath) && basePath !== '/') {
url = url.replace(basePath, '')
}
Expand Down Expand Up @@ -489,7 +490,7 @@ function prepareOpenapiMethod (opts, schema, ref, openapiObject, url) {
if (schema.servers) openapiMethod.servers = schema.servers
if (schema.callbacks) openapiMethod.callbacks = resolveCallbacks(opts, schema.callbacks, ref)
for (const key of Object.keys(schema)) {
if (key.startsWith('x-')) {
if (key.startsWith(CUSTOM_HEADER)) {
openapiMethod[key] = schema[key]
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/spec/swagger/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { resolveSchemaReference } = require('../../util/resolve-schema-reference'
const { xResponseDescription, xConsume } = require('../../constants')
const { generateParamsSchema } = require('../../util/generate-params-schema')
const { hasParams } = require('../../util/match-params')
const { CUSTOM_HEADER } = require('../constants')

function prepareDefaultOptions (opts) {
const swagger = opts.swagger
Expand All @@ -30,7 +31,7 @@ function prepareDefaultOptions (opts) {
const extensions = []

for (const [key, value] of Object.entries(opts.swagger)) {
if (key.startsWith('x-')) {
if (key.startsWith(CUSTOM_HEADER)) {
extensions.push([key, value])
}
}
Expand Down Expand Up @@ -97,7 +98,7 @@ function normalizeUrl (url, basePath, stripBasePath) {
} else {
path = url
}
if (!path.startsWith('/')) {
if (path[0] !== '/') {
path = '/' + String(path)
}
return formatParamUrl(path)
Expand Down Expand Up @@ -310,7 +311,7 @@ function prepareSwaggerMethod (schema, ref, swaggerObject, url) {
if (schema.deprecated) swaggerMethod.deprecated = schema.deprecated
if (schema.security) swaggerMethod.security = schema.security
for (const key of Object.keys(schema)) {
if (key.startsWith('x-')) {
if (key.startsWith(CUSTOM_HEADER)) {
swaggerMethod[key] = schema[key]
}
}
Expand Down
Loading