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

Fixes validation when using shared schemas #226

Conversation

leorossi
Copy link

It checks if querystring is a string rather than an object, then finds the related fastify schema (if exists), and use that object to generate swagger doc.

Fixes: #224

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@@ -202,7 +204,13 @@ function consumesFormOnly (schema) {
)
}

function getQueryParams (parameters, query) {
function getQueryParams (parameters, query, fastifySchemas) {
if (typeof query === 'string' && query.match(/#$/)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we have this problem also for the body if it is a string?

Copy link
Contributor

@SkeLLLa SkeLLLa Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be the problem with body, params, headers and all the stuff that accepts schemas as references.

This issue actually Fastify's regression fastify/fastify#2104

@@ -5,6 +5,8 @@ const path = require('path')
const yaml = require('js-yaml')

module.exports = function (fastify, opts, next) {
const fastifySchemas = fastify.getSchemas()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some concerns about using fastify.getSchemas(), cause they will return schemes only from "current" scope. So in this fix will only support those schemes which are defined through fastify plugin.

In order to support all cases you'll probably need to get them recursively from all contexts. See https://github.com/SkeLLLa/fastify-oas/blob/master/lib/openapi/index.js#L5 for example.

@SkeLLLa
Copy link
Contributor

SkeLLLa commented Mar 10, 2020

I think this issue was resolved in fastify/fastify#2108.

@mcollina mcollina closed this Mar 10, 2020
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

Successfully merging this pull request may close these issues.

Querystring not working with shared schema
3 participants