schema.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // Copyright 2015 go-swagger maintainers
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package spec
  15. import (
  16. "encoding/json"
  17. "fmt"
  18. "net/url"
  19. "strings"
  20. "github.com/go-openapi/swag"
  21. "k8s.io/kube-openapi/pkg/internal"
  22. jsonv2 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json"
  23. )
  24. // BooleanProperty creates a boolean property
  25. func BooleanProperty() *Schema {
  26. return &Schema{SchemaProps: SchemaProps{Type: []string{"boolean"}}}
  27. }
  28. // BoolProperty creates a boolean property
  29. func BoolProperty() *Schema { return BooleanProperty() }
  30. // StringProperty creates a string property
  31. func StringProperty() *Schema {
  32. return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}
  33. }
  34. // CharProperty creates a string property
  35. func CharProperty() *Schema {
  36. return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}
  37. }
  38. // Float64Property creates a float64/double property
  39. func Float64Property() *Schema {
  40. return &Schema{SchemaProps: SchemaProps{Type: []string{"number"}, Format: "double"}}
  41. }
  42. // Float32Property creates a float32/float property
  43. func Float32Property() *Schema {
  44. return &Schema{SchemaProps: SchemaProps{Type: []string{"number"}, Format: "float"}}
  45. }
  46. // Int8Property creates an int8 property
  47. func Int8Property() *Schema {
  48. return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int8"}}
  49. }
  50. // Int16Property creates an int16 property
  51. func Int16Property() *Schema {
  52. return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int16"}}
  53. }
  54. // Int32Property creates an int32 property
  55. func Int32Property() *Schema {
  56. return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int32"}}
  57. }
  58. // Int64Property creates an int64 property
  59. func Int64Property() *Schema {
  60. return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int64"}}
  61. }
  62. // StrFmtProperty creates a property for the named string format
  63. func StrFmtProperty(format string) *Schema {
  64. return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: format}}
  65. }
  66. // DateProperty creates a date property
  67. func DateProperty() *Schema {
  68. return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: "date"}}
  69. }
  70. // DateTimeProperty creates a date time property
  71. func DateTimeProperty() *Schema {
  72. return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: "date-time"}}
  73. }
  74. // MapProperty creates a map property
  75. func MapProperty(property *Schema) *Schema {
  76. return &Schema{SchemaProps: SchemaProps{Type: []string{"object"},
  77. AdditionalProperties: &SchemaOrBool{Allows: true, Schema: property}}}
  78. }
  79. // RefProperty creates a ref property
  80. func RefProperty(name string) *Schema {
  81. return &Schema{SchemaProps: SchemaProps{Ref: MustCreateRef(name)}}
  82. }
  83. // RefSchema creates a ref property
  84. func RefSchema(name string) *Schema {
  85. return &Schema{SchemaProps: SchemaProps{Ref: MustCreateRef(name)}}
  86. }
  87. // ArrayProperty creates an array property
  88. func ArrayProperty(items *Schema) *Schema {
  89. if items == nil {
  90. return &Schema{SchemaProps: SchemaProps{Type: []string{"array"}}}
  91. }
  92. return &Schema{SchemaProps: SchemaProps{Items: &SchemaOrArray{Schema: items}, Type: []string{"array"}}}
  93. }
  94. // ComposedSchema creates a schema with allOf
  95. func ComposedSchema(schemas ...Schema) *Schema {
  96. s := new(Schema)
  97. s.AllOf = schemas
  98. return s
  99. }
  100. // SchemaURL represents a schema url
  101. type SchemaURL string
  102. // MarshalJSON marshal this to JSON
  103. func (r SchemaURL) MarshalJSON() ([]byte, error) {
  104. if r == "" {
  105. return []byte("{}"), nil
  106. }
  107. v := map[string]interface{}{"$schema": string(r)}
  108. return json.Marshal(v)
  109. }
  110. // UnmarshalJSON unmarshal this from JSON
  111. func (r *SchemaURL) UnmarshalJSON(data []byte) error {
  112. var v map[string]interface{}
  113. if err := json.Unmarshal(data, &v); err != nil {
  114. return err
  115. }
  116. return r.fromMap(v)
  117. }
  118. func (r *SchemaURL) fromMap(v map[string]interface{}) error {
  119. if v == nil {
  120. return nil
  121. }
  122. if vv, ok := v["$schema"]; ok {
  123. if str, ok := vv.(string); ok {
  124. u, err := url.Parse(str)
  125. if err != nil {
  126. return err
  127. }
  128. *r = SchemaURL(u.String())
  129. }
  130. }
  131. return nil
  132. }
  133. // SchemaProps describes a JSON schema (draft 4)
  134. type SchemaProps struct {
  135. ID string `json:"id,omitempty"`
  136. Ref Ref `json:"-"`
  137. Schema SchemaURL `json:"-"`
  138. Description string `json:"description,omitempty"`
  139. Type StringOrArray `json:"type,omitempty"`
  140. Nullable bool `json:"nullable,omitempty"`
  141. Format string `json:"format,omitempty"`
  142. Title string `json:"title,omitempty"`
  143. Default interface{} `json:"default,omitempty"`
  144. Maximum *float64 `json:"maximum,omitempty"`
  145. ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
  146. Minimum *float64 `json:"minimum,omitempty"`
  147. ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
  148. MaxLength *int64 `json:"maxLength,omitempty"`
  149. MinLength *int64 `json:"minLength,omitempty"`
  150. Pattern string `json:"pattern,omitempty"`
  151. MaxItems *int64 `json:"maxItems,omitempty"`
  152. MinItems *int64 `json:"minItems,omitempty"`
  153. UniqueItems bool `json:"uniqueItems,omitempty"`
  154. MultipleOf *float64 `json:"multipleOf,omitempty"`
  155. Enum []interface{} `json:"enum,omitempty"`
  156. MaxProperties *int64 `json:"maxProperties,omitempty"`
  157. MinProperties *int64 `json:"minProperties,omitempty"`
  158. Required []string `json:"required,omitempty"`
  159. Items *SchemaOrArray `json:"items,omitempty"`
  160. AllOf []Schema `json:"allOf,omitempty"`
  161. OneOf []Schema `json:"oneOf,omitempty"`
  162. AnyOf []Schema `json:"anyOf,omitempty"`
  163. Not *Schema `json:"not,omitempty"`
  164. Properties map[string]Schema `json:"properties,omitempty"`
  165. AdditionalProperties *SchemaOrBool `json:"additionalProperties,omitempty"`
  166. PatternProperties map[string]Schema `json:"patternProperties,omitempty"`
  167. Dependencies Dependencies `json:"dependencies,omitempty"`
  168. AdditionalItems *SchemaOrBool `json:"additionalItems,omitempty"`
  169. Definitions Definitions `json:"definitions,omitempty"`
  170. }
  171. // Marshaling structure only, always edit along with corresponding
  172. // struct (or compilation will fail).
  173. type schemaPropsOmitZero struct {
  174. ID string `json:"id,omitempty"`
  175. Ref Ref `json:"-"`
  176. Schema SchemaURL `json:"-"`
  177. Description string `json:"description,omitempty"`
  178. Type StringOrArray `json:"type,omitzero"`
  179. Nullable bool `json:"nullable,omitzero"`
  180. Format string `json:"format,omitempty"`
  181. Title string `json:"title,omitempty"`
  182. Default interface{} `json:"default,omitzero"`
  183. Maximum *float64 `json:"maximum,omitempty"`
  184. ExclusiveMaximum bool `json:"exclusiveMaximum,omitzero"`
  185. Minimum *float64 `json:"minimum,omitempty"`
  186. ExclusiveMinimum bool `json:"exclusiveMinimum,omitzero"`
  187. MaxLength *int64 `json:"maxLength,omitempty"`
  188. MinLength *int64 `json:"minLength,omitempty"`
  189. Pattern string `json:"pattern,omitempty"`
  190. MaxItems *int64 `json:"maxItems,omitempty"`
  191. MinItems *int64 `json:"minItems,omitempty"`
  192. UniqueItems bool `json:"uniqueItems,omitzero"`
  193. MultipleOf *float64 `json:"multipleOf,omitempty"`
  194. Enum []interface{} `json:"enum,omitempty"`
  195. MaxProperties *int64 `json:"maxProperties,omitempty"`
  196. MinProperties *int64 `json:"minProperties,omitempty"`
  197. Required []string `json:"required,omitempty"`
  198. Items *SchemaOrArray `json:"items,omitzero"`
  199. AllOf []Schema `json:"allOf,omitempty"`
  200. OneOf []Schema `json:"oneOf,omitempty"`
  201. AnyOf []Schema `json:"anyOf,omitempty"`
  202. Not *Schema `json:"not,omitzero"`
  203. Properties map[string]Schema `json:"properties,omitempty"`
  204. AdditionalProperties *SchemaOrBool `json:"additionalProperties,omitzero"`
  205. PatternProperties map[string]Schema `json:"patternProperties,omitempty"`
  206. Dependencies Dependencies `json:"dependencies,omitempty"`
  207. AdditionalItems *SchemaOrBool `json:"additionalItems,omitzero"`
  208. Definitions Definitions `json:"definitions,omitempty"`
  209. }
  210. // SwaggerSchemaProps are additional properties supported by swagger schemas, but not JSON-schema (draft 4)
  211. type SwaggerSchemaProps struct {
  212. Discriminator string `json:"discriminator,omitempty"`
  213. ReadOnly bool `json:"readOnly,omitempty"`
  214. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
  215. Example interface{} `json:"example,omitempty"`
  216. }
  217. // Marshaling structure only, always edit along with corresponding
  218. // struct (or compilation will fail).
  219. type swaggerSchemaPropsOmitZero struct {
  220. Discriminator string `json:"discriminator,omitempty"`
  221. ReadOnly bool `json:"readOnly,omitzero"`
  222. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitzero"`
  223. Example interface{} `json:"example,omitempty"`
  224. }
  225. // Schema the schema object allows the definition of input and output data types.
  226. // These types can be objects, but also primitives and arrays.
  227. // This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/)
  228. // and uses a predefined subset of it.
  229. // On top of this subset, there are extensions provided by this specification to allow for more complete documentation.
  230. //
  231. // For more information: http://goo.gl/8us55a#schemaObject
  232. type Schema struct {
  233. VendorExtensible
  234. SchemaProps
  235. SwaggerSchemaProps
  236. ExtraProps map[string]interface{} `json:"-"`
  237. }
  238. // WithID sets the id for this schema, allows for chaining
  239. func (s *Schema) WithID(id string) *Schema {
  240. s.ID = id
  241. return s
  242. }
  243. // WithTitle sets the title for this schema, allows for chaining
  244. func (s *Schema) WithTitle(title string) *Schema {
  245. s.Title = title
  246. return s
  247. }
  248. // WithDescription sets the description for this schema, allows for chaining
  249. func (s *Schema) WithDescription(description string) *Schema {
  250. s.Description = description
  251. return s
  252. }
  253. // WithProperties sets the properties for this schema
  254. func (s *Schema) WithProperties(schemas map[string]Schema) *Schema {
  255. s.Properties = schemas
  256. return s
  257. }
  258. // SetProperty sets a property on this schema
  259. func (s *Schema) SetProperty(name string, schema Schema) *Schema {
  260. if s.Properties == nil {
  261. s.Properties = make(map[string]Schema)
  262. }
  263. s.Properties[name] = schema
  264. return s
  265. }
  266. // WithAllOf sets the all of property
  267. func (s *Schema) WithAllOf(schemas ...Schema) *Schema {
  268. s.AllOf = schemas
  269. return s
  270. }
  271. // WithMaxProperties sets the max number of properties an object can have
  272. func (s *Schema) WithMaxProperties(max int64) *Schema {
  273. s.MaxProperties = &max
  274. return s
  275. }
  276. // WithMinProperties sets the min number of properties an object must have
  277. func (s *Schema) WithMinProperties(min int64) *Schema {
  278. s.MinProperties = &min
  279. return s
  280. }
  281. // Typed sets the type of this schema for a single value item
  282. func (s *Schema) Typed(tpe, format string) *Schema {
  283. s.Type = []string{tpe}
  284. s.Format = format
  285. return s
  286. }
  287. // AddType adds a type with potential format to the types for this schema
  288. func (s *Schema) AddType(tpe, format string) *Schema {
  289. s.Type = append(s.Type, tpe)
  290. if format != "" {
  291. s.Format = format
  292. }
  293. return s
  294. }
  295. // AsNullable flags this schema as nullable.
  296. func (s *Schema) AsNullable() *Schema {
  297. s.Nullable = true
  298. return s
  299. }
  300. // CollectionOf a fluent builder method for an array parameter
  301. func (s *Schema) CollectionOf(items Schema) *Schema {
  302. s.Type = []string{jsonArray}
  303. s.Items = &SchemaOrArray{Schema: &items}
  304. return s
  305. }
  306. // WithDefault sets the default value on this parameter
  307. func (s *Schema) WithDefault(defaultValue interface{}) *Schema {
  308. s.Default = defaultValue
  309. return s
  310. }
  311. // WithRequired flags this parameter as required
  312. func (s *Schema) WithRequired(items ...string) *Schema {
  313. s.Required = items
  314. return s
  315. }
  316. // AddRequired adds field names to the required properties array
  317. func (s *Schema) AddRequired(items ...string) *Schema {
  318. s.Required = append(s.Required, items...)
  319. return s
  320. }
  321. // WithMaxLength sets a max length value
  322. func (s *Schema) WithMaxLength(max int64) *Schema {
  323. s.MaxLength = &max
  324. return s
  325. }
  326. // WithMinLength sets a min length value
  327. func (s *Schema) WithMinLength(min int64) *Schema {
  328. s.MinLength = &min
  329. return s
  330. }
  331. // WithPattern sets a pattern value
  332. func (s *Schema) WithPattern(pattern string) *Schema {
  333. s.Pattern = pattern
  334. return s
  335. }
  336. // WithMultipleOf sets a multiple of value
  337. func (s *Schema) WithMultipleOf(number float64) *Schema {
  338. s.MultipleOf = &number
  339. return s
  340. }
  341. // WithMaximum sets a maximum number value
  342. func (s *Schema) WithMaximum(max float64, exclusive bool) *Schema {
  343. s.Maximum = &max
  344. s.ExclusiveMaximum = exclusive
  345. return s
  346. }
  347. // WithMinimum sets a minimum number value
  348. func (s *Schema) WithMinimum(min float64, exclusive bool) *Schema {
  349. s.Minimum = &min
  350. s.ExclusiveMinimum = exclusive
  351. return s
  352. }
  353. // WithEnum sets a the enum values (replace)
  354. func (s *Schema) WithEnum(values ...interface{}) *Schema {
  355. s.Enum = append([]interface{}{}, values...)
  356. return s
  357. }
  358. // WithMaxItems sets the max items
  359. func (s *Schema) WithMaxItems(size int64) *Schema {
  360. s.MaxItems = &size
  361. return s
  362. }
  363. // WithMinItems sets the min items
  364. func (s *Schema) WithMinItems(size int64) *Schema {
  365. s.MinItems = &size
  366. return s
  367. }
  368. // UniqueValues dictates that this array can only have unique items
  369. func (s *Schema) UniqueValues() *Schema {
  370. s.UniqueItems = true
  371. return s
  372. }
  373. // AllowDuplicates this array can have duplicates
  374. func (s *Schema) AllowDuplicates() *Schema {
  375. s.UniqueItems = false
  376. return s
  377. }
  378. // AddToAllOf adds a schema to the allOf property
  379. func (s *Schema) AddToAllOf(schemas ...Schema) *Schema {
  380. s.AllOf = append(s.AllOf, schemas...)
  381. return s
  382. }
  383. // WithDiscriminator sets the name of the discriminator field
  384. func (s *Schema) WithDiscriminator(discriminator string) *Schema {
  385. s.Discriminator = discriminator
  386. return s
  387. }
  388. // AsReadOnly flags this schema as readonly
  389. func (s *Schema) AsReadOnly() *Schema {
  390. s.ReadOnly = true
  391. return s
  392. }
  393. // AsWritable flags this schema as writeable (not read-only)
  394. func (s *Schema) AsWritable() *Schema {
  395. s.ReadOnly = false
  396. return s
  397. }
  398. // WithExample sets the example for this schema
  399. func (s *Schema) WithExample(example interface{}) *Schema {
  400. s.Example = example
  401. return s
  402. }
  403. // WithExternalDocs sets/removes the external docs for/from this schema.
  404. // When you pass empty strings as params the external documents will be removed.
  405. // When you pass non-empty string as one value then those values will be used on the external docs object.
  406. // So when you pass a non-empty description, you should also pass the url and vice versa.
  407. func (s *Schema) WithExternalDocs(description, url string) *Schema {
  408. if description == "" && url == "" {
  409. s.ExternalDocs = nil
  410. return s
  411. }
  412. if s.ExternalDocs == nil {
  413. s.ExternalDocs = &ExternalDocumentation{}
  414. }
  415. s.ExternalDocs.Description = description
  416. s.ExternalDocs.URL = url
  417. return s
  418. }
  419. // MarshalJSON marshal this to JSON
  420. func (s Schema) MarshalJSON() ([]byte, error) {
  421. if internal.UseOptimizedJSONMarshaling {
  422. return internal.DeterministicMarshal(s)
  423. }
  424. b1, err := json.Marshal(s.SchemaProps)
  425. if err != nil {
  426. return nil, fmt.Errorf("schema props %v", err)
  427. }
  428. b2, err := json.Marshal(s.VendorExtensible)
  429. if err != nil {
  430. return nil, fmt.Errorf("vendor props %v", err)
  431. }
  432. b3, err := s.Ref.MarshalJSON()
  433. if err != nil {
  434. return nil, fmt.Errorf("ref prop %v", err)
  435. }
  436. b4, err := s.Schema.MarshalJSON()
  437. if err != nil {
  438. return nil, fmt.Errorf("schema prop %v", err)
  439. }
  440. b5, err := json.Marshal(s.SwaggerSchemaProps)
  441. if err != nil {
  442. return nil, fmt.Errorf("common validations %v", err)
  443. }
  444. var b6 []byte
  445. if s.ExtraProps != nil {
  446. jj, err := json.Marshal(s.ExtraProps)
  447. if err != nil {
  448. return nil, fmt.Errorf("extra props %v", err)
  449. }
  450. b6 = jj
  451. }
  452. return swag.ConcatJSON(b1, b2, b3, b4, b5, b6), nil
  453. }
  454. func (s Schema) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error {
  455. type ArbitraryKeys map[string]interface{}
  456. var x struct {
  457. ArbitraryKeys
  458. SchemaProps schemaPropsOmitZero `json:",inline"`
  459. SwaggerSchemaProps swaggerSchemaPropsOmitZero `json:",inline"`
  460. Schema string `json:"$schema,omitempty"`
  461. Ref string `json:"$ref,omitempty"`
  462. }
  463. x.ArbitraryKeys = make(map[string]any, len(s.Extensions)+len(s.ExtraProps))
  464. for k, v := range s.Extensions {
  465. if internal.IsExtensionKey(k) {
  466. x.ArbitraryKeys[k] = v
  467. }
  468. }
  469. for k, v := range s.ExtraProps {
  470. x.ArbitraryKeys[k] = v
  471. }
  472. x.SchemaProps = schemaPropsOmitZero(s.SchemaProps)
  473. x.SwaggerSchemaProps = swaggerSchemaPropsOmitZero(s.SwaggerSchemaProps)
  474. x.Ref = s.Ref.String()
  475. x.Schema = string(s.Schema)
  476. return opts.MarshalNext(enc, x)
  477. }
  478. // UnmarshalJSON marshal this from JSON
  479. func (s *Schema) UnmarshalJSON(data []byte) error {
  480. if internal.UseOptimizedJSONUnmarshaling {
  481. return jsonv2.Unmarshal(data, s)
  482. }
  483. props := struct {
  484. SchemaProps
  485. SwaggerSchemaProps
  486. }{}
  487. if err := json.Unmarshal(data, &props); err != nil {
  488. return err
  489. }
  490. sch := Schema{
  491. SchemaProps: props.SchemaProps,
  492. SwaggerSchemaProps: props.SwaggerSchemaProps,
  493. }
  494. var d map[string]interface{}
  495. if err := json.Unmarshal(data, &d); err != nil {
  496. return err
  497. }
  498. _ = sch.Ref.fromMap(d)
  499. _ = sch.Schema.fromMap(d)
  500. delete(d, "$ref")
  501. delete(d, "$schema")
  502. for _, pn := range swag.DefaultJSONNameProvider.GetJSONNames(s) {
  503. delete(d, pn)
  504. }
  505. for k, vv := range d {
  506. lk := strings.ToLower(k)
  507. if strings.HasPrefix(lk, "x-") {
  508. if sch.Extensions == nil {
  509. sch.Extensions = map[string]interface{}{}
  510. }
  511. sch.Extensions[k] = vv
  512. continue
  513. }
  514. if sch.ExtraProps == nil {
  515. sch.ExtraProps = map[string]interface{}{}
  516. }
  517. sch.ExtraProps[k] = vv
  518. }
  519. *s = sch
  520. return nil
  521. }
  522. func (s *Schema) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error {
  523. var x struct {
  524. Extensions
  525. SchemaProps
  526. SwaggerSchemaProps
  527. }
  528. if err := opts.UnmarshalNext(dec, &x); err != nil {
  529. return err
  530. }
  531. if err := x.Ref.fromMap(x.Extensions); err != nil {
  532. return err
  533. }
  534. if err := x.Schema.fromMap(x.Extensions); err != nil {
  535. return err
  536. }
  537. delete(x.Extensions, "$ref")
  538. delete(x.Extensions, "$schema")
  539. for _, pn := range swag.DefaultJSONNameProvider.GetJSONNames(s) {
  540. delete(x.Extensions, pn)
  541. }
  542. if len(x.Extensions) == 0 {
  543. x.Extensions = nil
  544. }
  545. s.ExtraProps = x.Extensions.sanitizeWithExtra()
  546. s.Extensions = internal.SanitizeExtensions(x.Extensions)
  547. s.SchemaProps = x.SchemaProps
  548. s.SwaggerSchemaProps = x.SwaggerSchemaProps
  549. return nil
  550. }