feat: implement skipping pointer type#1102
feat: implement skipping pointer type#1102deepmap-marcinr merged 2 commits intooapi-codegen:masterfrom gabor-boros:ext-skip-optional-pointer
Conversation
Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
|
@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>
|
@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. |
|
Ah! I was misunderstanding this from the number of contributions. Sorry for the noise in this case and thank you for the replies! |
|
@alexandear do you have any suggestion who to ask about feedback on this PR? |
|
eepmap-marcinr is one of the maintainers. |
|
Great suggestion @alexandear, thank you! @deepmap-marcinr is there anything I could help out here with the review? |
|
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? |
|
Thank you. |
* 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>
* 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>
|
@gabor-boros can I set this at global level ? It's a pain to do this every field. |
|
@pyashish I'm not sure there is a way for that. |
|
Thanks, is it on roadmap ? |
|
@pyashish To be honest, I've no idea. I'm just an independent contributor 😅 I needed this feature and implemented it |
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]ornull.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