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

JSON validation schema #156

Open
rfmoz opened this issue Sep 12, 2023 · 1 comment
Open

JSON validation schema #156

rfmoz opened this issue Sep 12, 2023 · 1 comment
Assignees

Comments

@rfmoz
Copy link

rfmoz commented Sep 12, 2023

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,

@rfmoz
Copy link
Author

rfmoz commented Sep 25, 2023

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"]
}

@clelland clelland self-assigned this Sep 25, 2023
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

No branches or pull requests

2 participants