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] Experiment with utoipa for API #1916

Closed
wants to merge 1 commit into from
Closed

Conversation

banool
Copy link
Contributor

@banool banool commented Jul 12, 2022

Description

This is an experiment using utoipa to generate our OpenAPI spec. This is what it spits out:

{

  "openapi": "3.0.3",
  "info": {
    "title": "aptos-api",
    "description": "Aptos REST API",
    "contact": {
      "name": "Aptos Labs",
      "email": "[email protected]"
    },
    "license": {
      "name": "Apache-2.0"
    },
    "version": "0.1.0"
  },
  "paths": {
    "/": {
      "get": {
        "tags": [
          "crate"
        ],
        "description": "",
        "operationId": "index",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IndexResponse"
                }
              }
            }
          },
          "500": {
            "description": "Error"
          }
        },
        "deprecated": false
      }
    }
  },
  "components": {
    "schemas": {
      "IndexResponse": {
        "type": "object",
        "required": [
          "ledger_info",
          "node_role"
        ],
        "properties": {
          "node_role": {
            "$ref": "#/components/schemas/RoleType"
          },
          "ledger_info": {
            "$ref": "#/components/schemas/LedgerInfo"
          }
        },
        "description": "The struct holding all data returned to the client by the"
      },
      "U64": {
        "type": "integer",
        "format": "int64"
      },
      "LedgerInfo": {
        "type": "object",
        "required": [
          "chain_id",
          "epoch",
          "ledger_version",
          "oldest_ledger_version",
          "ledger_timestamp"
        ],
        "properties": {
          "ledger_version": {
            "$ref": "#/components/schemas/U64"
          },
          "oldest_ledger_version": {
            "$ref": "#/components/schemas/U64"
          },
          "ledger_timestamp": {
            "$ref": "#/components/schemas/U64"
          },
          "chain_id": {
            "type": "integer",
            "format": "int32"
          },
          "epoch": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "RoleType": {
        "type": "string",
        "enum": [
          "validator",
          "full_node"
        ]
      }
    }
  }
}

Off the bat there are few issues compared to Poem (#1906):

There is more experimentation I could do if we wanted to go with this route, I haven't looked into how it handles more complex paths, errors, etc.

The main win with utoipa is you can use whatever framework you want, but that results in you needing to do more work yourself, leading to more opportunities for mistakes.

Naturally this is not exactly how I'd actually integrate utoipa, this is just to demonstrate what it'd look like.

Test Plan


This change is Reviewable

@banool banool force-pushed the banool/utoipa_openapi branch from 6286224 to dd1160e Compare July 12, 2022 15:26
@banool banool requested review from gregnazario, JoshLind and davidiw and removed request for gregnazario July 12, 2022 16:41
@banool
Copy link
Contributor Author

banool commented Jul 22, 2022

Abandoning this, utoipa isn't quite there yet.

@banool banool closed this Jul 22, 2022
@banool banool deleted the banool/utoipa_openapi branch July 22, 2022 03:14
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