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

[TT-12440] Update jsonschema support note #5916

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

titpetric
Copy link
Contributor

@titpetric titpetric commented Jan 22, 2025

User description

https://tyktech.atlassian.net/browse/TT-12440


PR Type

Documentation


Description

  • Updated JSON schema validation note for middleware.

  • Added explanation of schema draft detection behavior.

  • Removed outdated note on supported JSON schema version.


Changes walkthrough 📝

Relevant files
Documentation
validate-request-tyk-classic.md
Update JSON schema validation note and behavior explanation

tyk-docs/content/product-stack/tyk-gateway/middleware/validate-request-tyk-classic.md

  • Added details on schema draft detection using $schema.
  • Updated note to reflect hybrid mode for missing $schema.
  • Removed outdated reference to draft-04 as the only supported version.
  • Minor formatting adjustments for better readability.
  • +4/-3     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @titpetric titpetric requested a review from andyo-tyk January 22, 2025 12:24
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Clarity of Schema Draft Detection Explanation

    The explanation of schema draft detection behavior added in the note should be reviewed for clarity and accuracy to ensure users can easily understand the behavior and implications of the hybrid mode.

    **Note**
    
    By default the validator will try to detect the draft of a schema by using the $schema keyword and parse it in a strict draft-04, draft-06 or draft-07 mode. If $schema is missing, or the draft version is not explicitely set, a hybrid mode is used which merges together functionality of all drafts into one mode.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Clarify hybrid mode behavior explanation

    Clarify the behavior of the validator when $schema is missing or the draft version
    is not explicitly set, as the term "hybrid mode" might be ambiguous to users
    unfamiliar with its implications.

    tyk-docs/content/product-stack/tyk-gateway/middleware/validate-request-tyk-classic.md [67]

    -By default the validator will try to detect the draft of a schema by using the $schema keyword and parse it in a strict draft-04, draft-06 or draft-07 mode. If $schema is missing, or the draft version is not explicitely set, a hybrid mode is used which merges together functionality of all drafts into one mode.
    +By default, the validator attempts to detect the schema draft using the $schema keyword and parses it in strict draft-04, draft-06, or draft-07 mode. If $schema is missing or the draft version is not explicitly set, the validator operates in a hybrid mode, combining functionalities of all drafts. This hybrid mode may lead to unexpected behavior if schema features from different drafts conflict.
    Suggestion importance[1-10]: 7

    Why: The suggestion improves clarity by elaborating on the potential implications of the hybrid mode, which could help users better understand its behavior and avoid unexpected issues. However, the improvement is not critical, as the original explanation is already functional. The score reflects its moderate impact on documentation quality.

    7

    Copy link

    netlify bot commented Jan 22, 2025

    PS. Pls add /docs/nightly to the end of url

    Name Link
    🔨 Latest commit 3108ee0
    🔍 Latest deploy log https://app.netlify.com/sites/tyk-docs/deploys/6790e3591745ad00076df6fd
    😎 Deploy Preview https://deploy-preview-5916--tyk-docs.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link

    netlify bot commented Jan 22, 2025

    PS. Pls add /docs/nightly to the end of url

    Name Link
    🔨 Latest commit 3455ea7
    🔍 Latest deploy log https://app.netlify.com/sites/tyk-docs/deploys/6798dd8521da860008544546
    😎 Deploy Preview https://deploy-preview-5916--tyk-docs.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link
    Contributor

    @sharadregoti sharadregoti left a comment

    Choose a reason for hiding this comment

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

    @titpetric @andyo-tyk Can we remove the note and add the below section instead?


    The Validate JSON middleware supports JSON Schema `draft-04`. Using another version will return an `unsupported schema error, unable to validate` error in the Tyk Gateway logs.
    By default the validator will try to detect the draft of a schema by using the $schema keyword and parse it in a strict draft-04, draft-06 or draft-07 mode. If $schema is missing, or the draft version is not explicitly set, a hybrid mode is used which merges together functionality of all drafts into one mode.

    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Understanding JSON Schema Version Handling

    The Gateway automatically detects the version of the JSON schema from the $schema field in your schema definition. This field specifies the version of the JSON schema standard to be followed. Supported versions are draft-04, draft-06 and draft-07.

    • If the $schema field is present, the Gateway strictly follows the rules of the specified version.
    • If the $schema field is missing or the version is not specified, the Gateway uses a hybrid mode that combines features from multiple schema versions. This mode ensures that the validation will still work, but may not enforce the exact rules of a specific version.

    To ensure consistent and predictable validation, it is recommended to always include the $schema field in your schema definition. For example:

    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {
        "firstname": {
          "type": "string"
        },
        "lastname": {
          "type": "string"
        }
      }
    }

    By including $schema, the validator can operate in strict mode, ensuring that the rules for your chosen schema version are followed exactly.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants