Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace typeof undefined check #766

Merged
merged 1 commit into from
Oct 29, 2023
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
8 changes: 4 additions & 4 deletions lib/spec/openapi/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ function plainJsonObjectToOpenapi3 (container, jsonSchema, externalSchemas, secu
const jsonSchema = toOpenapiProp(propKey, obj[propKey])
if (jsonSchema.schema) {
// it is needed as required in schema is invalid prop - delete only if needed
if (typeof jsonSchema.schema.required !== 'undefined') delete jsonSchema.schema.required
if (jsonSchema.schema.required !== undefined) delete jsonSchema.schema.required
// it is needed as description in schema is invalid prop - delete only if needed
if (typeof jsonSchema.schema.description !== 'undefined') delete jsonSchema.schema.description
if (jsonSchema.schema.description !== undefined) delete jsonSchema.schema.description
}
return jsonSchema
})
Expand Down Expand Up @@ -252,7 +252,7 @@ function schemaToMedia (schema) {

function resolveBodyParams (body, schema, consumes, ref) {
const resolved = transformDefsToComponents(ref.resolve(schema))
if ((Array.isArray(consumes) && consumes.length === 0) || typeof consumes === 'undefined') {
if ((Array.isArray(consumes) && consumes.length === 0) || consumes === undefined) {
consumes = ['application/json']
}

Expand Down Expand Up @@ -339,7 +339,7 @@ function resolveResponse (fastifyResponseJson, produces, ref) {
} else {
const content = {}

if ((Array.isArray(produces) && produces.length === 0) || typeof produces === 'undefined') {
if ((Array.isArray(produces) && produces.length === 0) || produces === undefined) {
produces = ['application/json']
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/resolve-local-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { rawRequired } = require('../symbols')
const { xConsume } = require('../constants')

function resolveLocalRef (jsonSchema, externalSchemas) {
if (typeof jsonSchema.type !== 'undefined' && typeof jsonSchema.properties !== 'undefined') {
if (jsonSchema.type !== undefined && jsonSchema.properties !== undefined) {
// for the shorthand querystring/params/headers declaration
const propertiesMap = Object.keys(jsonSchema.properties).reduce((acc, headers) => {
const rewriteProps = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/resolve-swagger-function.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

function resolveSwaggerFunction (opts, cache, routes, Ref, done) {
if (typeof opts.openapi === 'undefined' || opts.openapi === null) {
if (opts.openapi === undefined || opts.openapi === null) {
return require('../spec/swagger')(opts, cache, routes, Ref, done)
} else {
return require('../spec/openapi')(opts, cache, routes, Ref, done)
Expand Down
Loading