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

Support complex objects as decorator argument values #918

Open
dselman opened this issue Oct 10, 2024 · 5 comments · May be fixed by #984
Open

Support complex objects as decorator argument values #918

dselman opened this issue Oct 10, 2024 · 5 comments · May be fixed by #984
Assignees

Comments

@dselman
Copy link
Contributor

dselman commented Oct 10, 2024

Feature Request 🛍️

Currently decorator arguments are limited to:

  • String
  • Number
  • Boolean
  • Type reference

It would be useful to support a stringified arbitrary object as a decorator argument value.

Use Case

Automated systems creating models and storing complex decorator arguments on the model.

Possible Solution

namespace [email protected]

concept TextFormat extends Decorator {
   o String font
   o Integer fontSize
   o Boolean isBold optional
   o Boolean isItalic optonal
}

@TextFormat({"font": "arial", "fontSize" : 12, "isBold" : true})
concept TextField {
    o String value
}

Context

When decorator arguments become complex they are hard to read, because they are based on positional arguments.

Detailed Description

We would have to extend the CTO grammar to support JSON objects within decorator arguments, marshalling them into a new type of DecoratorLiteral, or extending the DecoratorStringLiteral to carry the JSON value as a string.

Extend the logic that validates decorator arguments to check the structure of the JSON conforms to the related decorator definition.

Copy link
Contributor

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@Mamatha1718
Copy link

Hi @dselman @DianaLease , I would like to tackle this issue will you please assign it to me, I understand that supporting JSON objects in decorators can be helpful for handling dynamic and complex codebases by enabling key-value pairs. To solve this following changes are needed:

Grammar Update: Extend the CTO grammar to allow JSON objects in decorators, possibly by creating a new DecoratorLiteral type or extending the DecoratorStringLiteral.
Validation Logic: Modify the decorator argument validation to check the structure of the JSON and ensure it matches the related decorator definition.
Could you guide me on which files in the codebase handle:

The CTO grammar definition.
The validation logic for decorators related files.
Thank You.

@DianaLease
Copy link
Member

@Mamatha1718 Thanks for offering to work on this, I will assign the ticket to you!

I believe you'll need to add the new decorator type here: https://github.com/accordproject/concerto/blob/main/packages/concerto-cto/lib/parser.pegjs#L884-L925
and the validation logic here:

@dselman is away at the moment, but he can correct me if I'm wrong when he gets back as he is more familiar with this code!

@Mamatha1718
Copy link

Hi @DianaLease ,Thank you for assigning me this issue and providing the relevant files and code for better understanding. I appreciate the guidance!
Thank You.

@Mamatha1718
Copy link

Mamatha1718 commented Jan 31, 2025

Hi @dselman , @DianaLease , The PR is ready for review, #984 will you Please let me know if any other changes are need.
Thank You.

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

Successfully merging a pull request may close this issue.

3 participants