podhmo / reflect-openapi

Define OpenAPI with reflect package
Apache License 2.0
3 stars 0 forks source link

handling interception with useRefResolver, correctly #50

Closed podhmo closed 3 years ago

podhmo commented 3 years ago

for #39

time.Time is registered, but generated openapi doc is not included as schema.

podhmo commented 3 years ago

the simple reproducible example

package main

import (
    "time"

    reflectopenapi "github.com/podhmo/reflect-openapi"
)

type Media struct {
    Name  string    `json:"name"`
    CTime time.Time `json:"ctime"`
}

func main() {
    var c reflectopenapi.Config

    c.EmitDoc(func(m *reflectopenapi.Manager) {
        op := m.Visitor.VisitFunc(ListMedia)
        m.Doc.AddOperation("/Media/", "GET", op)
    })
}

func ListMedia() []*Media {
    return nil
}
podhmo commented 3 years ago

generated doc

{
  "components": {
    "schemas": {
      "Media": {
        "properties": {
          "ctime": {
            "$ref": "#/components/schemas/Time"
          },
          "name": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "Time": {
        "format": "date-time",
        "type": "string"
      }
    }
  },
  "info": {
    "description": "-",
    "title": "Sample API",
    "version": "0.0.0"
  },
  "openapi": "3.0.0",
  "paths": {
    "/Media/": {
      "get": {
        "operationId": "main.ListMedia",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/Media"
                  },
                  "type": "array"
                }
              }
            },
            "description": ""
          },
          "default": {
            "description": ""
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "http://localhost:8888",
      "description": "local development server"
    }
  ]
}
podhmo commented 3 years ago

fixed already.