|
1 | 1 | package parser_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "mokapi/js/mokapi" |
4 | 5 | "mokapi/schema/json/parser" |
5 | 6 | "mokapi/schema/json/schema" |
6 | 7 | "mokapi/schema/json/schema/schematest" |
7 | 8 | "mokapi/sortedmap" |
8 | 9 | "testing" |
9 | 10 |
|
| 11 | + "github.com/dop251/goja" |
10 | 12 | "github.com/stretchr/testify/require" |
11 | 13 | ) |
12 | 14 |
|
@@ -459,6 +461,61 @@ func TestParser_ParseObject(t *testing.T) { |
459 | 461 | require.Equal(t, map[string]interface{}{"foo": "bar", "bar": "abc"}, v) |
460 | 462 | }, |
461 | 463 | }, |
| 464 | + /*{ |
| 465 | + name: "unevaluatedProperties", |
| 466 | + schema: schematest.NewTypes(nil, |
| 467 | + schematest.WithAllOf( |
| 468 | + schematest.New("object", |
| 469 | + schematest.WithAllOf(schematest.New("object", |
| 470 | + schematest.WithProperty("city", schematest.New("string")), |
| 471 | + )), |
| 472 | + ), |
| 473 | + ), |
| 474 | + schematest.WithProperty("type", schematest.NewTypes(nil, schematest.WithEnumValues("residential", "business"))), |
| 475 | + schematest.WithRequired("type"), |
| 476 | + schematest.WithUnevaluatedProperties(schematest.NewBool(false)), |
| 477 | + ), |
| 478 | + data: map[string]any{"type": "residential", "city": "Washington"}, |
| 479 | + test: func(t *testing.T, v interface{}, err error) { |
| 480 | + require.NoError(t, err) |
| 481 | + }, |
| 482 | + },*/ |
| 483 | + { |
| 484 | + name: "parse from JavaScript shared value", |
| 485 | + schema: schematest.NewTypes(nil, |
| 486 | + schematest.WithProperty("type", schematest.NewTypes(nil, schematest.WithEnumValues("residential", "business"))), |
| 487 | + schematest.WithRequired("type"), |
| 488 | + ), |
| 489 | + data: func() any { |
| 490 | + vm := goja.New() |
| 491 | + v := vm.ToValue(map[string]any{"type": "residential"}) |
| 492 | + return mokapi.NewSharedValue(v, vm) |
| 493 | + }(), |
| 494 | + test: func(t *testing.T, v interface{}, err error) { |
| 495 | + require.NoError(t, err) |
| 496 | + require.Equal(t, map[string]interface{}{"type": "residential"}, v) |
| 497 | + }, |
| 498 | + }, |
| 499 | + { |
| 500 | + name: "parse struct with private fields", |
| 501 | + schema: schematest.NewTypes(nil, |
| 502 | + schematest.WithProperty("bar", schematest.New("string")), |
| 503 | + schematest.WithRequired("bar"), |
| 504 | + ), |
| 505 | + data: func() any { |
| 506 | + return &struct { |
| 507 | + foo string |
| 508 | + Bar string |
| 509 | + }{ |
| 510 | + foo: "bar", |
| 511 | + Bar: "abc", |
| 512 | + } |
| 513 | + }(), |
| 514 | + test: func(t *testing.T, v interface{}, err error) { |
| 515 | + require.NoError(t, err) |
| 516 | + require.Equal(t, map[string]interface{}{"bar": "abc"}, v) |
| 517 | + }, |
| 518 | + }, |
462 | 519 | } |
463 | 520 |
|
464 | 521 | t.Parallel() |
|
0 commit comments