belgif / openapi-problem

OpenAPI data types for problem messages
Apache License 2.0
10 stars 5 forks source link

Consider renaming the "in" property of InputValidationIssue #9

Open webketje opened 1 year ago

webketje commented 1 year ago

The word in is a reserved keyword in many languages used for web programming (Python, Javascript, C#, Groovy and probably many others). This makes it hard to access it from an object without extra safeguards:

Javascript example:

belgifError.issues[0].detail   // ok
belgifError.issues[0].in       // SyntaxError
belgifError.issues[0]['in']    // clunky, disables type checking in Typescript

Or even requires developers to add a mapping layer as in C#:

class BelgifInputValidationIssue
{
  string in = "body";  // error CS1519: Unexpected symbol `in'

  static void Main(string[] args)
  {
    BelgifInputValidationIssue instance = new BelgifInputValidationIssue();
  }
}

Possible alternative: context? location? origin? request_component?

(PS: I work for with belgif-conforming API's at BOSA but this is my personal account)

pvdbosch commented 1 year ago

The "name" property can be used to describe the full location, like in the example in the guide : https://www.belgif.be/specification/rest/api-guide/#bad-request

   {
      "type": "urn:problem-type:belgif:input-validation:schemaViolation",
      "in": "body",
      "name": "mandator.enterpriseNumber",
      "value": "123456",
      "detail": "An enterprise number should be 10 digits long"
    }

We didn't want to mandate this, because it can be tricky to implement this correctly depending on framework used. The in parameter name was chosen to be consistent with how it's defined in OpenAPI, but this could be weighed against language support.

JDMKSZ commented 1 year ago

The OpenAPI code generator handles this. Reserved keywords are prefixed by a '_'. See AbstractCSharpCodegen.java