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

Add support for generating pointers as x-nullable #1848

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Thiht
Copy link

@Thiht Thiht commented Jul 22, 2024

Describe the PR

With this change, pointers inside a struct are automatically generated with the x-nullable extension

New CLI flag: --nullablePointers

  • Pointers in structs are generated with x-nullable: true
  • If the schema contains a single $ref, like this:
my_field:
  $ref: "#/definitions/api.Child"
  x-nullable: true

it will be generated like this instead:

my_field:
  allOf:
    $ref: "#/definitions/api.Child"
  x-nullable: true

This ensures the result can then be converted to OpenAPI 3.0 without losing the nullable field (using: https://converter.swagger.io). See: https://stackoverflow.com/a/48114924

I'm willing to make some improvements if you have any suggestions, I'm not sure I made the change correctly as it just fits my use case for now :)

Relation issue
none

Additional context

I want to generate x-nullable on my pointers but I don't want to annotate all my fields with extensions:x-nullable. I think it makes sense to allow generating the x-nullable by default for all pointers.

With this change, pointers inside a struct are automatically generated with the x-nullable extension

New CLI flag: --nullablePointers
@ubogdan
Copy link
Contributor

ubogdan commented Oct 17, 2024

For next time, I recommend you should open an issue before writing an implementation.

@Thiht
Copy link
Author

Thiht commented Oct 21, 2024

@ubogdan haha sorry about that, I actually forked to add the feature for my team (we currently use the fork) and decided to try to upstream afterwards

I can still open an issue if you prefer and want to discuss some things, and if you have any feedback I'll be glad to make the changes

@ubogdan
Copy link
Contributor

ubogdan commented Oct 21, 2024

I don't have any issue adding this improvement to the code; right now, I don't see its usage.

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.

2 participants