Skip to content

POC: produce Swagger documentation for subiquity's API#2338

Draft
ogayot wants to merge 2 commits intocanonical:mainfrom
ogayot:aiohttp-apispec
Draft

POC: produce Swagger documentation for subiquity's API#2338
ogayot wants to merge 2 commits intocanonical:mainfrom
ogayot:aiohttp-apispec

Conversation

@ogayot
Copy link
Copy Markdown
Member

@ogayot ogayot commented Mar 11, 2026

Using python3-aiohttp-apispec, one can now document our API using @docs decorators in subiquity/common/apidef.py. I did a very simple example (without specifying the parameters and response schema).

The swagger.json file can be downloaded at /swagger.json

{
  "paths": {
    "/ssh": {
      "get": {
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "parameters": [],
        "summary": "Get SSH configuration",
        "description": "Return the current SSH configuration, including whether the SSH server is installed and enabled, and whether SSH keys are imported. ",
        "produces": [
          "application/json"
        ]
      },
      "post": {
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "parameters": [],
        "summary": "Configure the SSH server",
        "description": "Configure if the SSH server is installed and enabled.\nOne can also pass SSH keys to be added as authorized keys for the user.",
        "produces": [
          "application/json"
        ]
      }
    }
  },
  "info": {
    "title": "Subiquity API documentation",
    "version": "v1"
  },
  "swagger": "2.0"
}

It can then be fed to local tools or online tools such as https://editor.swagger.io/

Example on editor.swagger.io:

Screenshot from 2026-03-12 19-32-15

@ogayot ogayot changed the title POC: produce OpenAPI docs for subiquity's API POC: produce Swagger documentation for subiquity's API Mar 11, 2026
ogayot added 2 commits March 12, 2026 19:31
Using python3-aiohttp-apispec, one can now document our API using @docs
decorators in subiquity/common/apidef.py.

The swagger.json file (legacy OpenAPI) can be downloaded at /swagger.json:

 $ curl --unix-socket socket http://a/swagger.json

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant