yorkie-team / yorkie

Yorkie is a document store for collaborative applications.
https://yorkie.dev
Apache License 2.0
783 stars 145 forks source link

Add ConnectRPC Spec Definition for API Documentation #804

Closed devleejb closed 8 months ago

devleejb commented 8 months ago

What would you like to be added:

With the introduction of ConnectPRC, allowing REST API calls, it is necessary to document the specification. Using methods like OpenAPI to define the spec would enable the use of convenient GUI tools like Swagger.

Tools like protoc-gen-connect-openapi can automatically generate OpenAPI documentation from proto files.

The execution result is as shown below.

image image

This will not only benefit REST API users but also aid in API development.

Why is this needed:

Documenting the ConnectRPC specification will provide better understanding and usability of the API, benefiting both users and developers alike.

krapie commented 8 months ago

We might want to add this to our documentation for API usage 👍🏼

devleejb commented 8 months ago

@krapie Does the documentation mean Yorkie Docs, right?

krapie commented 8 months ago

@devleejb Yes, just like Firebase.

Screenshot 2024-03-04 at 8 20 39 PM

Edit: liveblocks API references seems to be the perfect example :)

hackerwins commented 8 months ago

We can also refer to the following:

devleejb commented 8 months ago

Can I try it?

hackerwins commented 8 months ago

@devleejb Sure. You're a maintainer of this project.

devleejb commented 8 months ago

I've made the modifications in buf.gen.yaml:

version: v1
plugins:
  - plugin: go
    out: api
    opt: paths=source_relative
  - plugin: connect-go
    out: api
    opt: paths=source_relative
  - plugin: connect-openapi
    out: api/docs
    opt:
      - base=api/docs/yorkie.base.yaml

The generated OpenAPI Spec can be served using the Swagger UI container, and I've added the corresponding command to the Makefile:

docker-swagger:
    docker run -p 3000:8080 \
        -e URLS="[ \
            { url: 'docs/yorkie/v1/admin.openapi.yaml', name: 'Admin' }, \
            { url: 'docs/yorkie/v1/resources.openapi.yaml', name: 'Resources' }, \
            { url: 'docs/yorkie/v1/yorkie.openapi.yaml', name: 'Yorkie' }  \
        ]" \
        -v `pwd`/api/docs:/usr/share/nginx/html/docs/ \
        swaggerapi/swagger-ui

As a result, when accessing the served documents, they will be displayed as shown in the image below:

image

However, adding the Authentication option in the connect-openapi library causes an error. I have reported this issue to the library's repository and will create a PR after resolving it. Link to the GitHub Issue

After incorporating these changes, the following updates are required for the Yorkie Document: