From d47633dbade53c2e216f68392b7c65589f57f925 Mon Sep 17 00:00:00 2001 From: Mateusz Bilski Date: Thu, 20 Oct 2022 10:28:49 +0200 Subject: [PATCH] Revert object --- codescan/application_test.go | 4 +--- codescan/parser.go | 2 -- codescan/schema.go | 6 +----- codescan/schema_test.go | 17 +---------------- .../goparsing/classification/models/nomodel.go | 10 +--------- 5 files changed, 4 insertions(+), 35 deletions(-) diff --git a/codescan/application_test.go b/codescan/application_test.go index fccc6e238..1b17869bf 100644 --- a/codescan/application_test.go +++ b/codescan/application_test.go @@ -5,9 +5,7 @@ import ( "testing" "github.com/go-openapi/spec" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) @@ -47,7 +45,7 @@ func loadClassificationPkgsCtx(t testing.TB, extra ...string) *scanCtx { func TestApplication_LoadCode(t *testing.T) { sctx := loadClassificationPkgsCtx(t) require.NotNil(t, sctx) - require.Len(t, sctx.app.Models, 32) + require.Len(t, sctx.app.Models, 31) require.Len(t, sctx.app.Meta, 1) require.Len(t, sctx.app.Routes, 7) require.Empty(t, sctx.app.Operations) diff --git a/codescan/parser.go b/codescan/parser.go index 3733d50df..e0a794a55 100644 --- a/codescan/parser.go +++ b/codescan/parser.go @@ -251,8 +251,6 @@ func swaggerSchemaForType(typeName string, prop swaggerTypable) error { prop.Typed("integer", "uint8") case "uintptr": prop.Typed("integer", "uint64") - case "object": - prop.Typed("object", "") default: return fmt.Errorf("unsupported type %q", typeName) } diff --git a/codescan/schema.go b/codescan/schema.go index dce74fc30..f4853d1a4 100644 --- a/codescan/schema.go +++ b/codescan/schema.go @@ -354,11 +354,6 @@ func (s *schemaBuilder) buildFromType(tpe types.Type, tgt swaggerTypable) error cmt = new(ast.CommentGroup) } - if typeName, ok := typeName(cmt); ok { - _ = swaggerSchemaForType(typeName, tgt) - return nil - } - if s.decl.Spec.Assign.IsValid() { return s.buildFromType(titpe.Underlying(), tgt) } @@ -476,6 +471,7 @@ func (s *schemaBuilder) buildFromType(tpe types.Type, tgt swaggerTypable) error func (s *schemaBuilder) buildFromInterface(decl *entityDecl, it *types.Interface, schema *spec.Schema, seen map[string]string) error { if it.Empty() { + schema.Typed("object", "") return nil } diff --git a/codescan/schema_test.go b/codescan/schema_test.go index 239d9d219..aa7deadc2 100644 --- a/codescan/schema_test.go +++ b/codescan/schema_test.go @@ -670,7 +670,7 @@ func TestInterfaceField(t *testing.T) { require.NoError(t, prs.Build(models)) schema := models["Interfaced"] - assertProperty(t, &schema, "", "custom_data", "", "CustomData") + assertProperty(t, &schema, "object", "custom_data", "", "CustomData") } func TestAliasedTypes(t *testing.T) { @@ -833,21 +833,6 @@ func TestEmbeddedAllOf(t *testing.T) { assertProperty(t, &asch, "string", "cat", "", "Cat") } -func TestSwaggerTypeNamed(t *testing.T) { - sctx := loadClassificationPkgsCtx(t) - decl := getClassificationModel(sctx, "NamedWithType") - require.NotNil(t, decl) - prs := &schemaBuilder{ - ctx: sctx, - decl: decl, - } - models := make(map[string]spec.Schema) - require.NoError(t, prs.Build(models)) - schema := models["namedWithType"] - - assertProperty(t, &schema, "object", "some_map", "", "SomeMap") -} - func TestSwaggerTypeStruct(t *testing.T) { sctx := loadClassificationPkgsCtx(t) decl := getClassificationModel(sctx, "NullString") diff --git a/fixtures/goparsing/classification/models/nomodel.go b/fixtures/goparsing/classification/models/nomodel.go index d06380a3f..4e5bd78e4 100644 --- a/fixtures/goparsing/classification/models/nomodel.go +++ b/fixtures/goparsing/classification/models/nomodel.go @@ -18,8 +18,8 @@ import ( "net/url" "time" - "github.com/go-openapi/strfmt" "github.com/cloudentity/go-swagger/fixtures/goparsing/classification/transitive/mods" + "github.com/go-openapi/strfmt" ) // NoModel is a struct without an annotation. @@ -753,11 +753,3 @@ type TextMarshalModel struct { StructStrfmtPtr *MarshalTextStructStrfmtPtr `json:"structStrfmtPtr"` CustomURL URL `json:"customUrl"` } - -// swagger:type object -type SomeObjectMap interface{} - -// swagger:model namedWithType -type NamedWithType struct { - SomeMap SomeObjectMap `json:"some_map"` -}