Skip to content

Commit c0d7f43

Browse files
udpate unit tests
1 parent d6ca514 commit c0d7f43

File tree

1 file changed

+5
-61
lines changed

1 file changed

+5
-61
lines changed

openapi3/origin_test.go

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ func TestOrigin_XML(t *testing.T) {
383383
base.Origin.Fields["prefix"])
384384
}
385385

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.
388388
func TestOrigin_OriginExistsInProperties(t *testing.T) {
389389
var data = `
390390
paths:
@@ -402,64 +402,7 @@ components:
402402
Foo:
403403
type: object
404404
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__:
463406
type: string
464407
`
465408

@@ -469,6 +412,7 @@ components:
469412
defer unsetIncludeOrigin()
470413

471414
_, err := loader.LoadFromData([]byte(data))
415+
require.Error(t, err)
472416
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())
474418
}

0 commit comments

Comments
 (0)