[Schema Inaccuracy] "Add labels to an issue" requestBody and description incorrect

Open
#3,366 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
openapi
Domain
api

Research direction

Start by locating the OpenAPI definition for POST /repos/{owner}/{repo}/issues/{issue_number}/labels and compare its requestBody schemas and descriptions with the behavior documented in this issue. Done means the endpoint description, accepted forms, and minItems constraints accurately reflect the observed API behavior.

Written by the indexing model from the issue text.

Description

feature fundamentals-and-support inaccuracy rest-schema shield waiting for review

Schema Inaccuracy

For POST /repos/{owner}/{repo}/issues/{issue_number}/labels, the description is currently

Adds labels to an issue. If you provide an empty array of labels, all labels are removed from the issue.

and the requestBody is documented as

The names of the labels to add to the issue's existing labels. You can pass an empty array to remove all labels. Alternatively, you can pass a single label as a string or an array of labels directly, but GitHub recommends passing an object with the labels key. You can also replace all of the labels for an issue. For more information, see "Set labels for an issue.

and the schema specifies, in effect:

  1. a lone $string
  2. an array of $strings
  3. an array of {name: $string}
  4. an object with a single property labels whose value is an array of strings
  5. an object with a single property labels whose value is an array of {name: $string}

incorrect description

First off, the descriptions (of both the endpoint and the requestBody) assert that passing an empty array will remove all the labels, this does not happen, it may have been copied over from the "set labels for an issue" endpoint.

incorrect minItems

On every array, the schema declares minItems: 1, this seems to be untrue for form (2) / (3) which does accept an empty array (it just does nothing), it is true for form 4/5

(1) is not valid

Trying to pass a naked string to the endpoint results in a validation error:

r = session.post(
    f'{pr.issue_url}/labels',
    json="test",
)

=>

{"message":"Invalid request.\n\nNo subschema in \"anyOf\" matched.\nFor 'anyOf/0', \"test\" is not an array.\nFor 'anyOf/1', \"test\" is not an array.\nFor 'anyOf/2', \"test\" is not an object.","documentation_url":"https://docs.github.com/rest/issues/labels#add-labels-to-an-issue"}

(5) is not valid

Trying to pass a nested record results in a validation error:

r = session.post(
    f'{pr.issue_url}/labels',
    json={"labels": [{"name": "test"}]},
)

=>

{"message":"Invalid request.\n\nNo subschema in \"anyOf\" matched.\nFor 'anyOf/0', {\"labels\"=>[{\"name\"=>\"test\"}]} is not an array.\nFor 'anyOf/1', {\"labels\"=>[{\"name\"=>\"test\"}]} is not an array.\nFor 'items', {\"name\"=>\"test\"} is not a string.","documentation_url":"https://docs.github.com/rest/issues/labels#add-labels-to-an-issue"}
Dominant language
No language data
Stars
1.6k
Forks
342
Avg merge
3h 33m
Merged PRs (30d)
51

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/rest-api-description

All issues in github/rest-api-description

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.