open-traffic-generator / openapiart

OpenAPI artifact generator
MIT License
6 stars 4 forks source link

API call with arguments consisting of an object with choices need to facilitate stronger type safety #360

Open ashutshkumr opened 2 years ago

ashutshkumr commented 2 years ago

Is your feature request related to a use case? Please describe. For code snippet below, error won't be reported if user happened to accidentally pass ps to both the calls or modified ps twice (with different choices).

api := gosnappi.NewApi()
c := api.NewConfig()

// set config
api.SetConfig(c)

// By design, pass parent object consisting of choices during API call

// set protocol state
ps := gosnappi.NewControlState()
ps.Protocol().SetState(gosnappi.ProtocolStateState.START)

// set transmit state
ts := gosnappi.NewControlState()
ts.FlowTransmit().SetState(gosnappi.TransmitStateState.START)

// call APIs
api.SetControlState(ps)
api.SetControlState(ts)

Describe the solution you'd like

Discussed following two approaches which potentially provide more guard rails.

ashutshkumr commented 2 years ago

Originally reported by @greg-dennis @marcushines