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
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.

1 participant