java-gitea-api icon indicating copy to clipboard operation
java-gitea-api copied to clipboard

Get content from a directory

Open apiphoque opened this issue 2 years ago • 1 comments

Description

Hi everyone, I am having some troubles with this specific function : repoGetContents(...)

When I use this with a filename, it works perfectly, even if the file is in a directory.

However, when I do it with a directory I get an error :

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
	at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:395) ~[gson-2.9.1.jar:na]
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:259) ~[gson-2.9.1.jar:na]
	at com.google.gson.Gson.fromJson(Gson.java:1058) ~[gson-2.9.1.jar:na]
	at com.google.gson.Gson.fromJson(Gson.java:1016) ~[gson-2.9.1.jar:na]
	at com.google.gson.Gson.fromJson(Gson.java:959) ~[gson-2.9.1.jar:na]
	at io.gitea.JSON.deserialize(JSON.java:137) ~[java-gitea-api-1.16.8.jar:na]
	at io.gitea.ApiClient.deserialize(ApiClient.java:720) ~[java-gitea-api-1.16.8.jar:na]
	at io.gitea.ApiClient.handleResponse(ApiClient.java:923) ~[java-gitea-api-1.16.8.jar:na]
	at io.gitea.ApiClient.execute(ApiClient.java:850) ~[java-gitea-api-1.16.8.jar:na]
	at io.gitea.api.RepositoryApi.repoGetContentsWithHttpInfo(RepositoryApi.java:9215) ~[java-gitea-api-1.16.8.jar:na]
	at io.gitea.api.RepositoryApi.repoGetContents(RepositoryApi.java:9198) ~[java-gitea-api-1.16.8.jar:na]
[...]

I think the problem is that this function returns a ContentsResponse, and in the case of a directory, we want a List<ContentsResponse>.

    public ContentsResponse repoGetContents(String owner, String repo, String filepath, String ref) throws ApiException {
        ApiResponse<ContentsResponse> resp = repoGetContentsWithHttpInfo(owner, repo, filepath, ref);
        return resp.getData();
    }

Note : I tested the directory name multiple times, with the actual Gitea API on postman, it works, I also tried multiples writing for my directory name such as "dir" "/dir" "dir/" or "/dir/', they all get the same error.

Maybe I'm missing something, its the first time I'm using this projet...

Gitea version

1.18.5

Can you reproduce the bug on the Gitea demo site?

As I mentionned I tried the routes with Postman and it works fine, I get a list of ContentResponse.

Operating system

Windows 10

How are you running Gitea ?

I have a docker image running on my computer, its on localhost:3000

apiphoque avatar Mar 28 '23 10:03 apiphoque

I have encountered the same issue. Did you by any chance find a way to fix it?

Nio520 avatar Aug 08 '23 12:08 Nio520