mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-11 11:57:04 +00:00
* Store capability OpenAPI V3 JSON schema in ConfigMap Store the OpenAPI v3 JSON Schema generated from the parameters of a capability which could be used by api server To fix #899 address comments try to fix data race issue Co-authored-by: Jianbo Sun <wonderflow.sun@gmail.com> * address comments: generate cue instance from cue json instead of local file * update ConfigMap data at any time * add more unit-test * fix conflicts * adapt to new spec.schematic.cue.template * adapt to new spec.schematic.cue.template for controller unittest cases * fix ci issues * adapt to namespaced scope definition * add more testcases on namespaced definitions with and without namespaces Co-authored-by: Jianbo Sun <wonderflow.sun@gmail.com>
30 lines
1.0 KiB
Go
30 lines
1.0 KiB
Go
package apiserver
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/oam-dev/kubevela/apis/types"
|
|
"github.com/oam-dev/kubevela/references/apiserver/util"
|
|
"github.com/oam-dev/kubevela/references/common"
|
|
)
|
|
|
|
// GetDefinition gets OpenAPI schema from Cue section of a WorkloadDefinition/TraitDefinition
|
|
// @tags definitions
|
|
// @ID GetDefinition
|
|
// @Summary gets OpenAPI schema from Cue section of a WorkloadDefinition/TraitDefinition
|
|
// @Param definitionName path string true "name of workload type or trait"
|
|
// @Success 200 {object} apis.Response{code=int,data=string}
|
|
// @Failure 500 {object} apis.Response{code=int,data=string}
|
|
// @Router /definitions/{definitionName} [get]
|
|
func (s *APIServer) GetDefinition(c *gin.Context) {
|
|
definitionName := c.Param("name")
|
|
cm, err := common.GetCapabilityConfigMap(s.KubeClient, definitionName)
|
|
if err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, errors.New("OpenAPI v3 JSON Schema is not ready"))
|
|
return
|
|
}
|
|
util.AssembleResponse(c, cm.Data[types.OpenapiV3JSONSchema], nil)
|
|
}
|