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

Supporting different content-type responses #79

Closed
2 tasks done
WoH opened this issue Nov 28, 2022 · 1 comment · Fixed by #83
Closed
2 tasks done

Supporting different content-type responses #79

WoH opened this issue Nov 28, 2022 · 1 comment · Fixed by #83
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@WoH
Copy link
Contributor

WoH commented Nov 28, 2022

Prerequisites

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

🚀 Feature Proposal

This plugin does not support response validation in combination with different content types.

Motivation

While not supported by this plugin, both fastify and swagger support it already:

Example

The following setup is supported by @fastify/swagger(-ui), but does not work when used with the fastify response validation plugin:

    {
      schema: {
        body: Polygon,
        response: {
          200: {
            description: "Success",
            content: {
              "application/geo+json": {
                schema: FeatureCollection,
              },
            },
          },
      },
  }

Results are errors, but at the end of the day, it just does not seem to be intended.

ERROR (110): strict mode: unknown keyword: "application/geo+json"
    err: {
      "type": "Error",
      "message": "strict mode: unknown keyword: \"application/geo+json\"",
      "stack":
          Error: strict mode: unknown keyword: "application/geo+json"
              at checkStrictMode (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/util.js:174:15)
              at checkUnknownRules (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/util.js:32:13)
              at alwaysValidSchema (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/util.js:19:5)
              at <anonymous> (/node_modules/@fastify/response-validation/node_modules/ajv/dist/vocabularies/applicator/properties.js:23:63)
              at Array.filter (<anonymous>)
              at Object.code (/node_modules/@fastify/response-validation/node_modules/ajv/dist/vocabularies/applicator/properties.js:23:37)
              at keywordCode (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/validate/index.js:454:13)
              at <anonymous> (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/validate/index.js:222:17)
              at CodeGen.code (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/codegen/index.js:439:13)
              at CodeGen.block (/node_modules/@fastify/response-validation/node_modules/ajv/dist/compile/codegen/index.js:568:18)
    }
ERROR (62): schema is invalid: data/properties/description must be object,boolean
    err: {
      "type": "Error",
      "message": "schema is invalid: data/properties/description must be object,boolean",
      "stack":
          Error: schema is invalid: data/properties/description must be object,boolean
              at Ajv.validateSchema (/node_modules/@fastify/response-validation/node_modules/ajv/dist/core.js:266:23)
              at Ajv._addSchema /node_modules/@fastify/response-validation/node_modules/ajv/dist/core.js:460:18)
              at Ajv.compile (/node_modules/@fastify/response-validation/node_modules/ajv/dist/core.js:158:26)
              at buildHook /node_modules/@fastify/response-validation/index.js:46:37)
              at Object.onRoute (/node_modules/@fastify/response-validation/index.js:38:34)
              at Object.addNewRoute (/node_modules/fastify/lib/route.js:243:16)
              at Object.route (/node_modules/fastify/lib/route.js:217:19)
              at Object.prepareRoute (/node_modules/fastify/lib/route.js:150:18)
              at Object._post (/node_modules/fastify/fastify.js:258:34)
              [...]
@mcollina
Copy link
Member

mcollina commented Dec 2, 2022

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcollina mcollina added enhancement New feature or request good first issue Good for newcomers labels Dec 2, 2022
WoH added a commit to WoH/fastify-response-validation that referenced this issue Dec 22, 2022
WoH added a commit to WoH/fastify-response-validation that referenced this issue Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants