department-for-transport-public / D-TRO

Digital Traffic Regulation Orders (D-TRO)
MIT License
3 stars 1 forks source link

Rules endpoints - escaped/control characters in response #38

Open ajf2 opened 1 week ago

ajf2 commented 1 week ago

Looking at the responses from the rules endpoints, it appears that they contain some control characters and escaped text such as \r, \n, \u003c, \u003d, and \". This doesn't pose too much of a problem, but it would be nice to have it fixed.

For example, calling the get rules by version endpoint, rules/3.2.4, I get this response (truncated for brevity):

{
  "schemaVersion": "3.2.4",
  "template": "[\r\n  {\r\n    \"id\": 1,\r\n    \"message\": \"weekInMonth instances must be unique.\",\r\n    \"name\": \"ExceptionPeriodApplicableInstanceOfDayWithinMonthInstancesUnique\",\r\n    \"path\": \"Source.provision.regulation.timeValidity.exceptionPeriod.recurringDayWeekMonthPeriod.applicableInstanceOfDayWithinMonth\",\r\n    \"rule\": {\r\n      \"all\": [\r\n        {\r\n          \"var\": \"Source.provision\"\r\n        },\r\n        {\r\n          \"all\": [\r\n            {\r\n              \"var\": \"regulation\"\r\n            },\r\n            {\r\n              \"or\": [\r\n                {\r\n                  \"!\": {\r\n                    \"var\": \"timeValidity.exceptionPeriod\"\r\n                  }\r\n                },\r\n                {\r\n                  \"all\": [\r\n                    {\r\n                      \"var\": \"timeValidity.exceptionPeriod\"\r\n                    },\r\n                    {\r\n                      \"or\": [\r\n                        {\r\n                          \"!\": {\r\n                            \"var\": \"recurringDayWeekMonthPeriod\"\r\n                          }\r\n                        },\r\n                        {\r\n                          \"all_unique\": [\r\n                            {\r\n                              \"map\": [\r\n                                {\r\n                                  \"filter\": [\r\n                                    {\r\n                                      \"var\": \"recurringDayWeekMonthPeriod\"\r\n                                    },\r\n                                    {\r\n                                      

...

}

It looks like the value of the template property is being sent as a string, hence the quotes around the array. I would expect a response similar to this (also truncated):

{
  "schemaVersion": "3.2.4",
  "template": [
  {
    "id": 1,
    "message": "weekInMonth instances must be unique.",
    "name": "ExceptionPeriodApplicableInstanceOfDayWithinMonthInstancesUnique",
    "path": "Source.provision.regulation.timeValidity.exceptionPeriod.recurringDayWeekMonthPeriod.applicableInstanceOfDayWithinMonth",
    "rule": {
      "all": [
        {
          "var": "Source.provision"
        },
        {
          "all": [
            {
              "var": "regulation"
            },
            {
              "or": [
                {
                  "!": {
                    "var": "timeValidity.exceptionPeriod"
                  }
                },
                {
                  "all": [
                    {
                      "var": "timeValidity.exceptionPeriod"
                    },
                    {
                      "or": [
                        {
                          "!": {
                            "var": "recurringDayWeekMonthPeriod"
                          }
                        },
                        {
                          "all_unique": [
                            {
                              "map": [
                                {
                                  "filter": [
                                    {
                                      "var": "recurringDayWeekMonthPeriod"
                                    },
                                    {
                                      "!": {
                                        "!": {
                                          "var": "applicableInstanceOfDayWithinMonth"
                                        }
                                      }
                                    }
                                  ]
                                },
                                {
                                  "var": "applicableInstanceOfDayWithinMonth"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },

...

]
}
stm-john-cooper commented 1 week ago

Thanks for raising this issue. We have added it to the backlog.