Open aryanicosa opened 1 year ago
I see in this commit https://github.com/emicklei/go-restful-openapi/commit/480c8f365ca44dad15868767c566c790658333ad made change to be able to handle time.Duration type. But, however, file is not a type. is there a better way to handle this case
similar issue in go-swaggo https://github.com/go-swagger/go-swagger/issues/1003
thank for reporting this issue. We could introduce a new type:
type SchemaType string
that is check in the Returns to allow a raw
type value so that:
Returns(http.StatusOK, http.StatusText(http.StatusOK), SchemaType("file"))
will produce your result.
@aryanicosa would that work for you?
I got your point and able to imagine the result, but I am sorry because confuse how to implement it
I realize that schema type is added here https://github.com/emicklei/go-restful-openapi/blob/v2/build_path.go#L287
but, I am not sure where to introduce type SchemaType string
and create the checker to return raw
type @emicklei
I am still learn and try to figure it out
you are on the right track, i think. From the top of my head, we could have a check after line 261.
if st, ok := e.Model.(SchemaType); ok {
r.Schema.AddType(modelName, string(st))
}
currently Returns it take code, message interface as parameters. e.g: Returns(http.StatusOK, http.StatusText(http.StatusOK), "file")
it will produce apispec like this: "responses": { "200": { "description": "OK", "schema": { "type": "string", } }
However, I am trying to fine a way to create api spec like below, because in reality the handler is returning a file to user "responses": { "200": { "description": "OK", "schema": { "type": "file", } }