MCPcopy Create free account
hub / github.com/goadesign/goa / validateAdditionalPropsSchema

Function validateAdditionalPropsSchema

http/codegen/openapi/v3/types_test.go:419–456  ·  view source on GitHub ↗
(t *testing.T, ctx string, schema *openapi.Schema, types map[string]*openapi.Schema, expected *additionalPropsType, prefix string)

Source from the content-addressed store, hash-verified

417}
418
419func validateAdditionalPropsSchema(t *testing.T, ctx string, schema *openapi.Schema, types map[string]*openapi.Schema, expected *additionalPropsType, prefix string) {
420 // Handle reference case
421 if expected.Ref != "" {
422 if schema.Ref == "" {
423 t.Errorf("%s: %sexpected reference to %s, but got inline schema", ctx, prefix, expected.Ref)
424 return
425 }
426 if schema.Ref != expected.Ref {
427 t.Errorf("%s: %sexpected reference %s, got %s", ctx, prefix, expected.Ref, schema.Ref)
428 }
429 return
430 }
431
432 // Resolve reference if present
433 if schema.Ref != "" {
434 typeName := nameFromRef(schema.Ref)
435 resolvedSchema, ok := types[typeName]
436 if !ok {
437 t.Errorf("%s: %scould not resolve reference %s", ctx, prefix, schema.Ref)
438 return
439 }
440 schema = resolvedSchema
441 }
442
443 // Check type
444 if string(schema.Type) != expected.Type {
445 t.Errorf("%s: %sexpected type %s, got %s", ctx, prefix, expected.Type, schema.Type)
446 }
447
448 // Check array items if expected
449 if expected.Items != nil {
450 if schema.Items == nil {
451 t.Errorf("%s: %sexpected array items to be set", ctx, prefix)
452 } else {
453 validateAdditionalPropsSchema(t, ctx, schema.Items, types, expected.Items, prefix+"items: ")
454 }
455 }
456}
457
458func TestTypesOnlyDifferByEnum(t *testing.T) {
459 root := codegen.RunDSL(t, dsls.StringEnumBodyDSL())

Callers 1

Calls 1

nameFromRefFunction · 0.85

Tested by

no test coverage detected