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

[question] Is there a way to return user defined schema type as "file" #99

Open
aryanicosa opened this issue Nov 3, 2022 · 5 comments

Comments

@aryanicosa
Copy link

aryanicosa commented Nov 3, 2022

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",
}
}

@aryanicosa
Copy link
Author

I see in this commit 480c8f3 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 go-swagger/go-swagger#1003

@emicklei
Copy link
Owner

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.

@emicklei
Copy link
Owner

@aryanicosa would that work for you?

@aryanicosa
Copy link
Author

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

@emicklei
Copy link
Owner

emicklei commented Dec 7, 2022

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))
}

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

No branches or pull requests

2 participants