open-traffic-generator / openapiart

OpenAPI artifact generator
MIT License
6 stars 4 forks source link

support for auto heirarchy #464

Closed Vibaswan closed 4 months ago

Vibaswan commented 5 months ago

Old Definition

The old way of auto works the same way. i.e. by defining auto in features example:

# initial definition
ipv4:
# other parameters
 dst:
  x-field-pattern:
    format: ipv4
    default: 0.0.0.0
    features: [auto, count]
  x-field-uid: 1

# after expansion by openapiart
Pattern.Ipv4Pattern.Ipv4.Dst:
  type: object
  properties:
    choice:
      type: string
      x-enum:
        value:
          x-field-uid: 2
        values:
          x-field-uid: 3
        auto:
          x-field-uid: 1
        increment:
          x-field-uid: 4
        decrement:
          x-field-uid: 5
      default: auto
      x-field-uid: 1
      enum:
      - value
      - values
      - auto
      - increment
      - decrement
    value:
      type: string
      x-field-uid: 2
      default: 0.0.0.0
      format: ipv4
    values:
      type: array
      items:
        type: string
        format: ipv4
      x-field-uid: 3
      default:
      - 0.0.0.0
    auto:
      description: |-
        The OTG implementation can provide a system generated
        value for this property. If the OTG is unable to generate a value
        the default value must be used.
      type: string
      x-field-uid: 4
      default: 0.0.0.0
      format: ipv4
    increment:
      $ref: '#/components/schemas/Pattern.Ipv4Pattern.Ipv4.Dst.Counter'
      x-field-uid: 5
    decrement:
      $ref: '#/components/schemas/Pattern.Ipv4Pattern.Ipv4.Dst.Counter'
      x-field-uid: 6

New Definition The new definition allows auto to be hierarchical. only valid property inside auto allowed till now is ref, which points to a object in the yaml and default which accepts a Boolean value to specify whether auto should be default choice or not.

# initial definition
ipv4:
# other properties
 dst:
  x-field-pattern:
    format: ipv4
    default: 0.0.0.0
    features: [auto, count]
    auto:
      $ref: "#/components/schemas/AutoIpOptions"
      default: false
  x-field-uid: 1

AutoIpOptions:
description: |-
  The OTG implementation can provide a system generated, value for this property. If the OTG is unable to generate a value, 
  the default value must be used.
type: object
  required: [choice]
  properties:
    choice:
      type: string
      x-field-uid: 1
      x-enum:
        static:
          x-field-uid: 1
        dhcp:
          x-field-uid: 2

# after expansion by openapiart
Pattern.Ipv4Pattern.Ipv4.Dst:
  type: object
  properties:
    choice:
      type: string
      x-enum:
        value:
          x-field-uid: 2
        values:
          x-field-uid: 3
        auto:
          x-field-uid: 1
        increment:
          x-field-uid: 4
        decrement:
          x-field-uid: 5
      default: auto
      x-field-uid: 1
      enum:
      - value
      - values
      - auto
      - increment
      - decrement
    value:
      type: string
      x-field-uid: 2
      default: 0.0.0.0
      format: ipv4
    values:
      type: array
      items:
        type: string
        format: ipv4
      x-field-uid: 3
      default:
      - 0.0.0.0
    auto:
      $ref: '#/components/schemas/AutoIpOptions'
      x-field-uid: 4
    increment:
      $ref: '#/components/schemas/Pattern.Ipv4Pattern.Ipv4.Dst.Counter'
      x-field-uid: 5
    decrement:
      $ref: '#/components/schemas/Pattern.Ipv4Pattern.Ipv4.Dst.Counter'
      x-field-uid: 6

Go snippet to set hierarchical auto

Config.Ipv4().Dst().SetValue("1.1.1.2")
Config.Ipv4().Dst().Auto().Static()
Config.Ipv4().Dst().Auto().Dhcp()

Python snippet to set hierarchical auto Note: python SDK exposes choice as of now unlike go SDK and also choices with no properties does not have a getter yet

config.ipv4.dst.value = "1.1.1.2"
config.ipv4.dst.auto.choice = "static"
config.ipv4.dst.auto.choice = "dhcp"
apratimmukherjee commented 5 months ago

@Vibaswan : Please change the examples to point to a single field such ipv4.src instead of ipv4.

Another query : How will the description be generated ... will it use the description if supplied by the model author ?

Vibaswan commented 5 months ago

@Vibaswan : Please change the examples to point to a single field such ipv4.src instead of ipv4.

Another query : How will the description be generated ... will it use the description if supplied by the model author ?

@apratimmukherjee corrected the examples Yes the description in auto hierarchy will be provided by the user , it should be mention in the object auto is referring to , updated the example as well

Vibaswan commented 4 months ago

models link where auto hierarchy is been used https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/open-traffic-generator/models/traffic_over_dhcp_interface/artifacts/openapi.yaml&nocors#tag/Configuration/operation/set_config

ipv4_yaml changes https://github.com/open-traffic-generator/models/pull/372/files#diff-b4e391ad7a6920f2c2eb0175634e1655ee8d42bdd7db74e833b99448f8de2116R115