Skip to content

application/octet-stream binary data? #124

Answered by vearutop
RPGillespie6 asked this question in Q&A
Discussion options

You must be logged in to vote

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":…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RPGillespie6
Comment options

Answer selected by RPGillespie6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants