-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,178 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package api | ||
|
||
import ( | ||
"embed" | ||
"io/fs" | ||
"net/http" | ||
) | ||
|
||
//go:embed doc.swagger.json | ||
var doc embed.FS | ||
|
||
func OpenAPIHandler() http.Handler { | ||
// Use subdirectory in embedded files | ||
subFS, err := fs.Sub(doc, ".") | ||
if err != nil { | ||
panic("couldn't create sub filesystem: " + err.Error()) | ||
} | ||
return http.FileServer(http.FS(subFS)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "helloworld demo api definition", | ||
"version": "1.0", | ||
"contact": { | ||
"name": "douyu", | ||
"url": "https://github.com/douyu/proto" | ||
} | ||
}, | ||
"tags": [ | ||
{ | ||
"name": "helloworld.v1.GreeterService" | ||
}, | ||
{ | ||
"name": "Project 001", | ||
"description": "This is how we do it.", | ||
"externalDocs": { | ||
"description": "Find out more", | ||
"url": "https://github.com/douyu/proto" | ||
} | ||
} | ||
], | ||
"consumes": [ | ||
"application/x-www-form-urlencoded" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"paths": { | ||
"/v1/helloworld.Greeter/SayHello": { | ||
"post": { | ||
"summary": "Sends a hello greeting", | ||
"operationId": "GreeterService_SayHello", | ||
"responses": { | ||
"200": { | ||
"description": "A successful response.", | ||
"schema": { | ||
"$ref": "#/definitions/v1SayHelloResponse" | ||
} | ||
} | ||
}, | ||
"parameters": [ | ||
{ | ||
"name": "body", | ||
"description": "The request message containing the user's name.", | ||
"in": "body", | ||
"required": true, | ||
"schema": { | ||
"$ref": "#/definitions/v1SayHelloRequest" | ||
} | ||
}, | ||
{ | ||
"name": "token", | ||
"description": "Token Header", | ||
"in": "header", | ||
"required": true, | ||
"type": "string" | ||
} | ||
], | ||
"tags": [ | ||
"Project 001" | ||
] | ||
} | ||
}, | ||
"/v1/helloworld.Greeter/SayHello/{name}": { | ||
"get": { | ||
"summary": "Sends a hello greeting", | ||
"operationId": "GreeterService_SayHello2", | ||
"responses": { | ||
"200": { | ||
"description": "A successful response.", | ||
"schema": { | ||
"$ref": "#/definitions/v1SayHelloResponse" | ||
} | ||
} | ||
}, | ||
"parameters": [ | ||
{ | ||
"name": "name", | ||
"description": "name ...", | ||
"in": "path", | ||
"required": true, | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "token", | ||
"description": "Token Header", | ||
"in": "header", | ||
"required": true, | ||
"type": "string" | ||
} | ||
], | ||
"tags": [ | ||
"Project 001" | ||
] | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"v1SayHelloRequest": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "name ..." | ||
} | ||
}, | ||
"description": "The request message containing the user's name." | ||
}, | ||
"v1SayHelloResponse": { | ||
"type": "object", | ||
"properties": { | ||
"error": { | ||
"type": "integer", | ||
"format": "int64", | ||
"title": "error" | ||
}, | ||
"msg": { | ||
"type": "string", | ||
"title": "msg" | ||
}, | ||
"data": { | ||
"$ref": "#/definitions/v1SayHelloResponseData", | ||
"description": "data ..." | ||
} | ||
}, | ||
"title": "The response message containing the greetings" | ||
}, | ||
"v1SayHelloResponseData": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"title": "name of the user" | ||
}, | ||
"ageNumber": { | ||
"type": "string", | ||
"format": "uint64", | ||
"description": "age_number is the age number." | ||
}, | ||
"sex": { | ||
"$ref": "#/definitions/v1Sex", | ||
"title": "sex is the user's sex" | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "string" | ||
}, | ||
"title": "metadata is the user's metadata" | ||
} | ||
}, | ||
"description": "Data is the data to be sent." | ||
}, | ||
"v1SayHiResponse": { | ||
"type": "object", | ||
"properties": { | ||
"error": { | ||
"type": "integer", | ||
"format": "int64", | ||
"title": "error" | ||
}, | ||
"msg": { | ||
"type": "string", | ||
"title": "msg" | ||
}, | ||
"data": { | ||
"$ref": "#/definitions/v1SayHiResponseData", | ||
"description": "data ..." | ||
} | ||
}, | ||
"title": "The response message containing the greetings" | ||
}, | ||
"v1SayHiResponseData": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"title": "name of the user" | ||
}, | ||
"ageNumber": { | ||
"type": "string", | ||
"format": "uint64", | ||
"description": "age_number is the age number." | ||
} | ||
}, | ||
"description": "Data is the data to be sent." | ||
}, | ||
"v1Sex": { | ||
"type": "integer", | ||
"format": "int32", | ||
"enum": [ | ||
1, | ||
2 | ||
], | ||
"description": "- 1: SEX_MALE ...\n - 2: SEX_FEMALE ...", | ||
"title": "Sex" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.