@@ -383,8 +383,8 @@ func TestOrigin_XML(t *testing.T) {
383
383
base .Origin .Fields ["prefix" ])
384
384
}
385
385
386
- // TestOrigin_OriginExistsInProperties verifies that we don't remove pre-existing "origin" fields.
387
- // See https://github.com/getkin/kin-openapi/issues/1051
386
+ // TestOrigin_OriginExistsInProperties verifies that loading fails when a specification
387
+ // contains a property named "__origin__", highlighting a limitation in the current implementation.
388
388
func TestOrigin_OriginExistsInProperties (t * testing.T ) {
389
389
var data = `
390
390
paths:
@@ -402,64 +402,7 @@ components:
402
402
Foo:
403
403
type: object
404
404
properties:
405
- origin:
406
- type: string
407
- `
408
-
409
- loader := NewLoader ()
410
- doc , err := loader .LoadFromData ([]byte (data ))
411
- require .NoError (t , err )
412
-
413
- require .NotEmpty (t , doc .Paths .Find ("/foo" ).Get .Responses .Status (200 ).Value .Content .Get ("application/json" ).Schema .Value .Properties ["origin" ])
414
- }
415
-
416
- // TestOrigin_OriginExistsInContent verifies that we don't remove pre-existing "origin" fields.
417
- // See https://github.com/getkin/kin-openapi/issues/1051
418
- func TestOrigin_OriginExistsInContent (t * testing.T ) {
419
- var data = `
420
- paths:
421
- /foo:
422
- get:
423
- responses:
424
- "200":
425
- description: OK
426
- content:
427
- origin:
428
- schema:
429
- $ref: "#/components/schemas/Foo"
430
- components:
431
- schemas:
432
- Foo:
433
- type: string
434
- `
435
-
436
- loader := NewLoader ()
437
- doc , err := loader .LoadFromData ([]byte (data ))
438
- require .NoError (t , err )
439
-
440
- require .NotEmpty (t , doc .Paths .Find ("/foo" ).Get .Responses .Status (200 ).Value .Content .Get ("origin" ))
441
- }
442
-
443
- // TestOrigin_OriginExistsInPropertiesWithIncludeOrigin demonstrates a limitation in the current implementation:
444
- // Include origin doesn't work if properties (or any other map) contains a key named "origin".
445
- func TestOrigin_OriginExistsInPropertiesWithIncludeOrigin (t * testing.T ) {
446
- var data = `
447
- paths:
448
- /foo:
449
- get:
450
- responses:
451
- "200":
452
- description: OK
453
- content:
454
- application/json:
455
- schema:
456
- $ref: "#/components/schemas/Foo"
457
- components:
458
- schemas:
459
- Foo:
460
- type: object
461
- properties:
462
- origin:
405
+ __origin__:
463
406
type: string
464
407
`
465
408
@@ -469,6 +412,7 @@ components:
469
412
defer unsetIncludeOrigin ()
470
413
471
414
_ , err := loader .LoadFromData ([]byte (data ))
415
+ require .Error (t , err )
472
416
require .Equal (t , `failed to unmarshal data: json error: invalid character 'p' looking for beginning of value, yaml error: error converting YAML to JSON: yaml: unmarshal errors:
473
- line 0: mapping key "origin " already defined at line 17` , err .Error ())
417
+ line 0: mapping key "__origin__ " already defined at line 17` , err .Error ())
474
418
}
0 commit comments