nitro icon indicating copy to clipboard operation
nitro copied to clipboard

defineRouteMeta needs to take a type parameter for examples value

Open airtonix opened this issue 1 month ago • 0 comments

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?

airtonix avatar Jun 03 '24 03:06 airtonix