Skip to content

Commit

Permalink
Add support for specifying the relative path to the OAS documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed Apr 29, 2021
1 parent 2c95857 commit 1218504
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gen/http/chi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewHTTPRouterWithOAS(svc {{.Result.SrcPkgPrefix}}{{.Result.Interface.Name}}
{{- end}}
if schema != nil {
r.Method("GET", "/api", oasv2.Handler(OASv2APIDoc, schema))
r.Method("GET", "{{.Spec.Metadata.DocsPath}}", oasv2.Handler(OASv2APIDoc, schema))
}
var codec httpcodec.Codec
Expand Down
5 changes: 5 additions & 0 deletions gen/util/openapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ type Specification struct {
}

type Metadata struct {
// Relative path to the OAS documentation.
DocsPath string

Title string
Version string
Description string
BasePath string

// Default tags for operations those have no tags.
DefaultTags []string
}

Expand Down
5 changes: 4 additions & 1 deletion gen/util/openapi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func buildSuccessResponse(text string, results map[string]*reflector.Param, opNa

func buildMetadata(comments []string) (m *Metadata, err error) {
m = &Metadata{
DocsPath: "/api",
Title: "No Title",
Version: "0.0.0",
Description: getDescriptionFromDoc(comments),
Expand All @@ -72,8 +73,10 @@ func buildMetadata(comments []string) (m *Metadata, err error) {
return nil, fmt.Errorf(`%q does not match the expected format: "<key>:<value>"`, value)
}

k, v := parts[0], parts[1]
k, v := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
switch k {
case "docsPath":
m.DocsPath = v
case "title":
m.Title = v
case "version":
Expand Down

0 comments on commit 1218504

Please sign in to comment.