wI2L / fizz

:lemon: Gin wrapper with OpenAPI 3 spec generation
https://pkg.go.dev/github.com/wI2L/fizz
MIT License
214 stars 52 forks source link

Add Any type for empty interface{} objects #53

Closed rw-access closed 3 years ago

rw-access commented 3 years ago

Closes https://github.com/wI2L/fizz/issues/51

Added handling for empty interface{} so that it's represented like an "any" type in OpenAPI.

From the specs: https://swagger.io/docs/specification/data-models/data-types/#any

Any Type A schema without a type matches any data type – numbers, strings, objects, and so on. {} is shorthand syntax for an arbitrary-type schema:

components:
  schemas:
    AnyValue: {}

If you want to provide a description:

components:
  schemas:
    AnyValue:
      description: Can be any value - string, number, boolean, array or object.

The above is equivalent to:

components:
  schemas:
    AnyValue:
      anyOf:
        - type: string
        - type: number
        - type: integer
        - type: boolean
        - type: array
          items: {}
        - type: object

If the null value needs to be allowed, add nullable: true:

components:
  schemas:
    AnyValue:
      nullable: true
      description: Can be any value, including `null`.
codecov[bot] commented 3 years ago

Codecov Report

Merging #53 (5677a88) into master (7bb66a1) will decrease coverage by 0.85%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #53      +/-   ##
==========================================
- Coverage   96.17%   95.31%   -0.86%     
==========================================
  Files           7        7              
  Lines         889      897       +8     
==========================================
  Hits          855      855              
- Misses         20       27       +7     
- Partials       14       15       +1     
Impacted Files Coverage Δ
openapi/generator.go 93.84% <0.00%> (-0.93%) :arrow_down:
openapi/types.go 97.18% <0.00%> (-2.82%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7bb66a1...5677a88. Read the comment docs.