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

Extends support for enum declarations #849

Open
dselman opened this issue May 1, 2024 · 3 comments
Open

Extends support for enum declarations #849

dselman opened this issue May 1, 2024 · 3 comments

Comments

@dselman
Copy link
Contributor

dselman commented May 1, 2024

Feature Request 🛍️

Add the ability to extend an existing enum declaration.

Use Case

namespace [email protected]

enum VehicleStatus {
   o STARTED
   o STOPPED
}

concept Vehicle {
   o VehicleStatus status
}

And then...

namespace [email protected]
import {VehicleStatus} from [email protected]

enum AcmeVehicleStatus extends VehicleStatus {
   o IDLING
}

A valid instance (IFF the [email protected] namespace is imported into the model manager):

{
   "$class" : "[email protected]",
   "status" : "IDLING"
}

Possible Solution

Allow enum declarations to be extended with new enum values.
Make properties of concepts that are enums "polymorphic" in the JSON validator: searching all enum declarations that extend the field type, and taking the union of all their values.

Context

User wants to extend the values of an enum without incrementing the model version of the concept that is using the enum declaration.

Detailed Description

Note that this does complicate namespace resolution, as the transitive closure of all models required by a namespace is now no longer explicit, even in strict mode. Before validating incoming JSON the model manager must be explicitly populated with all the namespaces that extend an enum declaration.

@mttrbrts
Copy link
Member

mttrbrts commented May 1, 2024

Are you proposing a Liskov substitution semantic, or is this just syntactic sugar for creating a new enum type that shares values with another type?

@dselman
Copy link
Contributor Author

dselman commented May 1, 2024

Closer to the former. The line

o VehicleStatus status

Is saying, "expect an enum value here, coming from the VehicleStatus enum declaration, or any enum declaration that extends VehicleStatus. We would have to add logic to enum declarations to check that they were not redeclaring enum values from a super type...

The implementation could be something like rebuilding EnumDeclaration on top of ConceptDeclaration so we share a lot of the logic for handling super types, decorators etc.

@mttrbrts
Copy link
Member

mttrbrts commented May 1, 2024

I'm having some déja vu!
#291

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

No branches or pull requests

2 participants