Skip to content

Commit

Permalink
fix linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Dec 8, 2024
1 parent 216bceb commit 58c9e8f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 75 deletions.
54 changes: 11 additions & 43 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { FastifyPluginCallback, FastifySchema, RouteOptions, onRequestHookHandler, preHandlerHookHandler } from 'fastify'
import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
import { FastifyPluginCallback, FastifySchema, RouteOptions } from 'fastify'
import {
OpenAPI,
OpenAPIV2,
OpenAPIV3,
// eslint-disable-next-line camelcase
OpenAPIV3_1
} from 'openapi-types'

/**
* Swagger-UI Vendor Extensions
Expand Down Expand Up @@ -61,6 +67,7 @@ declare module 'fastify' {
type SwaggerDocumentObject = {
swaggerObject: Partial<OpenAPIV2.Document>;
} | {
// eslint-disable-next-line camelcase
openapiObject: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>;
}

Expand All @@ -75,6 +82,7 @@ type SwaggerTransform = <S extends FastifySchema = FastifySchema>({
route: RouteOptions;
} & SwaggerDocumentObject) => { schema: FastifySchema; url: string }

// eslint-disable-next-line camelcase
type SwaggerTransformObject = (documentObject: SwaggerDocumentObject) => Partial<OpenAPIV2.Document> | Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>

type FastifySwagger = FastifyPluginCallback<fastifySwagger.SwaggerOptions>
Expand All @@ -85,42 +93,6 @@ declare namespace fastifySwagger {
mode?: 'static' | 'dynamic';
}

export type FastifySwaggerUiConfigOptions = Partial<{
deepLinking: boolean
displayOperationId: boolean
defaultModelsExpandDepth: number
defaultModelExpandDepth: number
defaultModelRendering: string
displayRequestDuration: boolean
docExpansion: string
filter: boolean | string
layout: string
maxDisplayedTags: number
showExtensions: boolean
showCommonExtensions: boolean
useUnsafeMarkdown: boolean
syntaxHighlight: {
activate?: boolean
theme?: string
} | false
tryItOutEnabled: boolean
validatorUrl: string | null
supportedSubmitMethods: Array<'get' | 'post' | 'put' | 'delete' | 'patch' | 'options'>
persistAuthorization: boolean
}>

export type FastifySwaggerInitOAuthOptions = Partial<{
clientId: string,
clientSecret: string,
realm: string,
appName: string,
scopeSeparator: string,
scopes: string | string[],
additionalQueryStringParams: { [key: string]: any },
useBasicAuthenticationWithAccessCodeGrant: boolean,
usePkceWithAuthorizationCodeGrant: boolean
}>

type JSONValue =
| string
| null
Expand All @@ -136,6 +108,7 @@ declare namespace fastifySwagger {
export interface FastifyDynamicSwaggerOptions extends FastifySwaggerOptions {
mode?: 'dynamic';
swagger?: Partial<OpenAPIV2.Document>;
// eslint-disable-next-line camelcase
openapi?: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>
hiddenTag?: string;
hideUntagged?: boolean;
Expand Down Expand Up @@ -195,11 +168,6 @@ declare namespace fastifySwagger {
specification: StaticPathSpec | StaticDocumentSpec;
}

export type FastifySwaggerUiHooksOptions = Partial<{
onRequest?: onRequestHookHandler,
preHandler?: preHandlerHookHandler,
}>

export function formatParamUrl (paramUrl: string): string

export const fastifySwagger: FastifySwagger
Expand Down
2 changes: 1 addition & 1 deletion test/types/http2-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ app
}
}
})
.ready(err => {
.ready(() => {
app.swagger()
})
2 changes: 1 addition & 1 deletion test/types/imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ app.register(fastifySwagger, fastifySwaggerOptions)
app.register(fastifySwaggerStar.default, fastifySwaggerOptions)
app.register(fastifySwaggerStar.fastifySwagger, fastifySwaggerOptions)

app.ready((err) => {
app.ready(() => {
app.swagger()
})
13 changes: 7 additions & 6 deletions test/types/swagger-ui-vendor-extensions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OpenAPIV2, OpenAPIV3 } from 'openapi-types'
import { expectAssignable } from 'tsd'

const xTokenNameOpenAPIv3: OpenAPIV3.Document = {
expectAssignable<OpenAPIV3.Document>({
openapi: '3.0.0',
info: {
version: '1.0.0',
Expand All @@ -21,9 +22,9 @@ const xTokenNameOpenAPIv3: OpenAPIV3.Document = {
}
},
paths: {}
}
})

const xTokenNameOpenAPIv2: OpenAPIV2.Document = {
expectAssignable<OpenAPIV2.Document>({
swagger: '2.0.0',
info: {
title: 'Test OpenApiv2 specification',
Expand Down Expand Up @@ -61,9 +62,9 @@ const xTokenNameOpenAPIv2: OpenAPIV2.Document = {
},
},
paths: {}
}
})

const xExampleOpenAPIv2: OpenAPIV2.Document = {
expectAssignable<OpenAPIV2.Document>({
swagger: '2.0.0',
info: {
title: 'Test OpenApiv2 specification',
Expand Down Expand Up @@ -109,4 +110,4 @@ const xExampleOpenAPIv2: OpenAPIV2.Document = {
}
}
}
}
})
37 changes: 13 additions & 24 deletions test/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@ import fastify, { FastifySchema, RouteOptions } from 'fastify'
import fastifySwagger, {
formatParamUrl,
SwaggerOptions,
FastifySwaggerInitOAuthOptions,
FastifySwaggerUiConfigOptions,
FastifySwaggerUiHooksOptions,
} from '../..'
import { minimalOpenApiV3Document } from './minimal-openapiV3-document'
import { expectType } from 'tsd'
import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'

import {
OpenAPI,
OpenAPIV2,
OpenAPIV3,
// eslint-disable-next-line camelcase
OpenAPIV3_1
} from 'openapi-types'

const app = fastify()
const uiConfig: FastifySwaggerUiConfigOptions = {
deepLinking: true,
defaultModelsExpandDepth: -1,
defaultModelExpandDepth: 1,
validatorUrl: null,
layout: 'BaseLayout',
supportedSubmitMethods: ['get'],
persistAuthorization: false,
}
const initOAuth: FastifySwaggerInitOAuthOptions = {
scopes: ['openid', 'profile', 'email', 'offline_access'],
}
const uiHooks: FastifySwaggerUiHooksOptions = {
onRequest: (request, reply, done) => { done() },
preHandler: (request, reply, done) => { done() },
}

app.register(fastifySwagger)
app.register(fastifySwagger, {})
Expand Down Expand Up @@ -157,7 +145,7 @@ app
}
}
})
.ready(err => {
.ready(() => {
app.swagger()
})

Expand Down Expand Up @@ -186,7 +174,7 @@ app
},
}
})
.ready((err) => {
.ready(() => {
app.swagger()
})

Expand All @@ -205,13 +193,13 @@ app.register(fastifySwagger, {
}
},
})
.ready((err) => {
.ready(() => {
app.swagger()
})

app.register(fastifySwagger, {
})
.ready((err) => {
.ready(() => {
app.swagger()
})

Expand All @@ -228,6 +216,7 @@ app.get(
schema satisfies FastifySchema
url satisfies string
route satisfies RouteOptions
// eslint-disable-next-line camelcase
documentObject satisfies { swaggerObject: Partial<OpenAPIV2.Document> } | { openapiObject: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document> }
return { schema, url }
},
Expand Down

0 comments on commit 58c9e8f

Please sign in to comment.