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

openapi3gen: allow overriding how a Schema is generated #920

Merged
merged 3 commits into from
Apr 6, 2024

Conversation

taufik-rama
Copy link
Contributor

@taufik-rama taufik-rama commented Mar 6, 2024

Implementation of #919

Copy link
Collaborator

@fenollp fenollp left a 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.

@fenollp fenollp linked an issue Mar 22, 2024 that may be closed by this pull request
@fenollp fenollp changed the title openapi3gen: Implementation of #919 openapi3gen: allow overriding how a Schema is generated Mar 22, 2024
* add unitest, generate docs
@taufik-rama
Copy link
Contributor Author

Thanks for the input, tagging @blackhun11 for his implementation, feel free to re-review those anytime @fenollp

@taufik-rama
Copy link
Contributor Author

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

schema.Type = &openapi3.Types{"string"} // Assuming this matches your custom implementation
schema.Format = "uuid"
}
func TestNewSchemaRefForValueWithSetSchemar(t *testing.T) {
Copy link
Collaborator

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.

https://go.dev/blog/examples

Copy link
Contributor

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

Comment on lines 615 to 620
// 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")
Copy link
Collaborator

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() {
Copy link
Collaborator

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.

@fenollp fenollp merged commit 5aee5fc into getkin:master Apr 6, 2024
7 checks passed
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.

openapi3gen: Allow client with custom type to supply their own type(s)
3 participants