diff --git a/models/v1alpha3/relationship/relationship_helper.go b/models/v1alpha3/relationship/relationship_helper.go index a6b9e65156..e6f8ecac92 100644 --- a/models/v1alpha3/relationship/relationship_helper.go +++ b/models/v1alpha3/relationship/relationship_helper.go @@ -50,8 +50,12 @@ func (r *RelationshipDefinition) UpdateStatus(db *database.Handler, status entit return nil } -func (r RelationshipDefinition) WriteComponentDefinition(relDirPath string) error { - relPath := filepath.Join(relDirPath, string(r.Kind), string(r.Type())+".json") +func (r RelationshipDefinition) WriteRelationshipDefinition(relDirPath string, fileType string) error { + relPath := filepath.Join(relDirPath, fmt.Sprintf("%s-%s.%s", r.Kind, utils.GetRandomAlphabetsOfDigit(3), fileType)) + if fileType == "yaml" { + err := utils.WriteYamlToFile[RelationshipDefinition](relPath, r) + return err + } err := utils.WriteJSONToFile[RelationshipDefinition](relPath, r) return err } diff --git a/models/v1beta1/component/component_helper.go b/models/v1beta1/component/component_helper.go index 408f120aa5..e4aace4b8a 100644 --- a/models/v1beta1/component/component_helper.go +++ b/models/v1beta1/component/component_helper.go @@ -65,14 +65,38 @@ func (m *ComponentDefinition) UpdateStatus(db *database.Handler, status entity.E return nil } -func (c ComponentDefinition) WriteComponentDefinition(componentDirPath string) (bool, error) { +func (c ComponentDefinition) WriteComponentDefinition(componentDirPath string, fileType string) (bool, error) { if c.Component.Kind == "" { return false, nil } - componentPath := filepath.Join(componentDirPath, c.Component.Kind+".json") + componentPath := filepath.Join(componentDirPath, c.Component.Kind+"."+fileType) if _, err := os.Stat(componentPath); err != nil { + if fileType == "yaml" { + err := utils.WriteYamlToFile[ComponentDefinition](componentPath, c) + return false, err + } err := utils.WriteJSONToFile[ComponentDefinition](componentPath, c) return false, err } return true, nil } +func (c *ComponentDefinition) ReplaceSVGData(baseDir string) error { + + compStyle := c.Styles + if compStyle != nil { + svgColor, err := utils.ReadSVGData(baseDir, compStyle.SvgColor) + if err == nil { + compStyle.SvgColor = svgColor + } else { + return err + } + svgWhite, err := utils.ReadSVGData(baseDir, compStyle.SvgWhite) + if err == nil { + compStyle.SvgWhite = svgWhite + } else { + return err + } + } + c.Styles = compStyle + return nil +} diff --git a/models/v1beta1/import.go b/models/v1beta1/import.go new file mode 100644 index 0000000000..d10daa3f3b --- /dev/null +++ b/models/v1beta1/import.go @@ -0,0 +1,36 @@ +// Package v1beta1 provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT. +package v1beta1 + +// ImportBody defines model for ImportBody. +type ImportBody struct { + FileName string `json:"file_name" yaml:"file_name"` + Model Model `json:"model" yaml:"model"` + + // ModelFile represents the binary content of the file as a byte array + ModelFile []byte `json:"model_file" yaml:"model_file"` + Url string `json:"url" yaml:"url"` +} + +type ImportRequest struct { + ImportBody ImportBody `json:"importBody" yaml:"importBody"` + Register bool `json:"register" yaml:"register"` + UploadType string `json:"uploadType" yaml:"uploadType"` +} + +type Model struct { + Category string `json:"category" yaml:"category"` + IsAnnotation bool `json:"isAnnotation" yaml:"isAnnotation"` + Model string `json:"model" yaml:"model"` + ModelDisplayName string `json:"modelDisplayName" yaml:"modelDisplayName"` + PrimaryColor string `json:"primaryColor" yaml:"primaryColor"` + PublishToRegistry bool `json:"publishToRegistry" yaml:"publishToRegistry"` + Registrant string `json:"registrant" yaml:"registrant"` + SecondaryColor string `json:"secondaryColor" yaml:"secondaryColor"` + Shape string `json:"shape" yaml:"shape"` + SubCategory string `json:"subCategory" yaml:"subCategory"` + SvgColor string `json:"svgColor" yaml:"svgColor"` + SvgComplete string `json:"svgComplete" yaml:"svgComplete"` + SvgWhite string `json:"svgWhite" yaml:"svgWhite"` +} diff --git a/models/v1beta1/model/model_helper.go b/models/v1beta1/model/model_helper.go index abbb19d2da..1e1fc703e8 100644 --- a/models/v1beta1/model/model_helper.go +++ b/models/v1beta1/model/model_helper.go @@ -42,7 +42,7 @@ func (m *ModelDefinition) GenerateID() (uuid.UUID, error) { if err != nil { return uuid.UUID{}, err } - + hash := md5.Sum(byt) return uuid.FromString(hex.EncodeToString(hash[:])) } @@ -138,3 +138,25 @@ func registerModel(db *database.Handler, regID, modelID uuid.UUID) error { } return nil } +func (m *ModelDefinition) ReplaceSVGData(baseDir string) error { + + metadata := m.Metadata + if metadata.SvgColor != "" { + svgData, err := utils.ReadSVGData(baseDir, metadata.SvgColor) + if err == nil { + metadata.SvgColor = svgData + } else { + return err + } + } + if metadata.SvgWhite != "" { + svgData, err := utils.ReadSVGData(baseDir, metadata.SvgWhite) + if err == nil { + metadata.SvgWhite = svgData + } else { + return err + } + } + m.Metadata = metadata + return nil +} diff --git a/schemas/constructs/openapi/mesheryHandlers.yml b/schemas/constructs/openapi/mesheryHandlers.yml new file mode 100644 index 0000000000..afb930068a --- /dev/null +++ b/schemas/constructs/openapi/mesheryHandlers.yml @@ -0,0 +1,156 @@ +openapi: 3.0.0 +info: + title: Meshmodels API + description: API for registering and exporting mesh models + version: 1.0.0 +components: + schemas: + ImportRequest: + type: object + required: + - importBody + - uploadType + - register + properties: + importBody: + $ref: '#/components/schemas/ImportBody' + uploadType: + type: string + register: + type: boolean + nullable: false + + ImportBody: + type: object + required: + - model_file + - url + - file_name + - model + properties: + model_file: + type: string + format: byte + description: "This represents the binary content of the file as a byte array" + url: + type: string + file_name: + type: string + model: + $ref: '#/components/schemas/Model' + + Model: + type: object + required: + - modelDisplayName + - registrant + - model + - category + - subCategory + - shape + - primaryColor + - secondaryColor + - svgColor + - svgWhite + - svgComplete + - isAnnotation + - publishToRegistry + properties: + modelDisplayName: + type: string + registrant: + type: string + model: + type: string + category: + type: string + subCategory: + type: string + shape: + type: string + primaryColor: + type: string + pattern: "^#[0-9A-Fa-f]{6}$" + secondaryColor: + type: string + pattern: "^#[0-9A-Fa-f]{6}$" + svgColor: + type: string + svgWhite: + type: string + svgComplete: + type: string + isAnnotation: + type: boolean + publishToRegistry: + type: boolean + +paths: + /api/meshmodels/register: + post: + summary: Register mesh models + operationId: RegisterMeshmodels + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ImportRequest' + responses: + '200': + description: Successful registration + content: + application/json: + schema: + type: object + properties: + message: + type: string + '400': + description: Invalid request format + '500': + description: Internal server error + + /api/meshmodels/export: + get: + summary: Export a mesh model + operationId: ExportModel + parameters: + - in: query + name: id + schema: + type: string + required: true + - in: query + name: name + schema: + type: string + - in: query + name: version + schema: + type: string + - in: query + name: output_format + schema: + type: string + enum: [json, yaml, oci] + default: oci + - in: query + name: file_type + schema: + type: string + enum: [oci, tar, gzip] + default: oci + responses: + '200': + description: Successful export + content: + application/octet-stream: + schema: + type: string + format: binary + '400': + description: Invalid request format + '500': + description: Internal server error +