raml-org / raml-spec

RAML Specification
http://raml.org
3.87k stars 858 forks source link

Ability to define wellknown objects in RAML #772

Open hitengajjar opened 2 years ago

hitengajjar commented 2 years ago

We have a use case where users should be able to define well-known objects (instances) that are validated against their type in RAML. We need these instances defined as a RAML fragment.

We have found 2 ways to define instances with the current RAML specification. My intention with this bug ticket is to have a discussion on this topic, help us choose better approaches, or maybe if you see a need to enhance language with specific keywords to define instances.

Approach 1 using annotationTypes e.g.

annotationTypes:
  wellknown-objects: MyType[]
types:
  MyType:
    properties:
      id: string
      name: string
    (wellknown-objects):
      - id: "123"
        name: "wow"
      - id: "345"
        name: "newone"

The problem is: that instances defined this way are in place with types and this is a restriction for us.


Approach 2 using facets e.g.

types:
  _MyType:  # Have to create this as unfortunately, we cannot refer self in facets
    additionalProperties: false
    properties:
      id: string
      name: string
  MyType: 
    type: _MyType
    additionalProperties: false
    #
    facets:
      wellknown-object-value?: _MyType

  MyInstance:
    type: MyType
    wellknown-object-value:
       id: "345"
       name: "afds"

This method allows us to define instances in RAML fragments but it has below issues.

  1. Semantic meaning of types is changed to define instances. Instances still are defined as RAML Types.
  2. Instances can be inherited as they are still types. This doesn't make sense for instances.
git2gus[bot] commented 2 years ago

Git2Gus App is installed but the .git2gus/config.json doesn't exist.