Skip to content

Commit a5dca60

Browse files
committed
Refactor code structure for improved readability and maintainability
Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
1 parent b58d038 commit a5dca60

File tree

7 files changed

+5548
-363
lines changed

7 files changed

+5548
-363
lines changed

build/openapi.config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import-mapping:
3737
"../v1alpha1/catalog_data.json": "github.com/meshery/schemas/models/v1alpha1/catalog_data"
3838

3939
# v1alpha3
40-
"../v1alpha3/relationship.json": "github.com/meshery/schemas/models/v1alpha3/relationship"
41-
"../v1alpha3/selector.json": "github.com/meshery/schemas/models/v1alpha3/selector"
40+
"../v1alpha3/relationship/relationship.json": "github.com/meshery/schemas/models/v1alpha3/relationship"
41+
"../v1alpha3/selector/selector.json": "github.com/meshery/schemas/models/v1alpha3/selector"
4242

4343
# v1beta1
4444
"../v1beta1/model.json": "github.com/meshery/schemas/models/v1beta1/model"

models/v1alpha3/relationship/relationship.go

Lines changed: 2535 additions & 355 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/v1alpha3/relationship/relationship_helper.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,28 @@ func (r *RelationshipDefinition) GenerateID() (uuid.UUID, error) {
2525
}
2626

2727
func (r RelationshipDefinition) GetID() uuid.UUID {
28-
return r.Id
28+
if r.Id == nil {
29+
return uuid.Nil
30+
}
31+
return *r.Id
2932
}
3033

3134
func (r *RelationshipDefinition) GetEntityDetail() string {
3235
return fmt.Sprintf("type: %s, definition version: %s, kind: %s, model: %s, version: %s", r.Type(), r.Version, r.Kind, r.Model.DisplayName, r.Model.Version)
3336
}
3437

3538
func (r *RelationshipDefinition) Create(db *database.Handler, hostID uuid.UUID) (uuid.UUID, error) {
36-
r.Id, _ = r.GenerateID()
39+
id, err := r.GenerateID()
40+
if err != nil {
41+
return uuid.UUID{}, err
42+
}
43+
r.Id = &id
3744

38-
err := db.Omit(clause.Associations).Create(&r).Error
45+
err = db.Omit(clause.Associations).Create(&r).Error
3946
if err != nil {
4047
return uuid.UUID{}, err
4148
}
42-
return r.Id, err
49+
return id, err
4350
}
4451

4552
func (r *RelationshipDefinition) UpdateStatus(db *database.Handler, status entity.EntityStatus) error {
@@ -58,4 +65,4 @@ func (r RelationshipDefinition) WriteRelationshipDefinition(relDirPath string, f
5865

5966
func (r *RelationshipDefinition) GetDefaultEvaluationQuery() string {
6067
return fmt.Sprintf("%s_%s_relationship", strings.ToLower(string(r.Kind)), strings.ToLower(r.SubType))
61-
}
68+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
openapi: 3.0.0
2+
info:
3+
title: relationship
4+
version: 1.0.0
5+
paths: {}
6+
components:
7+
schemas:
8+
RelationshipDefinition:
9+
$ref: "./relationship.yaml"

typescript/generated/v1alpha3/relationship/Relationship.ts

Lines changed: 728 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)