Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update write function #174

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions models/v1alpha3/relationship/relationship_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand that you're not considering the file extension here and that this is identified elsewhere, I do wonder if that logic allow for both .yaml and .yml or if it even depends on the file extension at all.

err := utils.WriteYamlToFile[RelationshipDefinition](relPath, r)
return err
}
err := utils.WriteJSONToFile[RelationshipDefinition](relPath, r)
return err
}
Expand Down
28 changes: 26 additions & 2 deletions models/v1beta1/component/component_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
36 changes: 36 additions & 0 deletions models/v1beta1/import.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion models/v1beta1/model/model_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]))
}
Expand Down Expand Up @@ -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
}
156 changes: 156 additions & 0 deletions schemas/constructs/openapi/mesheryHandlers.yml
Original file line number Diff line number Diff line change
@@ -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

Loading