File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,10 @@ import (
2424
2525 restful "github.com/emicklei/go-restful"
2626
27+ builderutil "k8s.io/kube-openapi/pkg/builder3/util"
2728 "k8s.io/kube-openapi/pkg/common"
2829 "k8s.io/kube-openapi/pkg/common/restfuladapter"
2930 "k8s.io/kube-openapi/pkg/spec3"
30- builderutil "k8s.io/kube-openapi/pkg/builder3/util"
3131 "k8s.io/kube-openapi/pkg/util"
3232 "k8s.io/kube-openapi/pkg/validation/spec"
3333)
@@ -226,10 +226,14 @@ func newOpenAPI(config *common.Config) openAPI {
226226 }
227227 }
228228
229- o .definitions = o .config .GetDefinitions (func (name string ) spec.Ref {
230- defName , _ := o .config .GetDefinitionName (name )
231- return spec .MustCreateRef ("#/components/schemas/" + common .EscapeJsonPointer (defName ))
232- })
229+ if o .config .Definitions != nil {
230+ o .definitions = o .config .Definitions
231+ } else {
232+ o .definitions = o .config .GetDefinitions (func (name string ) spec.Ref {
233+ defName , _ := o .config .GetDefinitionName (name )
234+ return spec .MustCreateRef ("#/components/schemas/" + common .EscapeJsonPointer (defName ))
235+ })
236+ }
233237
234238 return o
235239}
Original file line number Diff line number Diff line change @@ -94,6 +94,10 @@ type Config struct {
9494 // or any of the models will result in spec generation failure.
9595 GetDefinitions GetOpenAPIDefinitions
9696
97+ // Provides the definition for all models used by routes. One of GetDefinitions or Definitions must be defined to generate a spec.
98+ // This takes precedent over the GetDefinitions function
99+ Definitions map [string ]OpenAPIDefinition
100+
97101 // GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
98102 //
99103 // Deprecated: GetOperationIDAndTagsFromRoute should be used instead. This cannot be specified if using the new Route
@@ -141,8 +145,13 @@ type OpenAPIV3Config struct {
141145
142146 // OpenAPIDefinitions should provide definition for all models used by routes. Failure to provide this map
143147 // or any of the models will result in spec generation failure.
148+ // One of GetDefinitions or Definitions must be defined to generate a spec.
144149 GetDefinitions GetOpenAPIDefinitions
145150
151+ // Provides the definition for all models used by routes. One of GetDefinitions or Definitions must be defined to generate a spec.
152+ // This takes precedent over the GetDefinitions function
153+ Definitions map [string ]OpenAPIDefinition
154+
146155 // GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
147156 //
148157 // Deprecated: GetOperationIDAndTagsFromRoute should be used instead. This cannot be specified if using the new Route
You can’t perform that action at this time.
0 commit comments