application/octet-stream binary data? #124
Answered
by
vearutop
RPGillespie6
asked this question in
Q&A
-
How would I specify that the request or response body is a binary payload of type Basically, I want it to generate:
I've tried:
etc, but can't find any docs. Anyone know? I will submit a PR to improve the docs if I can figure it out. |
Beta Was this translation helpful? Give feedback.
Answered by
vearutop
Jul 11, 2024
Replies: 1 comment 1 reply
-
You can achieve that with a customized content unit. Please check an example: https://go.dev/play/p/9uH7zLRS60R package main
import (
"encoding/json"
"net/http"
"github.com/swaggest/openapi-go"
"github.com/swaggest/openapi-go/openapi31"
)
func main() {
r := openapi31.NewReflector()
oc, _ := r.NewOperationContext(http.MethodGet, "/")
oc.AddReqStructure(nil, func(cu *openapi.ContentUnit) {
cu.ContentType = "application/octet-stream"
cu.Format = "binary"
cu.Description = "Raw bytes of the data"
})
_ = r.AddOperation(oc)
j, _ := json.MarshalIndent(r.SpecSchema(), "", " ")
println(string(j))
} {
"openapi": "3.1.0",
"info": {
"title": "",
"version": ""
},
"paths": {
"/": {
"get": {
"requestBody": {
"description": "Raw bytes of the data",
"content": {
"application/octet-stream": {
"schema": {
"format": "binary",
"type": "string"
}
}
}
},
"responses": {
"204": {
"description": "No Content"
}
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
RPGillespie6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can achieve that with a customized content unit. Please check an example:
https://go.dev/play/p/9uH7zLRS60R