Skip to content

Generator redesign read meta for resource name to class struct (DCNE-345) #1350

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

Open
wants to merge 9 commits into
base: generator_redesign
Choose a base branch
from

Conversation

akinross
Copy link
Collaborator

fixes DCNE-345

@akinross akinross changed the title Generator redesign read meta to class struct (DCNE-345) Generator redesign read meta for resource name to class struct (DCNE-345) May 12, 2025
@akinross akinross force-pushed the generator_redesign_read_meta_to_class_struct branch from aba6ba9 to 9012df2 Compare May 12, 2025 10:44
Copy link
Collaborator

@anvitha-jain anvitha-jain left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@sajagana sajagana left a comment

Choose a reason for hiding this comment

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

LGTM!

func (c *Class) setResourceName() error {
genLogger.Debug(fmt.Sprintf("Setting resource name for class '%s'.", c.ClassName))

// TODO: add logic to override the resource name from an definition file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not important but..
->
// TODO: add logic to override the resource name from a definition file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

assuming the change was an to a, changed this now

@akinross akinross requested a review from shrsr May 14, 2025 16:41
Copy link
Collaborator

@shrsr shrsr left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@gmicol gmicol left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@sajagana sajagana left a comment

Choose a reason for hiding this comment

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

LGTM!

@akinross akinross requested a review from lhercot May 21, 2025 20:03
Comment on lines 235 to 239
if label, ok := c.MetaFileContent["label"]; ok && label != "" {
c.ResourceName = utils.Underscore(label.(string))
} else {
return fmt.Errorf("failed to set resource name for class '%s': label not found", c.ClassName)
}
Copy link
Member

Choose a reason for hiding this comment

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

This also does not account for relational classes right where we need to add relation_ right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok will include logic for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

included logic for this, added some todo notes for overwrites that we would likely require

Comment on lines 262 to 267
// For relational class nested attributes the name is changed to 'to_resource_name' when the resource name includes 'from_resource_name'.
// ex. 'relation_from_bridge_domain_to_netflow_monitor_policy' would translate to 'relation_to_netflow_monitor_policy'.
m := regexp.MustCompile("from_(.*)_to_")
if m.MatchString(c.ResourceNameNested) {
c.ResourceNameNested = m.ReplaceAllString(c.ResourceNameNested, "to_")
}
Copy link
Member

Choose a reason for hiding this comment

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

No sure why this is needed as we could just do it before as a classic set or make this part of the resource name function itself. Not sure we want this as a separate function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes did not account for constructing the relation_ from_ and to_ parts, will change the logic with the comment above.

Comment on lines +70 to +75
for _, test := range tests {
genLogger.Info(fmt.Sprintf("Executing: %s' with input '%s' and expected output '%s'", t.Name(), test["input"], test["expected"]))
result, err := Plural(test["input"])
assert.NoError(t, err, fmt.Sprintf("Expected no error, but got '%s'", err))
assert.Equal(t, test["expected"], result, fmt.Sprintf("Expected '%s', but got '%s'", test["expected"], result))
}
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be repeated in some fashion quite a bit. Should this be a function that accept a series of attribute including the tested function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will have a look at creating functions for all the repeating tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

had a look and think it will if we want to standardise this we should have a follow up discussion, for now created isolated test cases

@akinross akinross force-pushed the generator_redesign_read_meta_to_class_struct branch from 66d4405 to 71c61e0 Compare June 3, 2025 12:57
@akinross akinross force-pushed the generator_redesign_read_meta_to_class_struct branch from 71c61e0 to 6541502 Compare June 3, 2025 13:01
@akinross akinross requested a review from lhercot June 3, 2025 13:02
Copy link
Collaborator

@samiib samiib left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants