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

Item schema: add more detail to the code sample #51

Open
tyssejc opened this issue Dec 20, 2022 · 0 comments
Open

Item schema: add more detail to the code sample #51

tyssejc opened this issue Dec 20, 2022 · 0 comments

Comments

@tyssejc
Copy link
Contributor

tyssejc commented Dec 20, 2022

Issue

The point of a schema is to impose strict rules around how data should be structured.

It's not clear from the code sample:

  • what the type of each value should be
  • what the minimum/maximum length should be
  • what regex pattern it should match

https://github.com/searchdiscovery/client-jnj-ga4-dl-spec/blob/c89eb6b620313668e77041fae439c8a7a32e34a7/schemas/item.md?plain=1#L7-L36

As a result, at least one property ("price") has been implemented as a string and not a number. This was missed in QA and UAT.

Suggestions

1. express as a TypeScript interface

interface EventMessage {
  item_id: string;
  price: number;
  affiliation?: string;
}

2. express as JSON schema

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "affiliation": {
      "type": "string"
    },
    "item_id": {
      "type": "string"
    },
    "price": {
       "type": "number",
       "pattern": "/\d+\.\d{2,}"
  },
  "required": [
    "item_id"
  ]
}

The nice thing about JSON Schema is that those rules can be ingested by automated testing software and used in assertions.

adding comments to the code sample is not sufficient!

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

1 participant