Skip to content

Commit

Permalink
feat: define api and generate swagger file
Browse files Browse the repository at this point in the history
Signed-off-by: richardli1598 <opennaslab@gmail.com>
  • Loading branch information
richardli1598 committed Oct 14, 2023
1 parent 05f2310 commit 57b9dc3
Show file tree
Hide file tree
Showing 14 changed files with 521 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bifrost-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
args: --timeout=30m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
Expand Down
133 changes: 133 additions & 0 deletions api/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions api/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"swagger": "2.0",
"info": {
"description": "Take you to the land of light, the city of freedom(A unified external service management system for NAS).",
"title": "bifrost API",
"termsOfService": "http://swagger.io/terms/",
"contact": {},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "0.1"
},
"basePath": "/api/v1",
"paths": {
"/steps": {
"get": {
"description": "List all supported bifrost steps",
"produces": [
"application/json"
],
"tags": [
"Steps"
],
"summary": "List all bifrost steps",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/opennaslab_io_bifrost_pkg_customapi.StepInfoList"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {
"opennaslab_io_bifrost_pkg_customapi.Documentation": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/opennaslab_io_bifrost_pkg_customapi.Documentation"
}
},
"name": {
"type": "string"
},
"required": {
"type": "boolean"
},
"type": {
"type": "string"
}
}
},
"opennaslab_io_bifrost_pkg_customapi.StepInfo": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"image": {
"type": "string"
},
"name": {
"type": "string"
},
"parameters": {
"$ref": "#/definitions/opennaslab_io_bifrost_pkg_customapi.StepParameter"
}
}
},
"opennaslab_io_bifrost_pkg_customapi.StepInfoList": {
"type": "object",
"properties": {
"steps": {
"type": "array",
"items": {
"$ref": "#/definitions/opennaslab_io_bifrost_pkg_customapi.StepInfo"
}
}
}
},
"opennaslab_io_bifrost_pkg_customapi.StepParameter": {
"type": "object",
"properties": {
"in": {
"type": "array",
"items": {
"$ref": "#/definitions/opennaslab_io_bifrost_pkg_customapi.Documentation"
}
}
}
}
}
}
71 changes: 71 additions & 0 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
basePath: /api/v1
definitions:
opennaslab_io_bifrost_pkg_customapi.Documentation:
properties:
description:
type: string
items:
items:
$ref: '#/definitions/opennaslab_io_bifrost_pkg_customapi.Documentation'
type: array
name:
type: string
required:
type: boolean
type:
type: string
type: object
opennaslab_io_bifrost_pkg_customapi.StepInfo:
properties:
description:
type: string
image:
type: string
name:
type: string
parameters:
$ref: '#/definitions/opennaslab_io_bifrost_pkg_customapi.StepParameter'
type: object
opennaslab_io_bifrost_pkg_customapi.StepInfoList:
properties:
steps:
items:
$ref: '#/definitions/opennaslab_io_bifrost_pkg_customapi.StepInfo'
type: array
type: object
opennaslab_io_bifrost_pkg_customapi.StepParameter:
properties:
in:
items:
$ref: '#/definitions/opennaslab_io_bifrost_pkg_customapi.Documentation'
type: array
type: object
info:
contact: {}
description: Take you to the land of light, the city of freedom(A unified external
service management system for NAS).
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: http://swagger.io/terms/
title: bifrost API
version: "0.1"
paths:
/steps:
get:
description: List all supported bifrost steps
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/opennaslab_io_bifrost_pkg_customapi.StepInfoList'
"500":
description: Internal Server Error
schema:
type: string
summary: List all bifrost steps
tags:
- Steps
swagger: "2.0"
9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ import (
"opennaslab.io/bifrost/pkg/server"
)

// @title bifrost API
// @version 0.1
// @description Take you to the land of light, the city of freedom(A unified external service management system for NAS).
// @termsOfService http://swagger.io/terms/

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @BasePath /api/v1
func main() {
opt := options.NewBifrostDBOptions()
if err := opt.Validate(); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@ require (
github.com/docker/docker v24.0.6+incompatible
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2
gorm.io/driver/mysql v1.5.1
gorm.io/gorm v1.25.4
k8s.io/klog v1.0.0
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
Expand All @@ -29,10 +39,12 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -54,6 +66,7 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
)
Loading

0 comments on commit 57b9dc3

Please sign in to comment.