cancel
Showing results for 
Search instead for 
Did you mean: 

Restricting Floating MetaObject in domainObject definition using OPen APi 3.0

Highlighted
New Contributor

Restricting Floating MetaObject in domainObject definition using OPen APi 3.0

Hi all,
I am trying to create domain object with meta which can have different required params based on the actions for example

{
 "action": "tap",
"title":"choose option"
"postback": "swagger"
}

{
 "action": "openPhonebook",
"title":"choose contact"
"meta":{
"sessionId":"ytyut"
}

{
 "action": "openKeyPad":
"meta":{
   "sessionId":"678768",
    "partialMessage":"type your input.."
  }
}

Inorder to make sure the params in meta is required as per action defined above i followed the this docshttps://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/ and created domain as follows. is there any alternate way?

meta:
      type: object
      properties:
        partialMessage:
          type: string
          example: Change operator to 
        sessionId:
          type: string
          example: 6567678872937
actionType:
      type: string
      enum: ['tap', 'openPhonebook', 'openKeypad']
      example: openPhonebook
# base action object
actionObject:
      type: object
      required:
      - action
      properties:
        action:
          $ref: '#/components/schemas/actionType'
        title:
          type: string
        postback:
          type: string
        meta:
          $ref: '#/components/schemas/meta'
      additionalProperties: false
 # action specific 
tap:
      allOf:
        - $ref: '#/components/schemas/actionObject'
        - type: object
          required:
          - postback
          - title
          properties:
            action:
              type: string
              enum: ['tap']
    openPhonebook:
      allOf:
        - $ref: '#/components/schemas/actionObject'
        - type: object
          required:
          - title
          properties:
            action:
              type: string
              enum: ['openPhonebook']
             meta:
              allOf:
              - $ref: '#/components/schemas/meta'
              - type: object
                required:
                - sessionId
    openKeypad:
      allOf:
        - $ref: '#/components/schemas/actionTemplate'
        - type: object
          required:
          - title
          properties:
            action:
              type: string
              enum: ['openKeypad']
            meta:
              allOf:
              - $ref: '#/components/schemas/meta'
              - type: object
                required:
                - partialMessage

Is it possible to define constant value which can be reference inside enum
like instead of hardcoding single enum i want to make reference to a constant which may be changed but it will not affect schema like as follows

enumTap:
      type: string
      value: tap
tap:
      allOf:
        - $ref: '#/components/schemas/actionObject'
        - type: object
          required:
          - postback
          - title
          properties:
            action:
              type: string
              enum: 
              - $ref: #/Component/enumTap
New Here?
Join us and watch the welcome video:
Top Kudoed Authors
Top Kudoed Posts