MurmurationsNetwork / MurmurationsServices

Index, Library and other microservices that implement the Murmurations protocol
https://docs.murmurations.network/developers/index-api.html
GNU General Public License v3.0
6 stars 3 forks source link

Translate JSON Schema parser error results into readable error messages #389

Closed geoffturk closed 1 week ago

geoffturk commented 1 year ago

https://github.com/xeipuuv/gojsonschema/blob/master/errors.go https://github.com/xeipuuv/gojsonschema/blob/master/locales.go

https://github.com/MurmurationsNetwork/MurmurationsServices/blob/main/pkg/validatenode/validatenode.go https://github.com/MurmurationsNetwork/MurmurationsServices/blob/main/pkg/profile/profilevalidator/profilevalidator.go

geoffturk commented 1 year ago
image
geoffturk commented 3 weeks ago

Ensure all error messages are in a consistent format

All error messages should clearly identify the field that caused the error and the schema(s) which contain that field that failed validation. For example:

{
    "errors": [
        {
            "status": 400,
            "source": {
                "pointer": "/primary_url"
            },
            "title": "Pattern Mismatch",
            "detail": "The submitted data does not match the required pattern: '^https?://.*' - Schema: organizations_schema-v1.0.0"
        }
    ]
}

Here's an example of a profile (https://ic3.dev/murmurations/field-length-limits.json) that is failing validation, and the errors messages are not containing all of fields to easily locate the offending field:

{
    "errors": [
        {
            "status": 400,
            "title": "Invalid Length, max length is 100",
            "detail": "String length exceeded"
        },
        {
            "status": 400,
            "title": "Invalid Length, max length is 3",
            "detail": "String length exceeded"
        },
        {
            "status": 400,
            "title": "Invalid Length, max length is 2000",
            "detail": "String length exceeded"
        },
        {
            "status": 400,
            "source": {
                "pointer": "/tags"
            },
            "title": "Too Many Tags",
            "detail": "Maximum of 100 tags allowed"
        },
        {
            "status": 400,
            "source": {
                "pointer": "/tags"
            },
            "title": "Tag Too Long",
            "detail": "Each tag should be under 100 characters"
        },
        {
            "status": 400,
            "title": "Invalid Length, max length is 200",
            "detail": "String length exceeded"
        },
        {
            "status": 400,
            "title": "Invalid Length, max length is 100",
            "detail": "String length exceeded"
        }
    ]
}