-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: support global type overrides #1059
Conversation
@ian-fox, is there any open issue regarding this issue? I'm asking this because we appreciate everyone's effort to write a PR, but sometimes it is safer to validate the solution before writing the implementation. |
There is not, I figured it was small enough that is write it up, learn something in the process, and if it wasn't accepted then that's fine because it didn't take too long anyway. If there are any changes you'd suggest I'm happy to make them, and if it's just a poor design that you'd rather not accept that's also totally fine. |
@ian-fox the ability to replace the definitions without touching the source code sound good to me. Somehow an attempt to solve this issue was partially solved by introducing "swaggerype" a long time ago. I'm thinking it would be nice to have a simple dot file in the same way git has".gitingore". YAML/TOML is too heavy (the libraries are not light at all and it will introduce additional unwanted dependencies) and JSON is not so user-friendly when it comes to editing. Eventually, we can add at a later time the ability to control the flow like cmd params do, without the need to update the CI pipeline. Example swag dot file (.swag) // replace a defintion
replace database/sql.NullInt64 int64
// skip parsing a package
skip github.com/grpc/grpc-go |
Sounds good to me! I'll go add those changes 😄 |
I think all the issues with the tests and static analysis should be fixed now. |
Codecov Report
@@ Coverage Diff @@
## master #1059 +/- ##
==========================================
- Coverage 94.42% 94.22% -0.21%
==========================================
Files 9 9
Lines 2261 2320 +59
==========================================
+ Hits 2135 2186 +51
- Misses 66 70 +4
- Partials 60 64 +4
Continue to review full report at Codecov.
|
I'm thinking it's easier to finish the code changes first and after that, you can take care of the code coverage. |
Can you please fix the failing tests? |
Yep. Sorry about that, was counting on CI to run the monkey-patch related ones because monkey does not work on my computer. |
We need to keep compatible with older GO versions.
try simply return errors.New("file does not exist"); |
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.
LGTM
Thank you for all your help! |
@ian-fox Thanks for your contribution. You're wellcome. |
Describe the PR
When using generated files (such as from sqlboiler) we encountered a situation where we wanted to override a type (e.g. have
null.String
, a struct with custom json marshal/unmarshalers, show up in the swagger docs asstring
instead of as astruct
with a string and a bool) but could not use theswaggertype
struct tag overrides, as sqlboiler does not allow you to customize those on a per-type basis.This PR adds a global "overrides file" where you can specify a mapping of what type is actually used in the code, and what type (basic or otherwise) you'd like it to render as in the generated docs.
Please let me know if you think there are any changes that should be made!
Relation issue
#985 seems related
Additional context
The solution to our problem seemed to be either modifying sqlboiler to allow it to insert custom tags on a per-type basis (e.g. add a
swaggertype:"string"
tag whenever it generated a struct with anull.String
) or to modify swaggo to be able to do replacements without the struct tag; this seemed like it was probably more broadly useful because it may help with other generators than just sqlboiler.