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

Aliased Attribute Names Are Not Used In Error Responses #1447

Open
4 tasks
ghost opened this issue Feb 5, 2024 · 0 comments
Open
4 tasks

Aliased Attribute Names Are Not Used In Error Responses #1447

ghost opened this issue Feb 5, 2024 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 5, 2024

This issue is a (choose one):

  • [X ] Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • [ X] I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • [ X] The feature I'm asking for is compliant with the JSON:API spec.

Description

I have a model with an attribute named status_is_active. In the API we want this to render as active so do the following in the resource:

attribute :active, delegate: :status_is_active

If there is an API error related to this attribute, the error reports the name from the model rather than the name from the resource. For example:

{
  "errors": [
    {
      "title": "is not included in the list",
      "detail": "status_is_active - is not included in the list",
      "code": "100",
      "source": {
          "pointer": "/data/attributes/status_is_active"
      },
      "status": "422"
    }
  ]
}

Expected: the error uses the name of the attribute in the resource rather than the name used in the model. For example:

{
  "errors": [
    {
      "title": "is not included in the list",
      "detail": "active - is not included in the list",
      "code": "100",
      "source": {
          "pointer": "/data/attributes/active"
      },
      "status": "422"
    }
  ]
}

Rationale: users of the API only know about what's in the API - returning a value from the model that is aliased in the API is confusing/wrong.

Thanks!

@ghost ghost changed the title Error Response Does Not Honor Delegated Attribute Aliased Attribute Names Are Not Used In Error Responses Feb 5, 2024
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

No branches or pull requests

0 participants