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

defineRouteMeta needs to take a type parameter for examples value #2490

Open
1 task
airtonix opened this issue Jun 3, 2024 · 0 comments
Open
1 task

defineRouteMeta needs to take a type parameter for examples value #2490

airtonix opened this issue Jun 3, 2024 · 0 comments

Comments

@airtonix
Copy link

airtonix commented Jun 3, 2024

Describe the feature


defineRouteMeta({
  openAPI: {
    tags: ["test"],
    description: "Test route description",
    requestBody: {
      required: true,
      content: {
        "application/json": {
          description: "Payload",
          summary: "Payload",
          schema: SomeInputSchemaJson,
          examples: {
            my_correct_example {
              summary: "an awesome example",
              value: {
                 yayValidField: 'nice'
              },
            },
            my_incorrect_example {
              summary: "oops",
              value: {
                 failTrain: 'lmao'
              },
            },
          },
        },
      },
    },
    responses: {
      "200": {
        summary: "Success",
        description: "Success",
        content: {
          "application/json": {
            encoding: {},
            schema: SomeOutputSchemaJson,
          },
        },
      },
    },
  },
});

Given the above route meta, we should be able to ensure that we get type safety when inserting incorrect example data structure :

defineRouteMeta<SomeInput>({
  openAPI: {
    tags: ["test"],
    description: "Test route description",
    requestBody: {
      required: true,
      content: {
        "application/json": {
          description: "Payload",
          summary: "Payload",
          schema: SomeInputSchemaJson,
          examples: {
            my_correct_example {
              summary: "an awesome example",
              value: {
                 yayValidField: 'nice'
              },
            },
            my_incorrect_example {
              summary: "oops",
              value: {
                 failTrain: 'lmao' 👈👈👈👈👈👈👈👈 should now show error
              },
            },
          },
        },
      },
    },
    responses: {
      "200": {
        summary: "Success",
        description: "Success",
        content: {
          "application/json": {
            encoding: {},
            schema: SomeOutputSchemaJson,
          },
        },
      },
    },
  },
});

Additional information

  • Would you be willing to help implement this feature?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant