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

Not showing type error for status codes not in schema #74

Open
2 tasks done
SEAN-7 opened this issue Jan 27, 2024 · 0 comments
Open
2 tasks done

Not showing type error for status codes not in schema #74

SEAN-7 opened this issue Jan 27, 2024 · 0 comments

Comments

@SEAN-7
Copy link

SEAN-7 commented Jan 27, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.25.2

Plugin version

3.0.0

Node.js version

20.10.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.3

Description

In my schema, I've specified that the only response code is 201. However, if I write my handler as returning a 200, I don't get a type error:

Steps to Reproduce

import { FastifyPluginAsyncJsonSchemaToTs } from "@fastify/type-provider-json-schema-to-ts"

const plugin: FastifyPluginAsyncJsonSchemaToTs = async function (
    fastify,
    _opts
) {
    fastify.post(
        "/sign-up",
        {
            schema: {
                response: {
                    201: {
                        type: "object",
                        properties: {
                            email: { type: "string" },
                        },
                        required: ["email"],
                    },
                },
            },
        },
        async (_, reply) => {
            return reply.status(200).send() // This should show a type error on status 200 because not in schema
        }
    )
}

export default plugin

Expected Behavior

When using generics, it'll show a type error on 200 which I believe is the desired behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant