api-management-developer-portal icon indicating copy to clipboard operation
api-management-developer-portal copied to clipboard

Samples for response definitions with Problem JSON content type failing to show in developer portal

Open sykesjd opened this issue 3 years ago • 2 comments

Bug description

In the event a response definition for an endpoint is specified to have content type of application/problem+json (per RFC 7807), the sample for that response definition will not display properly on the developer portal page for that endpoint, instead displaying the generic JavaScript [object Object]. If the content type is changed to application/json for the endpoint response, the sample will display as normal.

This bug is a recent addition, as we've been using application/problem+json for a while and haven't had any problems with it until recently. Unfortunately, we don't know the exact time this problem started occurring.

Reproduction steps

  1. Under an APIM instance in Azure Portal, go to 'APIs'.
  2. Select an API from the left side bar of the resulting pane.
  3. Select 'Definitions'.
  4. Select '+ Add definition'.
  5. Give the definition the name RFC7807Response.
  6. Paste the definition provided below into the 'Payload' field.
  7. Select 'Create definition'.
  8. Select 'Operations'.
  9. Select '+ Add operation'.
  10. Give the operation any name, verb, and URL.
  11. Select 'Responses'.
  12. Select '+ Add response'.
  13. Select status code 400.
  14. Specify 'Content Type' as application/problem+json.
  15. Paste the sample sample provided below into the 'Sample' field.
  16. Select RFC7807Response for the 'Definition' field.
  17. Select 'Save'.
  18. In a new tab, navigate to the API Details page for the API in the APIM instance's developer portal.
  19. Select the new API endpoint.
  20. Scroll down to the table view for the 400 response definition.

Definition:

{
    "required": [
        "Status",
        "Title"
    ],
    "type": "object",
    "properties": {
        "Status": {
            "type": "integer",
            "description": "HTTP status code returned"
        },
        "Title": {
            "type": "string",
            "description": "Primary message for the error"
        },
        "Detail": {
            "type": "string",
            "description": "Secondary message for the error, if applicable"
        },
        "Errors": {
            "type": "object",
            "additionalProperties": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            },
            "description": "(string, string[]) dictionary of parameter-specific problems for a semantic error, if applicable"
        }
    }
}

Sample:

{"Status":400,"Title":"The provided parameters failed to validate.","Errors":{"operation":["is badly formatted in the body."]}}

Expected behavior

The following is provided under 'Example' for the 400 response definition:

{
    "Status": 400,
    "Title": "The provided parameters failed to validate.",
    "Errors": {
        "operation": ["is badly formatted in the body."]
    }
}

Actual behavior

The following is provided under 'Example' for the 400 response definition:

[object Object]

Is your portal managed or self-hosted?

Managed

API Management service name

qa-resku-rga-apim Offending definition is RFC7807Response, which is used on all endpoints as the response definition for 400, 401, 422, and 500 responses 400 response on endpoint 'Close RA' was updated to application/json to verify the problem was specific to application/problem+json Custom domain for portal: https://qa-rga-docs.reskureturns.com/

Environment

  • Operating system: Windows 10 (latest)
  • Browser: Google Chrome, Microsoft Edge
  • Version: 95, 95 (respectively)

sykesjd avatar Oct 28 '21 14:10 sykesjd

@sykesjd, thank you for opening this issue. We will triage it within the next few business days.

msftbot[bot] avatar Oct 28 '21 14:10 msftbot[bot]

@sykesjd, thank you for reporting the bug.

msftbot[bot] avatar Nov 01 '21 17:11 msftbot[bot]