Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for random UDF for x-field-pattern fields #467

Merged
merged 10 commits into from
Jul 23, 2024

Conversation

Vibaswan
Copy link
Collaborator

Introducing New random feature for x-field-pattern

Random for Ipv4 Pattern

# initial definition
ipv4:
# other parameters
 dst:
  x-field-pattern:
    format: ipv4
    default: 0.0.0.0
    features: [random]
  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
        random:
          x-field-uid: 6
      default: value
      x-field-uid: 1
      enum:
      - value
      - values
      - random
    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
    random:
     $ref: '#/components/schemas/Pattern.Ipv4Pattern.Ipv4.Dst.Random'
     x-field-uid: 4

Pattern.Ipv4Pattern.Ipv4.Dst.Random:
  description: |-
    ipv4 random pattern
  type: object
  properties:
    min:
      type: string
      x-field-uid: 1
      default: 0.0.0.0
      format: ipv4
    max:
      type: string
      x-field-uid: 2
      default: 255.255.255.255
      format: ipv4
    seed:
      type: integer
      x-field-uid: 3
      default: 1
      format: uint32
    count:
      type: integer
      x-field-uid: 4
      default: 1
      format: uint32

Random for mac pattern

# initial definition
mac:
# other parameters
 dst:
  x-field-pattern:
    format: mac
    features: [random]
  x-field-uid: 1

# after expansion by openapiart
# skipping intermediate strcuture

Pattern.MacPattern.Mac.Random:
  description: |-
    mac random pattern
  type: object
  properties:
    min:
      type: string
      x-field-uid: 1
      default: 00:00:00:00:00:00
      format: mac
    max:
      type: string
      x-field-uid: 2
      default: ff:ff:ff:ff:ff:ff
      format: mac
    seed:
      type: integer
      x-field-uid: 3
      default: 1
      format: uint32
    count:
      type: integer
      x-field-uid: 4
      default: 1
      format: uint32

Random for integer pattern

# initial definition
integer_pattern:
# other parameters
 integer:
  x-field-pattern:
    format: integer
    default: 0
    length: 8
    features: [random]
  x-field-uid: 1

# after expansion by openapiart
# skipping intermediate structure

Pattern.IntegerPattern.Integer.Random:
  description: |-
    integer random pattern
  type: object
  properties:
    min:
      type: integer
      x-field-uid: 1
      default: 0
      format: uint32
      maximum: 255
    max:
      type: integer
      x-field-uid: 2
      default: 255
      format: uint32
      maximum: 255
    seed:
      type: integer
      x-field-uid: 3
      default: 1
      format: uint32
      maximum: 255
    count:
      type: integer
      x-field-uid: 4
      default: 1
      format: uint32
      maximum: 255

sample python code to use random

random = config.ipv4.dst.random
random.min = "1.2.3.4"
random.max = "255.255.3.4"
random.count = 2
random.seed = 2

sample go code to use random

r := Config.Ipv4().Dst().Random()
r.SetMin("1.2.3.4").SetMax("255.255.3.4").SetCount(2).SetSeed(2)

@Vibaswan Vibaswan requested a review from ashutshkumr June 12, 2024 06:49
@Vibaswan Vibaswan requested a review from alakendu July 18, 2024 04:44

# TODO; temporary hack to add auto hierarchy field at the end, remove later
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure we cover following scenario before removing TODO

  1. Test should not regress, expecting you have some test.
  2. I couldn't figure out proper fix of this todo. Could you please pointing out that change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier the fix was to add new auto parameters to end by default forcefully , now the solution is that the features are added according to their position in the features list

pkg/unit1_test.go Outdated Show resolved Hide resolved
@Vibaswan Vibaswan merged commit 93cd89c into main Jul 23, 2024
15 checks passed
@Vibaswan Vibaswan deleted the x-field-random-support branch July 23, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants