这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/bookstore/bookstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var memoryDB = sync.Map{}
func main() {
// Create a new router and give our API a title and version.
app := cli.NewRouter("BookStore API", "1.0.0")
app.ServerLink("Development server", "http://localhost:8888")
app.ServerLink("Development server", "http://localhost:8888", map[string]huma.CaServerVariable{})

genres := app.Resource("/v1/genres")
genres.Get("list-genres", "Returns a list of all genres",
Expand Down
2 changes: 1 addition & 1 deletion examples/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var memoryDB = sync.Map{}
func main() {
// Create a new router and give our API a title and version.
app := cli.NewRouter("Notes API", "1.0.0")
app.ServerLink("Development server", "http://localhost:8888")
app.ServerLink("Development server", "http://localhost:8888", map[string]huma.CaServerVariable{})

notes := app.Resource("/v1/notes")
notes.Get("list-notes", "Returns a list of all notes",
Expand Down
12 changes: 10 additions & 2 deletions openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ type oaContact struct {

// oaServer describes an OpenAPI 3 API server location
type oaServer struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
URL string `json:"url"`
Description string `json:"description,omitempty"`
Variables map[string]CaServerVariable `json:"variables,omitempty"`
}

// CaServerVariable describe a server variable for server URL template substitution.
type CaServerVariable struct {
Enum []string `json:"enum,omitempty"`
Default string `json:"default,omitempty"`
Description string `json:"description,omitempty"`
}

// paramLocation describes where in the HTTP request the parameter comes from.
Expand Down
3 changes: 2 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ func (r *Router) Contact(name, email, url string) {
}

// ServerLink adds a new server link to this router for documentation.
func (r *Router) ServerLink(description, uri string) {
func (r *Router) ServerLink(description, uri string, variables map[string]CaServerVariable) {
r.servers = append(r.servers, oaServer{
Description: description,
URL: uri,
Variables: variables,
})
}

Expand Down