Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
38 lines
1012 B
Go
38 lines
1012 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package web
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"gitea.dev/modules/setting"
|
|
"gitea.dev/modules/templates"
|
|
"gitea.dev/modules/util"
|
|
"gitea.dev/services/context"
|
|
)
|
|
|
|
func swaggerJsonServe(ctx *context.Context, file string) {
|
|
buf, err := templates.AssetFS().ReadFile(file)
|
|
if err != nil {
|
|
ctx.HTTPError(http.StatusInternalServerError, "unable to read api json file: "+file)
|
|
return
|
|
}
|
|
r := strings.NewReplacer(
|
|
"0.0.0+GITEA-API-APP-VERSION", template.JSEscapeString(setting.AppVer),
|
|
"/GITEA-API-APP-SUBURL/", template.JSEscapeString(setting.AppSubURL)+"/",
|
|
)
|
|
ctx.Resp.Header().Set("Content-Type", "application/json")
|
|
_, _ = r.WriteString(ctx.Resp, util.UnsafeBytesToString(buf))
|
|
}
|
|
|
|
func SwaggerV1Json(ctx *context.Context) {
|
|
swaggerJsonServe(ctx, "swagger/v1-swagger.generated.json")
|
|
}
|
|
|
|
func OpenAPI3Json(ctx *context.Context) {
|
|
swaggerJsonServe(ctx, "swagger/v1-openapi3.generated.json")
|
|
}
|