belgif / rest-guide

REST Guidelines of Belgian government institutions
https://www.belgif.be/specification/rest/api-guide/
Apache License 2.0
26 stars 4 forks source link

problem type identifier #39

Closed pvdbosch closed 3 years ago

pvdbosch commented 4 years ago

In GitLab by @pvdbosch on Nov 14, 2019, 14:02

Proposal to add a standard "code" property to each Problem JSON.

This is inspired on the DigiPolis Antwerp REST guide, but we'd use a more human readable problem code.

possibilities:

"type": "https://b2b-test.ksz-bcss.fgov.be/socialStatus/v1/problems/notFound"
"type": "https://b2b-acpt.ksz-bcss.fgov.be/socialStatus/v1/problems/notFound"
"code": "gCloud:resourceNotFound"
"code": "be.fgov.kszbcss.socialStatus.v1:notFound"
"code": "notFound"

The last option for "code" seemed to be preferred during last WG, i.e. take the last part of the type URL. There is some risk on a new generic gCloud standard problem code overlapping with already existing API-specific ones, but that risk might be small enough to ignore.

pvdbosch commented 4 years ago

In GitLab by @pvdbosch on Nov 14, 2019, 14:37

changed the description

pvdbosch commented 4 years ago

In GitLab by @pvdbosch on Nov 14, 2019, 14:38

changed title from {-environment-independent -}problem code to problem code

pvdbosch commented 4 years ago

up for discussion in a next WG

pvdbosch commented 4 years ago

on a related note: an instance not in URI format doesn't validate (in stoplight) "instance": "d9e35127-e9b1-4201-a211-2b52e52508df"

I've changed the example in common-v1.yaml to the following to make it validate: "instance": "urn:uuid:d9e35127-e9b1-4201-a211-2b52e52508df"

This is a standardized URN format for UUIDs

pvdbosch commented 4 years ago

My proposal:

I think using URNs is better than using relative URIs like zalando recommends because relative URIs should need to be resolved to their full URI to be a unique identifier, and resolving the base URI to which they are relative is context-dependent.

pvdbosch commented 4 years ago

Did some research about what the specs say about URI vs relative URI:

Sources:

pvdbosch commented 3 years ago

discussed on WG of November 2020, but no conclusion yet. A summary of the discussion follows.

Points raised

  1. if something else than absolute URIs are used in "type" (and "instance"), they should according to the Problem JSON spec be interpreted and resolved as relative URIs to get the full problem type identifier. This would lead easily to incorrectly resolved problem types.

For instance, when GET https://something.com/myapi/v1/employers/123 returns a Problem JSON with as "type":

  1. Using another field instead of "type" as problem type identifier isn't conform to the Problem JSON RFC.

Consumers MUST use the "type" string as the primary identifier for the problem type;

"type": A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type

Any 3rd party tooling that works with Problem JSON would search for "type".

  1. You could use the correct full relative URI as problem type: "/myapi/v1/problems/myProblemType"

However:

  1. Using a stable but non-dereferenceable http(s) url as type, is confusing because users might try to dereference it

  2. Compliance of definition of identifiers with ICEG URI standard

not investigated much yet

Also see unresolved discussion on ICEG URI standard and REST APIs in https://github.com/belgif/thematic/issues/31

  1. Desire to prioritize readability over complexity for problem type identifier (i.e. no long URN structure) - Willem

Option 1

Example:

{ "type": "https://b2b-acpt.ksz-bcss.fgov.be/socialStatus/v1/refData/problems/ssinReplaced", "code": "ssinReplaced" }

Option 2

{ "type": "urn:problem-type:ksz-bcss.fgov.be:socialStatus:ssinReplaced", "typeHref": "https://b2b-acpt.ksz-bcss.fgov.be/socialStatus/v1/refData/problems/ssinReplaced" }

This option is similar to this blog but with typeHref added.

TBD:

Option 3

{ "type": "/socialStatus/problems/ssinReplaced", "typeHref": "https://b2b-acpt.ksz-bcss.fgov.be/socialStatus/v1/refData/problems/ssinReplaced" }

3a: relative link within base path This option is similar to Zalando REST guide.

3b: relative link includes full base path (without domain name) => increased dependency on technical URIs in application code

Option 4

"type": "https://b2b-acpt.ksz-bcss.fgov.be/socialStatus/v1/refData/problems/ssinReplaced"

type always has absolute URL (env-dependent) clients should parse type to retrieve identifier

pvdbosch commented 3 years ago

My preference would be to maintain compliance with the Problem RFC and restrict our usage further to forbid relative URIs; avoiding complexity to resolve them correctly.

For problem type identifiers either:

Other issues:

pvdbosch commented 3 years ago

type should be a URI or relative URI that is env-independent string and stable over time

If it's a relative URL (starting with /) or absolute one, it should be dereferenceable. If it's a URN, not dereferenceable.

type: type: string format: uri => format: uri-reference

not accepted yet ; decision deferred

pvdbosch commented 3 years ago

summarized options in https://github.com/belgif/rest-guide/wiki/problem-type-identifiers , with trade-offs in the table at the end of the page

pvdbosch commented 3 years ago

Results of dedicated meeting on problem type are on wiki:

pvdbosch commented 3 years ago

WG agreed on chosen solution. We'll document it with rationale for deviation from RFC standard. We'll try to provide this feedback also to the RFC via appropriate channel.

pvdbosch commented 3 years ago

PRs #80 and https://github.com/belgif/openapi-problem/pull/3 ready for review

Not discussed in WG yet: #80 specifies /refData/problemTypes/{problemType} as URL-template for API-specific problem type doc

pvdbosch commented 3 years ago

reviewed together in WG. Merged - will be part of next guide update.