This issue describes a concrete proposal on how to realise attributes reuse through yaml syntax and tooling.
Related issues / PRs:
Proposal
I'm proposing to introduce a new, additional type of attribute reference called embed (alternatively: nest) in the syntax that would behave similarly to ref property BUT with the following difference: When embed is used the referenced attribute will be nested under the namespace of the attribute group in which the attribute is being referenced.
Example
See the following example that illustrates the idea and the difference to ref:
We would define geo attributes in a geo.yaml file:
groups:
- id: geo
prefix: geo
type: attribute_group
brief: Describes the geo location
attributes:
- id: location.lon
type: double
brief: Longitude of the geo location in [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).
examples: [ -73.614830 ]
- id: location.lat
type: double
brief: Latitude of the geo location in [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).
examples: [ 45.505918 ]
In client and server files we would embed the attributes.
! Note: Here I consciously embed the geo.location.lon attribute BUT ref the geo.location.lat attribute to demonstrate the difference:
groups:
- id: client
prefix: client
type: attribute_group
brief: ...
attributes:
- id: address
...
- embed: geo.location.lon <<-- THAT IS NEW
- ref: geo.location.lat
When rendering (or code generating) the above it will result in the following attributes:
client.geo.location.lon
geo.location.lat
Note the difference that geo.location.lon is now nested under the client namespace because it was embedded (embed) while geo.location.lat keeps it's original full name because it was referenced (ref).
Extended proposal
We could even think about an embed_namespaces property on the attribute_group level to simplify embeddings of entire namespaces into other namespace. For example for geo we could do something like the following to embed ALL of the geo.* fields into the client:
groups:
- id: client
prefix: client
type: attribute_group
brief: ...
embed_namespaces:
- id: geo <<-- EMBED the entire geo namespace under client
attributes:
- id: address
...
This issue describes a concrete proposal on how to realise attributes reuse through yaml syntax and tooling.
Related issues / PRs:
Proposal
I'm proposing to introduce a new, additional type of attribute reference called
embed(alternatively:nest) in the syntax that would behave similarly torefproperty BUT with the following difference: Whenembedis used the referenced attribute will be nested under thenamespaceof the attribute group in which the attribute is being referenced.Example
See the following example that illustrates the idea and the difference to
ref:We would define geo attributes in a
geo.yamlfile:In client and server files we would
embedthe attributes.! Note: Here I consciously
embedthegeo.location.lonattribute BUTrefthegeo.location.latattribute to demonstrate the difference:When rendering (or code generating) the above it will result in the following attributes:
client.geo.location.longeo.location.latNote the difference that
geo.location.lonis now nested under theclientnamespace because it was embedded (embed) whilegeo.location.latkeeps it's original full name because it was referenced (ref).Extended proposal
We could even think about an
embed_namespacesproperty on theattribute_grouplevel to simplify embeddings of entire namespaces into other namespace. For example forgeowe could do something like the following to embed ALL of thegeo.*fields into the client: