-
-
Notifications
You must be signed in to change notification settings - Fork 445
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
Best method for including example of defined input? #296
Comments
Does this help? https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3gen |
@fenollp thats the code I'm using... So the following works for making the schema object: type MyStruct struct {
MyField string `json:"myfield"`
}
s, _, _ := openapi3gen.NewSchemaRefForValue(&MyStruct{}) But I would then need to manipulate that object to add examples for each field. Obviously for this example that is trivial, but for a more complex struct it would quickly become very cumbersome. Ideally I would be able to do something like the following: type MyStruct struct {
MyField string `json:"myfield" oapi-example:"this string should look like this"`
}
s, _, _ := openapi3gen.NewSchemaRefForValue(&MyStruct{}) And it would populate the example automatically. I've dug into the code a bit and the fix to allow something like that would be to add fields to the jsoninfo struct for processing. Not sure if this is a direction that the project wants to go though. Thoughts? |
What is stopping you from setting kin-openapi/openapi3/schema.go Line 109 in 66309f4
|
I am attempting to allow a user-defined struct to define what the input schema for an API would be. I've found the
NewSchemaRefForValue
function that does successfully generate the properties block for a given struct, but there doesn't appear to be a way to provide example input using that function. Is there a method for achieving this currently?The text was updated successfully, but these errors were encountered: