| 88 | } |
| 89 | |
| 90 | func (h *RequestHandler) handleOpenAPI(path, basePath string) (string, string, bool) { |
| 91 | group := "" |
| 92 | format := "json" |
| 93 | |
| 94 | openAPIPathJSON := basePath + "/openapi.json" |
| 95 | openAPIPathYAML := basePath + "/openapi.yaml" |
| 96 | openAPIPathYML := basePath + "/openapi.yml" |
| 97 | |
| 98 | switch path { |
| 99 | case basePath, basePath + "/": |
| 100 | group = constant.OpenAPIDefaultGroup |
| 101 | case openAPIPathJSON: |
| 102 | group = constant.OpenAPIDefaultGroup |
| 103 | format = "json" |
| 104 | case openAPIPathYAML: |
| 105 | group = constant.OpenAPIDefaultGroup |
| 106 | format = "yaml" |
| 107 | case openAPIPathYML: |
| 108 | group = constant.OpenAPIDefaultGroup |
| 109 | format = "yaml" |
| 110 | default: |
| 111 | pathPart := strings.TrimPrefix(path, basePath+"/") |
| 112 | // Reject reserved sub-paths and paths containing "/" — these are |
| 113 | // not valid group names and should not fall through to the spec. |
| 114 | if strings.Contains(pathPart, "/") || |
| 115 | pathPart == "swagger-ui" || strings.HasPrefix(pathPart, "swagger-ui/") || |
| 116 | pathPart == "redoc" || strings.HasPrefix(pathPart, "redoc/") || |
| 117 | pathPart == "api-docs" || strings.HasPrefix(pathPart, "api-docs/") { |
| 118 | return "", "", false |
| 119 | } |
| 120 | if strings.HasSuffix(pathPart, ".json") { |
| 121 | group = strings.TrimSuffix(pathPart, ".json") |
| 122 | format = "json" |
| 123 | } else if strings.HasSuffix(pathPart, ".yaml") || strings.HasSuffix(pathPart, ".yml") { |
| 124 | group = strings.TrimSuffix(pathPart, ".yaml") |
| 125 | group = strings.TrimSuffix(group, ".yml") |
| 126 | format = "yaml" |
| 127 | } else { |
| 128 | group = pathPart |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if group == "" { |
| 133 | group = constant.OpenAPIDefaultGroup |
| 134 | } |
| 135 | |
| 136 | return h.getOpenAPIContent(group, format) |
| 137 | } |
| 138 | |
| 139 | func (h *RequestHandler) getOpenAPIContent(group, format string) (string, string, bool) { |
| 140 | openAPI := h.service.GetOpenAPI(&OpenAPIRequest{ |