Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(docs): host swagger doc by github page (#427)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
RogerLamTd and davidtaikocha committed Oct 18, 2023
1 parent d33e19b commit ab4e613
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 24 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Swagger

on:
push:
branches:
- main

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
name: Swagger autogen docs
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
cache: true

- name: install swag cli
run: go install github.com/swaggo/swag/cmd/swag@latest

- name: swag init
run: ./scripts/gen_swagger_json.sh

deploy:
if: ${{ always() }}
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
name: github pages deploy swagger docs
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v2

- name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: '.'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
22 changes: 14 additions & 8 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const docTemplate = `{
},
"license": {
"name": "MIT",
"url": "hhttps://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md"
"url": "https://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md"
},
"version": "{{.Version}}"
},
Expand All @@ -38,7 +38,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/server.ProposeBlockResponse"
"$ref": "#/definitions/prover_server.ProposeBlockResponse"
}
},
"422": {
Expand All @@ -64,15 +64,15 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/server.Status"
"$ref": "#/definitions/prover_server.Status"
}
}
}
}
}
},
"definitions": {
"server.ProposeBlockResponse": {
"prover_server.ProposeBlockResponse": {
"type": "object",
"properties": {
"prover": {
Expand All @@ -86,7 +86,7 @@ const docTemplate = `{
}
}
},
"server.Status": {
"prover_server.Status": {
"type": "object",
"properties": {
"currentCapacity": {
Expand All @@ -95,7 +95,13 @@ const docTemplate = `{
"maxExpiry": {
"type": "integer"
},
"minProofFee": {
"minOptimisticTierFee": {
"type": "integer"
},
"minPseZkevmTierFee": {
"type": "integer"
},
"minSgxTierFee": {
"type": "integer"
}
}
Expand All @@ -106,10 +112,10 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "prover-api.test.taiko.xyz",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "Taiko Prover API",
Title: "Taiko Prover Server API",
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
Expand Down
21 changes: 13 additions & 8 deletions docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
"title": "Taiko Prover API",
"title": "Taiko Prover Server API",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
Expand All @@ -10,11 +10,10 @@
},
"license": {
"name": "MIT",
"url": "hhttps://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md"
"url": "https://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md"
},
"version": "1.0"
},
"host": "prover-api.test.taiko.xyz",
"paths": {
"/assignment": {
"post": {
Expand All @@ -30,7 +29,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/server.ProposeBlockResponse"
"$ref": "#/definitions/prover_server.ProposeBlockResponse"
}
},
"422": {
Expand All @@ -56,15 +55,15 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/server.Status"
"$ref": "#/definitions/prover_server.Status"
}
}
}
}
}
},
"definitions": {
"server.ProposeBlockResponse": {
"prover_server.ProposeBlockResponse": {
"type": "object",
"properties": {
"prover": {
Expand All @@ -78,7 +77,7 @@
}
}
},
"server.Status": {
"prover_server.Status": {
"type": "object",
"properties": {
"currentCapacity": {
Expand All @@ -87,7 +86,13 @@
"maxExpiry": {
"type": "integer"
},
"minProofFee": {
"minOptimisticTierFee": {
"type": "integer"
},
"minPseZkevmTierFee": {
"type": "integer"
},
"minSgxTierFee": {
"type": "integer"
}
}
Expand Down
19 changes: 11 additions & 8 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
definitions:
server.ProposeBlockResponse:
prover_server.ProposeBlockResponse:
properties:
prover:
type: string
Expand All @@ -8,26 +8,29 @@ definitions:
type: integer
type: array
type: object
server.Status:
prover_server.Status:
properties:
currentCapacity:
type: integer
maxExpiry:
type: integer
minProofFee:
minOptimisticTierFee:
type: integer
minPseZkevmTierFee:
type: integer
minSgxTierFee:
type: integer
type: object
host: prover-api.test.taiko.xyz
info:
contact:
email: [email protected]
name: API Support
url: https://community.taiko.xyz/
license:
name: MIT
url: hhttps://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md
url: https://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md
termsOfService: http://swagger.io/terms/
title: Taiko Prover API
title: Taiko Prover Server API
version: "1.0"
paths:
/assignment:
Expand All @@ -41,7 +44,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/server.ProposeBlockResponse'
$ref: '#/definitions/prover_server.ProposeBlockResponse'
"422":
description: prover does not have capacity
schema:
Expand All @@ -58,6 +61,6 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/server.Status'
$ref: '#/definitions/prover_server.Status'
summary: Get current prover server status
swagger: "2.0"
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<head>
<!-- Load the latest Swagger UI code and style from npm using unpkg.com -->
<script src="https://unpkg.com/[email protected]/swagger-ui-bundle.js"></script>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/swagger-ui.css" />
<title>Prover Server API</title>
</head>
<body>
<div id="swagger-ui"></div> <!-- Div to hold the UI component -->
<script>
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "docs/swagger.json", //Location of Open API spec in the repo
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
})
window.ui = ui
}
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions prover/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import (
"github.com/taikoxyz/taiko-client/pkg/rpc"
)

// @title Taiko Prover Server API
// @version 1.0
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url https://community.taiko.xyz/
// @contact.email [email protected]

// @license.name MIT
// @license.url https://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md

// CreateAssignmentRequestBody represents a request body when handling assignment creation request.
type CreateAssignmentRequestBody struct {
FeeToken common.Address
Expand Down
3 changes: 3 additions & 0 deletions scripts/gen_swagger_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#/bin/sh

swag init -g prover/server/api.go --parseDependency

0 comments on commit ab4e613

Please sign in to comment.