Skip to content

Add "combine" or "merge" operator for models #1292

Open
@johanste

Description

@johanste

Something that I have missed is the ability to combine models outside of spread operators. One example of a (unrelated) language is jsonnet's object combine operator (see inheritance and nested field inheritance the sections).

To illustrate a bit what I'm thinking:

model Base {
  id: string;
  etag?: string;
  apiVersion: string;
}

model Overrides {
  id: int32;
  description?: string;
  apiVersion: never;
}

model Combined is Base + Overrides;

/*
// Resulting model:

model Combined {
  id: int32;
  etag?: string;
  apiVersion: never;
  description?: string;
}
*/

As indicated, the resulting model is not a subtype of either operands, the order of attributes could be preserved (although there is an argument to be made that overriding attributes should move later), decorators (not shown) are not merged etc.

I can think of a couple of places in azure core where this would be useful and simplify our life.

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    design:neededA design request has been raised that needs a proposalfeatureNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions