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

API validationError response is invalid, content_type for repoGetRawFile & repoGetArchive #21997

Open
commonism opened this issue Dec 1, 2022 · 0 comments
Labels

Comments

@commonism
Copy link

Description

There is a mismatch in the definition of the

  • validationError
  • error
    (and most likely all responses without properties but header only fields) and the response.

The content_type for the response of

  • repoGetRawFile
  • repoGetArchive
    mismatches the spec.

using aiopenapi3 master

import random
import string
import codecs

from aiopenapi3 import OpenAPI, ResponseSchemaError, ContentTypeError

import pytest

@pytest.fixture()
def TOKEN():
    return "API TOKEN SHA1"

def test_gitea(TOKEN):
    api = OpenAPI.load_sync("https://try.gitea.io/swagger.v1.json")

    api.authenticate(AuthorizationHeaderToken=f"token {TOKEN}")

    user = api._.userGetCurrent()
    repo = "".join(random.choice(string.ascii_lowercase) for i in range(6))

    DEFAULTS = {"repo":repo, "owner":user.login}


    body = api._.createCurrentUserRepo.data.get_type().construct(name=repo, private=True, default_branch="main")
    repo = api._.createCurrentUserRepo(data=body)

    body = api._.repoCreateFile.data.get_type().construct(content=codecs.encode(b"# README", "base64"))
    api._.repoCreateFile(parameters={**DEFAULTS, "filepath":"README.md"}, data=body)

    branch = "test"
    body = api._.repoCreateBranch.data.get_type().construct(new_branch_name=branch, old_branch_name="main")
    data = api._.repoCreateBranch(parameters=DEFAULTS, data=body)

    with pytest.raises(ResponseSchemaError) as e:
        body = api._.repoCreatePullRequest.data.get_type().construct(base=branch, head=branch, title="important!")
        api._.repoCreatePullRequest(parameters=DEFAULTS, data=body)
    assert e.value.expectation.ref == '#/responses/validationError'
    assert e.value.schema == None
    assert e.value.response.content != None
    assert set(e.value.response.json().keys()).issubset(set(["message","url"]))


    with pytest.raises(ContentTypeError) as e:
        data = api._.repoGetRawFile(parameters={**DEFAULTS, "filepath": "README.md"})
    assert e.value.content_type.partition("/")[0] == "text"
    assert e.value.operation.produces == ["application/json"]

    with pytest.raises(ContentTypeError) as e:
        data = api._.repoGetArchive(parameters={**DEFAULTS, "archive":f"{branch}.tar.gz"})
    assert e.value.content_type == "application/octet-stream"
    assert e.value.operation.produces == ["application/json"]

    api._.repoDelete(parameters=DEFAULTS)

Gitea Version

1.19.0+dev-139-g67881ae99

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

using https://try.gitea.io/

Database

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant