Skip to content

OpenAPI: Generated C# client crashes on empty collection response #1375

Closed
@bkoelman

Description

@bkoelman

When a JsonApiDotNetCore server returns the response for getting a primary collection endpoint, but there are no matching resources, it returns only the self link in the response (no pagination links).

This crashes a generated C# client, which expects the first link to always exist. This is because the OAS file defines the first link as required:

"linksInResourceCollectionDocument": {
  "required": [
    "first",
    "self"
  ],
  "type": "object",
  "properties": {
    "self": {
      "minLength": 1,
      "type": "string"
    },
    "describedby": {
      "type": "string"
    },
    "first": {
      "minLength": 1,
      "type": "string"
    },
    "last": {
      "type": "string"
    },
    "prev": {
      "type": "string"
    },
    "next": {
      "type": "string"
    }
  },
  "additionalProperties": false
}

As far as I'm aware, there is no such requirement that the first link must always appear in the GET response of a collection request.
Therefore I believe the generated OAS file should be corrected to not have first in the set of required properties.

The same applies to linksInResourceIdentifierCollectionDocument.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions