OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Restricting Floating MetaObject in domainObject definition using OPen APi 3.0

Open shankar96 opened this issue 7 years ago • 1 comments

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 docs https://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

shankar96 avatar Mar 29 '19 13:03 shankar96

Since this issue is outdated and inactive, it will be closed. Please open an new issue if you still need some help on this.

lornajane avatar Jan 24 '24 16:01 lornajane