mirror of https://github.com/harness/drone.git
server urls added, resource moved to the root path (#35)
parent
7317ec9d62
commit
41cbb6622f
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package repo
|
||||
package resource
|
||||
|
||||
import (
|
||||
"net/http"
|
|
@ -33,6 +33,9 @@ func Generate() *openapi3.Spec {
|
|||
reflector.Spec.Info.
|
||||
WithTitle("API Specification").
|
||||
WithVersion(version.Version.String())
|
||||
reflector.Spec.Servers = []openapi3.Server{{
|
||||
URL: "/api/v1/",
|
||||
}}
|
||||
|
||||
//
|
||||
// register endpoints
|
||||
|
@ -43,6 +46,7 @@ func Generate() *openapi3.Spec {
|
|||
buildUsers(&reflector)
|
||||
spaceOperations(&reflector)
|
||||
repoOperations(&reflector)
|
||||
resourceOperations(&reflector)
|
||||
|
||||
//
|
||||
// define security scheme
|
||||
|
|
|
@ -60,29 +60,6 @@ func repoOperations(reflector *openapi3.Reflector) {
|
|||
_ = reflector.SetJSONResponse(&createRepository, new(usererror.Error), http.StatusForbidden)
|
||||
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos", createRepository)
|
||||
|
||||
opListGitignore := openapi3.Operation{}
|
||||
opListGitignore.WithTags("repository")
|
||||
opListGitignore.WithMapOfAnything(map[string]interface{}{"operationId": "listGitignore"})
|
||||
_ = reflector.SetRequest(&opListGitignore, new(gitignoreRequest), http.MethodGet)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, []string{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusForbidden)
|
||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/resources/gitignore", opListGitignore)
|
||||
|
||||
opListLicenses := openapi3.Operation{}
|
||||
opListLicenses.WithTags("repository")
|
||||
opListLicenses.WithMapOfAnything(map[string]interface{}{"operationId": "listLicenses"})
|
||||
_ = reflector.SetRequest(&opListLicenses, new(licenseRequest), http.MethodGet)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, []struct {
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
}{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusForbidden)
|
||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/resources/license", opListLicenses)
|
||||
|
||||
opFind := openapi3.Operation{}
|
||||
opFind.WithTags("repository")
|
||||
opFind.WithMapOfAnything(map[string]interface{}{"operationId": "findRepository"})
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/internal/api/usererror"
|
||||
"github.com/swaggest/openapi-go/openapi3"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//nolint:funlen
|
||||
func resourceOperations(reflector *openapi3.Reflector) {
|
||||
opListGitignore := openapi3.Operation{}
|
||||
opListGitignore.WithTags("resource")
|
||||
opListGitignore.WithMapOfAnything(map[string]interface{}{"operationId": "listGitignore"})
|
||||
_ = reflector.SetRequest(&opListGitignore, new(gitignoreRequest), http.MethodGet)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, []string{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusForbidden)
|
||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/resources/gitignore", opListGitignore)
|
||||
|
||||
opListLicenses := openapi3.Operation{}
|
||||
opListLicenses.WithTags("resource")
|
||||
opListLicenses.WithMapOfAnything(map[string]interface{}{"operationId": "listLicenses"})
|
||||
_ = reflector.SetRequest(&opListLicenses, new(licenseRequest), http.MethodGet)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, []struct {
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
}{}, http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusForbidden)
|
||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/resources/license", opListLicenses)
|
||||
}
|
|
@ -7,6 +7,7 @@ package router
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/harness/gitness/internal/api/handler/resource"
|
||||
"net/http"
|
||||
|
||||
"github.com/harness/gitness/internal/api/controller/repo"
|
||||
|
@ -105,6 +106,7 @@ func setupRoutesV1(r chi.Router, config *types.Config, repoCtrl *repo.Controller
|
|||
setupAdmin(r, userCtrl)
|
||||
setupAccount(r, userCtrl)
|
||||
setupSystem(r)
|
||||
setupResources(r)
|
||||
}
|
||||
|
||||
func setupSpaces(r chi.Router, spaceCtrl *space.Controller) {
|
||||
|
@ -141,10 +143,6 @@ func setupRepos(r chi.Router, config *types.Config, repoCtrl *repo.Controller) {
|
|||
r.Route("/repos", func(r chi.Router) {
|
||||
// Create takes path and parentId via body, not uri
|
||||
r.Post("/", handlerrepo.HandleCreate(config, repoCtrl))
|
||||
r.Route("/resources", func(r chi.Router) {
|
||||
r.Get("/gitignore", handlerrepo.HandleGitIgnore())
|
||||
r.Get("/license", handlerrepo.HandleLicence())
|
||||
})
|
||||
r.Route(fmt.Sprintf("/{%s}", request.PathParamRepoRef), func(r chi.Router) {
|
||||
// repo level operations
|
||||
r.Get("/", handlerrepo.HandleFind(repoCtrl))
|
||||
|
@ -231,6 +229,13 @@ func setupSystem(r chi.Router) {
|
|||
})
|
||||
}
|
||||
|
||||
func setupResources(r chi.Router) {
|
||||
r.Route("/resources", func(r chi.Router) {
|
||||
r.Get("/gitignore", resource.HandleGitIgnore())
|
||||
r.Get("/license", resource.HandleLicence())
|
||||
})
|
||||
}
|
||||
|
||||
func setupAdmin(r chi.Router, _ *user.Controller) {
|
||||
r.Route("/users", func(r chi.Router) {
|
||||
r.Post("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
Loading…
Reference in New Issue