-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
openapi3gen: allow overriding how a Schema is generated #920
openapi3gen: allow overriding how a Schema is generated #920
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! LGTM, just: commit ./docs.sh
and add a test or better: an example that shows your use case.
* add unitest, generate docs
Thanks for the input, tagging @blackhun11 for his implementation, feel free to re-review those anytime @fenollp |
Oh and regarding the example, I wrote one similar to my usecase on the issue #919 , so should those examples be commited to someplace on the repo? or is that issue sufficient for the example |
openapi3gen/openapi3gen_test.go
Outdated
schema.Type = &openapi3.Types{"string"} // Assuming this matches your custom implementation | ||
schema.Format = "uuid" | ||
} | ||
func TestNewSchemaRefForValueWithSetSchemar(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please turn this into an example so usage of SetSchema
gets examples in the docs
This name example's name should include the name of the interface you introduce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @fenollp thank you for the review! i just change my Test
to use Example
and already put the output also. kindly re-review it again. thank you
openapi3gen/openapi3gen_test.go
Outdated
// Optional: Marshal and inspect the schemas and schemaRef if needed for further verification | ||
_, err = json.MarshalIndent(schemas, "", " ") | ||
require.NoError(t, err, "error marshaling schemas") | ||
|
||
_, err = json.MarshalIndent(schemaRef, "", " ") | ||
require.NoError(t, err, "error marshaling schemaRef") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be at least one call to require.JSONEq(t, .., ..)
with the serialized json data, showing that format
is indeed set, possibly that it isn't set any wrong place, ...
Feel free to copy from #919
schema.Format = "uuid" | ||
} | ||
|
||
func ExampleID_SetSchema() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost! See here you define an Example
for the SetSchema
method of the ID
type. It doesn't help because these type and method live in test files so don't end up in the generated docs. Instead this should be named ExampleSetSchemar
.
I'll amend this myself, no worries.
Implementation of #919