Skip to content

Horizon Server API: Specify content type as "application/json" and provide a response for all errors to enhance tooling support #20

@PatrickDittrich

Description

@PatrickDittrich

In order to enhance tooling support please specify the content type as application/json instead of */* and return a model for each response

I had success with adding a APIErrorResponseInfo model to the schamas and was then able to use Microsoft Kiota to generate an working rest client.

"components": {
  "schemas": {
    "....": {
    },
    "APIErrorResponseInfo": {
      "type": "object",
      "properties": {
        "errors": {
          "type": "array",
          "items": {
            "$ref": "#/components/schemas/APIError"
          },
          "description": "List of error objects containing error key and error message."
        },
        "status": {
          "type": "string",
          "description": "Response HTTP status code of the operation.",
          "example": "BAD_REQUEST"
        },
        "timestamp": {
          "type": "integer",
          "description": "Timestamp in milliseconds when the operation failed. Measured as epoch time.",
          "format": "int64",
          "example": 1763739153178
        }
      },
      "description": "Response for a failed API call."
    }
  }
}

And as example the modified refreshAccessToken definition

"/refresh": {
  "post": {
    "tags": [
      "Auth"
    ],
    "summary": "Refreshes access token from refresh token.",
    "operationId": "refreshAccessToken",
    "requestBody": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/RefreshToken"
          }
        }
      },
      "required": true
    },
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AccessToken"
            }
          }
        }
      },
      "400": {
        "description": "Bad Request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIErrorResponseInfo"
            }
          }
        }
      },
      "429": {
        "description": "Too many requests",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIErrorResponseInfo"
            }
          }
        }
      },
      "500": {
        "description": "Internal Server Error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIErrorResponseInfo"
            }
          }
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions