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

Improve docs: add more details for JSON schema validation #277

Closed
2 tasks done
radomird opened this issue Oct 1, 2021 · 2 comments · Fixed by #280
Closed
2 tasks done

Improve docs: add more details for JSON schema validation #277

radomird opened this issue Oct 1, 2021 · 2 comments · Fixed by #280

Comments

@radomird
Copy link
Contributor

radomird commented Oct 1, 2021

Prerequisites

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

Issue

When validating non-file fields in the body and NOT using the shared schema, according to the plugin documentation, we can validate the fields by using the following syntax:

body: {
  type: 'object',
  properties: {
    hello: {
      properties: {
        value: { 
          type: 'string',
        }
      }
    }
 }

However one would expect that for the non-file fields (like this for example: { "hello": "world"} ) the JSON schema for validation would be:

body: {
  type: 'object',
  properties: {
    hello: {
      type: 'string'
    }
  }
}

just like it's mentioned in the fastify docs.

However, the plugin converts the non-file fields from this:

{ "hello": "world"}

to this:

{ 
  hello: {
    fieldname: "hello",
    value: "world",
    fieldnameTruncated: false,
    valueTruncated: false,
    fields: body
  }
}

and therefore the validation schema on top (from the plugin docs) makes sense.

However, the problem is that this conversion is not mentioned anywhere in the documentation and it's just really confusing and leads to issues like this: fastify/help#525 (comment)

I would suggest to mention the conversion which would explain why is the validation schema defined like it is.

@mcollina
Copy link
Member

mcollina commented Oct 1, 2021

Would you like to send a PR?

@radomird
Copy link
Contributor Author

radomird commented Oct 4, 2021

@mcollina Sure, will do that.

@Eomm Eomm closed this as completed in #280 Oct 4, 2021
Eomm added a commit that referenced this issue Oct 4, 2021
…280)

* Updated README.md with relevant information about the sharedSchemaId. #276

* Improve docs: added more details on field conversion [#277]

* Fixed typo

* Added an example for the non-file field validation

* Apply suggestions from code review

Minor styling changes on the text.

Co-authored-by: Manuel Spigolon <[email protected]>

* Minor wording update

Co-authored-by: Manuel Spigolon <[email protected]>
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 a pull request may close this issue.

2 participants