From 870b882739919df3726b7b42ddac61974f805a26 Mon Sep 17 00:00:00 2001 From: Jefftree Date: Thu, 28 Sep 2023 12:37:47 -0400 Subject: [PATCH] Add security requirement to root OpenAPI --- pkg/spec3/spec.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/spec3/spec.go b/pkg/spec3/spec.go index 43613519f..5db819c7f 100644 --- a/pkg/spec3/spec.go +++ b/pkg/spec3/spec.go @@ -36,6 +36,8 @@ type OpenAPI struct { Servers []*Server `json:"servers,omitempty"` // Components hold various schemas for the specification Components *Components `json:"components,omitempty"` + // SecurityRequirement holds a declaration of which security mechanisms can be used across the API + SecurityRequirement []map[string][]string `json:"security,omitempty"` // ExternalDocs holds additional external documentation ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` } @@ -60,12 +62,13 @@ func (o *OpenAPI) MarshalJSON() ([]byte, error) { func (o *OpenAPI) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { type OpenAPIOmitZero struct { - Version string `json:"openapi"` - Info *spec.Info `json:"info"` - Paths *Paths `json:"paths,omitzero"` - Servers []*Server `json:"servers,omitempty"` - Components *Components `json:"components,omitzero"` - ExternalDocs *ExternalDocumentation `json:"externalDocs,omitzero"` + Version string `json:"openapi"` + Info *spec.Info `json:"info"` + Paths *Paths `json:"paths,omitzero"` + Servers []*Server `json:"servers,omitempty"` + Components *Components `json:"components,omitzero"` + SecurityRequirement []map[string][]string `json:"security,omitempty"` + ExternalDocs *ExternalDocumentation `json:"externalDocs,omitzero"` } x := (*OpenAPIOmitZero)(o) return opts.MarshalNext(enc, x)