Skip to content

Commit

Permalink
fix: fix type missmatch (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobaha authored Aug 5, 2022
1 parent e1ce5de commit 72e8d9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@coobaha/typed-fastify",
"description": "opinionated types for fastify",
"version": "1.0.0-rc.1",
"version": "1.0.0",
"bin": {
"typed-fastify-schema": "bin/gen.bin.js",
"tfs": "bin/gen.bin.js"
Expand Down
19 changes: 15 additions & 4 deletions src/typed-fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ const addSchema = <
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, Logger>,
SchemaCompiler extends F.FastifySchema = F.FastifySchema,
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
ContextConfig = F.ContextConfigDefault,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider, Logger>,
>(
fastify: F.FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
fastify: F.FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
opts: {
jsonSchema: {
schema: Record<string, any>;
Expand Down Expand Up @@ -72,7 +75,15 @@ const addSchema = <
};
}
});
const httpMethods: Set<F.HTTPMethods> = new Set(['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS']);
const httpMethods: Set<F.HTTPMethods> = new Set([
'DELETE',
'GET',
'HEAD',
'PATCH',
'POST',
'PUT',
'OPTIONS',
] as const);

for (const path in opts.service) {
if (!Object.hasOwnProperty.call(opts.service, path)) continue;
Expand Down Expand Up @@ -447,7 +458,7 @@ export type RequestHandler<
SchemaCompiler = F.FastifySchema,
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, Logger>,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider, Logger>,
Paths = ServiceSchema['paths'],
OpHandler = {
[Path in HandlerPaths]: Handler<
Expand Down
3 changes: 2 additions & 1 deletion test/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import swagger, { FastifyDynamicSwaggerOptions } from '@fastify/swagger';
import fastify from 'fastify';
import addSchema from '../src';
import { defaultService } from './fixtures';
import type { TestSchema } from './test_schema';
import jsonSchema from './test_schema.gen.json';

async function init(): Promise<void> {
Expand All @@ -28,7 +29,7 @@ async function init(): Promise<void> {
exposeRoute: true,
} as FastifyDynamicSwaggerOptions);

addSchema(app, {
addSchema<TestSchema>(app, {
jsonSchema: jsonSchema,
service: defaultService,
});
Expand Down

0 comments on commit 72e8d9b

Please sign in to comment.