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

feat: implement skipping pointer type #1102

Merged

Conversation

gabor-boros
Copy link
Contributor

@gabor-boros gabor-boros commented Jun 10, 2023

This PR implements skipping pointer types for optional fields to address #1039 and #1061. A new extension is defined to achieve the desired behaviour: x-go-type-skip-optional-pointer.

The extension's name maybe longer than usual, but at least descriptive. If set to true, the type will not be a pointer if the field is optional or nullable. If set to false, the type will be a pointer.

In the case of custom types, like what was proposed in the mentioned issues (Optional[string] or null.Bool), the extension is respected, so it is controllable what to generate (ie. pointer or non-pointer type).

I have already tested this on my own and works very well. Also, added some tests to cover value parsing and code generation. Probably there are cases I didn't prepare for, but I'm happy to add more scenarios.

Upon merge, this PR fixes #388, #382, #823, #1039, #1061 and closes #266, #479

Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
@gabor-boros
Copy link
Contributor Author

@alexandear I assume you are a maintainer in the repo. May I ask a review from you? I found no contribution guidelines.

README.md Outdated Show resolved Hide resolved
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
@alexandear
Copy link
Contributor

@gabor-boros in fact, I'm not an official oapi-codegen maintainer. And don't have permission to merge this PR. So, we should wait for maintainers.

@gabor-boros
Copy link
Contributor Author

Ah! I was misunderstanding this from the number of contributions. Sorry for the noise in this case and thank you for the replies!

@gabor-boros
Copy link
Contributor Author

@alexandear do you have any suggestion who to ask about feedback on this PR?

@alexandear
Copy link
Contributor

eepmap-marcinr is one of the maintainers.

@gabor-boros
Copy link
Contributor Author

Great suggestion @alexandear, thank you!

@deepmap-marcinr is there anything I could help out here with the review?

@notgurev
Copy link

This would be a huge relief from a lot of unnecessary boilerplate.

@deepmap-marcinr this PR is backwards-compatible and shouldn't cause any hate mail (unlike similar PRs you commented on). Any chance it could be merged?

@deepmap-marcinr
Copy link
Contributor

Thank you.

@deepmap-marcinr deepmap-marcinr merged commit 8e4a4fe into oapi-codegen:master Jul 28, 2023
debuggerpk pushed a commit to breuHQ/oapi-codegen that referenced this pull request Sep 18, 2023
* feat: implement skipping pointer type

Signed-off-by: Gabor Boros <gabor.brs@gmail.com>

* docs: apply Go language naming

Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>

---------

Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
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.

Create slice/map/string fields without pointers (for optional fields)
4 participants