Skip to content

JSON validation schema #156

Open
Open

Description

@rfmoz

Hello,

Receiving the json reports from anywhere force to implement some filtering capabilities before store their content into the backend.

It would be helpful to have a JSON Schema with the predefined fields that are expected in the request.

Maybe this task is something that the parse consumers are forced to perform, but nowadays, each in their own personalized way.

Thanks,

Activity

  1. rfmoz commented on Sep 25, 2023

    @rfmoz
    Author

    After getting 10M samples and validate them, this is a working proposal:

    {
      "$schema": "http://json-schema.org/2020-12/schema#",
      "type": "object",
      "properties": {
        "age": {
          "type": "integer"
        },
        "body": {
          "type": "object"
        },
        "type": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "user_agent": {
          "type": "string"
        }
      },
      "required": ["age", "body", "type", "url", "user_agent"]
    }
    

    But, is it possible to narrow the schema for every different type:

    Crash:

    {
      "$schema": "http://json-schema.org/2020-12/schema#",
      "type": "object",
      "properties": {
        "age": {
          "type": "integer"
        },
        "body": {
          "type": "object",
          "properties": {
            "reason": {
              "type": "string"
            }
          }
        },
        "type": {
          "type": "string",
          "const": "crash"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "user_agent": {
          "type": "string"
        }
      },
      "required": ["age", "body", "type", "url", "user_agent"]
    }
    

    Deprecation:

    {
      "$schema": "http://json-schema.org/2020-12/schema#",
      "type": "object",
      "properties": {
        "age": {
          "type": "integer"
        },
        "body": {
          "type": "object",
          "properties": {
            "columnNumber": {
              "type": "integer"
            },
            "id": {
              "type": "string"
            },
            "lineNumber": {
              "type": "integer"
            },
            "message": {
              "type": "string"
            },
            "sourceFile": {
              "type": "string",
              "format": "uri"
            }
          },
          "required": ["id", "message"]
        },
        "type": {
          "type": "string",
          "const": "deprecation"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "user_agent": {
          "type": "string"
        }
      },
      "required": ["age", "body", "type", "url", "user_agent"]
    }
    

    Intervention:

      "$schema": "http://json-schema.org/2020-12/schema#",
      "title": "intervention",
      "type": "object",
      "properties": {
        "age": {
          "type": "integer"
        },
        "body": {
          "type": "object",
          "properties": {
            "columnNumber": {
              "type": "integer"
            },
            "id": {
              "type": "string"
            },
            "lineNumber": {
              "type": "integer"
            },
            "message": {
              "type": "string"
            },
            "sourceFile": {
              "type": "string",
              "format": "uri"
            }
          },
          "required": ["message"]
        },
        "type": {
          "type": "string",
          "const": "intervention"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "user_agent": {
          "type": "string"
        }
      },
      "required": ["age", "body", "type", "url", "user_agent"]
    }
    

    Network Error:

    {
      "$schema": "http://json-schema.org/2020-12/schema#",
      "type": "object",
      "properties": {
        "age": {
          "type": "integer"
        },
        "body": {
          "type": "object",
          "properties": {
            "elapsed_time": {
              "type": "integer"
            },
            "method": {
              "type": "string"
            },
            "phase": {
              "type": "string"
            },
            "protocol": {
              "type": "string"
            },
            "referrer": {
              "type": "string",
              "format": "uri"
            },
            "sampling_fraction": {
              "type": "number"
            },
            "server_ip": {
              "type": "string",
              "format": "ipv4"
            },
            "status_code": {
              "type": "integer"
            },
            "type": {
              "type": "string"
            }
          },
          "required": ["elapsed_time", "method", "phase", "protocol", "referrer", "sampling_fraction", "server_ip", "status_code", "type"]
        },
        "type": {
          "type": "string",
          "const": "network-error"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "user_agent": {
          "type": "string"
        }
      },
      "required": ["age", "body", "type", "url", "user_agent"]
    }
    
  2. self-assigned this
    on Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions