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

Align error format with Commonalities guidelines #104

Merged

Conversation

jlurien
Copy link
Collaborator

@jlurien jlurien commented Jan 25, 2023

As discussed in issue #97, we have to align current error model and examples to the guidelines:

  • Add new status property
  • Created new Generic500 response and $ref all previous instances

As discussed in issue [camaraproject#97](camaraproject#97), we have to align current error model and examples to the guidelines:

- Add new `status` property
- Created new `Generic500` response and $ref all previous instances
@hdamker
Copy link
Collaborator

hdamker commented Jan 25, 2023

@jlurien Short question: is this PR intended for the minor fix release (which I want to close "now") or already for v0.9? As status is a required field, it might fit better into v0.9.0?

@jlurien
Copy link
Collaborator Author

jlurien commented Jan 25, 2023

@jlurien Short question: is this PR intended for the minor fix release (which I want to close "now") or already for v0.9? As status is a required field, it might fit better into v0.9.0?

0.9 definitely

sfnuser
sfnuser previously approved these changes Jan 25, 2023
Schemas for GenericXXX responses must restrict the ErrorInfo model to the allowed values at `status`  and `code` for  every specific response
@hdamker
Copy link
Collaborator

hdamker commented Jan 28, 2023

Added rewievers @eric-murray @patrice-conil as discussed within our call. @sfnuser please renew your review as well. Thanks!

@patrice-conil
Copy link
Collaborator

Hi @jlurien,
Just a sample to illustrate my review
ErrorInfo definition may look like this:

ErrorInfo:
discriminator: type
type: object
required:
- type
- status
- code
- message
properties:
type:
description: The error class name
type: "string"
status:
type: string
pattern: "^[4-5][0-9]{2}$"
description: HTTP status code returned along with this error response
code:
type: string
description: Code given to this error
message:
type: string
description: Detailed error description

@jlurien
Copy link
Collaborator Author

jlurien commented Jan 30, 2023

Hi @jlurien, Just a sample to illustrate my review ErrorInfo definition may look like this:

ErrorInfo: discriminator: type type: object required: - type - status - code - message properties: type: description: The error class name type: "string" status: type: string pattern: "^[4-5][0-9]{2}$" description: HTTP status code returned along with this error response code: type: string description: Code given to this error message: type: string description: Detailed error description

Hi @patrice-conil, have you commented in the file? I guess this is about the problem you mentioned in the meeting with allOf for some openapi generator. ErrorModel is defined in the commonalities so any change should be aligned there. But in case we decide to define a discriminator to the base class, we could use the existent status or code for this, along with a mapping. Adding a new required property type is would repeat the same information.

Another alternative, as we are not reusing that much of the base ErrorModel, it is just to add the message property to all GenericXXXResponses and remove the allOf. I would not be surprised if some tool has problems as well with OAS3 mapping as that is not supported in legacy Swagger 2.

@patrice-conil
Copy link
Collaborator

Hi @jlurien, yes I commented in the file. and it is indeed linked to the problem that I mentioned last Friday. I agree with you, this mapping should do the trick... but it's quite new and probably not so well supported by generators.
I think simplifying the generation of client side is one way to have a usable API. Perhaps we should spend more time documenting our validation rules than documenting sample responses to describe the behaviour of our proposal.

example:
status: "403"
code: FORBIDDEN
message: "Operation not allowed: ..."
SessionNotFound404:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Generic404 as Generic403, Generic401 ?
All these errors are specialization of ErrorInfo ... usage is to define a type or @type field as discriminator in ErrorInfo to help deserializer to manage subtype deserialization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have named it Generic404 as well, but as the only case in this API for 404 was Session Not Found, I chose a more specific name and added an explicit message in the example. Problem with Generic responses is that example has to be generic as well. For automatic API publishing in a web portal it is convenient to embed good examples in the spec, but for client generation purposes it may complicate things.

I can change the name to Generic404 if that is more coherent with the rest of responses

@jlurien
Copy link
Collaborator Author

jlurien commented Jan 30, 2023

Hi @jlurien, yes I commented in the file. and it is indeed linked to the problem that I mentioned last Friday. I agree with you, this mapping should do the trick... but it's quite new and probably not so well supported by generators. I think simplifying the generation of client side is one way to have a usable API. Perhaps we should spend more time documenting our validation rules than documenting sample responses to describe the behaviour of our proposal.

I only see the latest comment about Generic404. If mapping is not well supported, I prefer to remove the allOf that adding an additional property @type in the API spec for all errors to overcome the limitation, as that would add too much redundancy in the response:

HTTP 404
{ 
  "@type": "Generic404",
  "status": "404"
  "code": "NOT_FOUND",
  "message": "Session not found"
}

code/API_definitions/qod-api.yaml Outdated Show resolved Hide resolved
code/API_definitions/qod-api.yaml Outdated Show resolved Hide resolved
code: NOT_FOUND
message: "Session Id does not exist"
Generic500:
description: Server error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better naming would be "Internal Server Error" for the description of a 500 - Internal Server Error.

enum: ["500"]
code:
type: string
enum: ["INTERNAL"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what "INTERNAL" means.
Better use the following naming:

enum: ["INTERNAL_SERVER_ERROR"]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Internal Server Error" is also the description for the status code "500" within Hypertext Transfer Protocol (HTTP) Status Code Registry. Therefore +1 .

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on aligning as much as possible to standard HTTP terms.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have aligned the codes with the ones in Commonalities, and currently they define INTERNAL for 500 and UNAVAILABLE for 503. code has not to be necessarily the description of the HTTP code, but in any case, the discussion for this should be moved to Commonalities.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for now ... we just should get a conclusion on that before we close v0.9.0.

- `status` is now an integer
- `code` values aligned with Commonalities (INVALID_ARGUMENT, UNAUTHENTICATED, PERMISSION_DENIED...)
- Specific schemas defined for all errors, so `ErrorInfo` schema is not used. I have created a new issue in Commonalities to decide whether to reference specific model per error or the common model: <camaraproject/WorkingGroups#151>. When a common approach is decided we should align this to it.
@jlurien
Copy link
Collaborator Author

jlurien commented Feb 8, 2023

Please review the latest version. Some comments:

  • status is now an integer
  • code values aligned with Commonalities (INVALID_ARGUMENT, UNAUTHENTICATED, PERMISSION_DENIED...)
  • Specific schemas defined for all errors, so ErrorInfo schema is not used. I have created a new issue in Commonalities to decide whether to reference specific model per error or the common model: Schemas in error responses WorkingGroups#151. When a common approach is decided we should align this to it.

@hdamker
Copy link
Collaborator

hdamker commented Feb 9, 2023

LGTM, just asking @patrice-conil @maxl2287 @eric-murray for a final review (and closing remarks for the open conversations).

@hdamker hdamker requested review from eric-murray and maxl2287 and removed request for maxl2287 February 9, 2023 07:05
@eric-murray
Copy link
Collaborator

Is it intended to approve and merge this PR before Commonalities Issue #151 is resolved?

@jlurien
Copy link
Collaborator Author

jlurien commented Feb 9, 2023

Is it intended to approve and merge this PR before Commonalities Issue #151 is resolved?

We could merge it as it is now and later update the $refs to the right schemas, and remove the unused ones. Indeed I have intentionally left the ErrorInfo schema even if it is currently unused.

@hdamker hdamker merged commit 39f9c9b into camaraproject:main Feb 10, 2023
@jlurien jlurien deleted the chore/errors-alignment-with-guidelines branch February 13, 2023 08:58
@hdamker hdamker mentioned this pull request Jun 17, 2023
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

Successfully merging this pull request may close these issues.

6 participants