Skip to content

Is there an option for choosing between Schema and SchemaReference #55

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

You must be logged in to vote

Hello, this is possible with Reflector.InlineDefinition.

https://go.dev/play/p/t_QV033Lejd

package main

import (
	"fmt"
	"net/http"

	"github.com/swaggest/openapi-go/openapi3"
)

type MyStruct struct {
	Field1 *int  `json:"field1"`
	Field2 *bool `json:"field2"`
}

// ForceRequestBody enforces body on bodyless operations (GET/HEAD/DELETE/TRACE),
// would not be needed for POST/PUT/PATCH.
func (m MyStruct) ForceRequestBody() {}

func main() {
	r := openapi3.Reflector{}

	// Mark MyStruct as inlinable.
	r.InlineDefinition(MyStruct{}) // <----

	// Alternatively you can enable such behavior for all types, this may be dangerous if there are cyclic refs.
	//
	// r.DefaultOptions = append(r.Def…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by Fifi31
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