Skip to content

feat: implement skipping pointer type #1102

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

Merged
merged 2 commits into from
Jul 28, 2023
Merged

feat: implement skipping pointer type #1102

merged 2 commits into from
Jul 28, 2023

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.

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>
danicc097 pushed a commit to danicc097/oapi-codegen that referenced this pull request Aug 31, 2024
* 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>
@pyashish
Copy link

@gabor-boros can I set this at global level ? It's a pain to do this every field.

@gabor-boros
Copy link
Contributor Author

@pyashish I'm not sure there is a way for that.

@pyashish
Copy link

pyashish commented Nov 6, 2024

Thanks, is it on roadmap ?

@gabor-boros
Copy link
Contributor Author

gabor-boros commented Nov 7, 2024

@pyashish To be honest, I've no idea. I'm just an independent contributor 😅 I needed this feature and implemented it

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)
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy