Skip to content

How do I get the value for a parameter example? #61

Answered by vearutop
mcred asked this question in Q&A
Discussion options

You must be logged in to vote

Not sure if I understand the problem, but this is how you can read this value

	var s openapi3.ParameterOrRef
	// .....
	if s.Parameter != nil && s.Parameter.Example != nil {
		ex := *s.Parameter.Example
		
		// If you expect an integer value in example, you'd need to unbox it from 
		// float64 which is used in JSON for all numbers.
		if n, ok := ex.(float64); ok {
			i := int(n)
			
			fmt.Printf("I'm an example value: %d!\n", i)
		}
	}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mcred
Comment options

Answer selected by mcred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants