|
1 | 1 | package openapi3 |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | 4 | "fmt" |
6 | 5 | "net" |
7 | 6 | "net/http" |
@@ -524,23 +523,27 @@ paths: {} |
524 | 523 | servers: |
525 | 524 | - @@@ |
526 | 525 | ` |
527 | | - for value, expected := range map[string]error{ |
528 | | - `{url: /}`: nil, |
529 | | - `{url: "http://{x}.{y}.example.com"}`: errors.New("invalid servers: server has undeclared variables"), |
530 | | - `{url: "http://{x}.y}.example.com"}`: errors.New("invalid servers: server URL has mismatched { and }"), |
531 | | - `{url: "http://{x.example.com"}`: errors.New("invalid servers: server URL has mismatched { and }"), |
532 | | - `{url: "http://{x}.example.com", variables: {x: {default: "www"}}}`: nil, |
533 | | - `{url: "http://{x}.example.com", variables: {x: {default: "www", enum: ["www"]}}}`: nil, |
534 | | - `{url: "http://{x}.example.com", variables: {x: {enum: ["www"]}}}`: errors.New(`invalid servers: field default is required in {"enum":["www"]}`), |
535 | | - `{url: "http://www.example.com", variables: {x: {enum: ["www"]}}}`: errors.New("invalid servers: server has undeclared variables"), |
536 | | - `{url: "http://{y}.example.com", variables: {x: {enum: ["www"]}}}`: errors.New("invalid servers: server has undeclared variables"), |
| 526 | + for value, expected := range map[string]string{ |
| 527 | + `{url: /}`: "", |
| 528 | + `{url: "http://{x}.{y}.example.com"}`: "invalid servers: server has undeclared variables", |
| 529 | + `{url: "http://{x}.y}.example.com"}`: "invalid servers: server URL has mismatched { and }", |
| 530 | + `{url: "http://{x.example.com"}`: "invalid servers: server URL has mismatched { and }", |
| 531 | + `{url: "http://{x}.example.com", variables: {x: {default: "www"}}}`: "", |
| 532 | + `{url: "http://{x}.example.com", variables: {x: {default: "www", enum: ["www"]}}}`: "", |
| 533 | + `{url: "http://{x}.example.com", variables: {x: {enum: ["www"]}}}`: `invalid servers: field default is required in {"enum":["www"]}`, |
| 534 | + `{url: "http://www.example.com", variables: {x: {enum: ["www"]}}}`: "invalid servers: server has undeclared variables", |
| 535 | + `{url: "http://{y}.example.com", variables: {x: {enum: ["www"]}}}`: "invalid servers: server has undeclared variables", |
537 | 536 | } { |
538 | 537 | t.Run(value, func(t *testing.T) { |
539 | 538 | loader := NewLoader() |
540 | 539 | doc, err := loader.LoadFromData([]byte(strings.Replace(spec, "@@@", value, 1))) |
541 | 540 | require.NoError(t, err) |
542 | 541 | err = doc.Validate(loader.Context) |
543 | | - require.Equal(t, expected, err) |
| 542 | + if expected == "" { |
| 543 | + require.NoError(t, err) |
| 544 | + } else { |
| 545 | + require.EqualError(t, err, expected) |
| 546 | + } |
544 | 547 | }) |
545 | 548 | } |
546 | 549 | } |
0 commit comments