discord-gophers / goapi-gen

This package contains a set of utilities for generating Go boilerplate code for services based on OpenAPI 3.0 API definitions
Apache License 2.0
137 stars 12 forks source link

Implement x-go-optional-value, x-go-string #82

Closed diamondburned closed 2 years ago

diamondburned commented 2 years ago

This commit implements x-go-optional-value, which forces the code generator to generate value types (not pointer types) for optional parameters. This closes issue #76.

Particularly, with how this commit is implemented, this is completely allowed:

    OptionalObject:
      description: Tests x-go-optional-value on the whole object
      x-go-optional-value: true
      properties:
        str1:
          type: string
        str2:
          type: string
        str_ptr1:
          type: string
          x-go-optional-value: false
        str_ptr2:
          type: string
          x-go-optional-value: false

The x-go-optional-values can override each other depending on its hierarchy.

This commit also implements x-go-string, which adds the ",string" suffix into the JSON tag of a field, allowing that field to be parsed from a string to an integer of any type. This closes issue #77.