diff --git a/datamodel/high/v3/document_test.go b/datamodel/high/v3/document_test.go index fca6eff..43eb027 100644 --- a/datamodel/high/v3/document_test.go +++ b/datamodel/high/v3/document_test.go @@ -56,7 +56,7 @@ func TestNewDocument_Security(t *testing.T) { initTest() h := NewDocument(lowDoc) assert.Len(t, h.Security, 1) - assert.Len(t, h.Security[0].Requirements, 1) + assert.Equal(t, 1, orderedmap.Len(h.Security[0].Requirements)) assert.Len(t, h.Security[0].Requirements.GetOrZero("OAuthScheme"), 2) } @@ -97,13 +97,13 @@ func TestNewDocument_Servers(t *testing.T) { assert.Len(t, h.Servers, 2) assert.Equal(t, "{scheme}://api.pb33f.io", h.Servers[0].URL) assert.Equal(t, "this is our main API server, for all fun API things.", h.Servers[0].Description) - assert.Len(t, h.Servers[0].Variables, 1) + assert.Equal(t, 1, orderedmap.Len(h.Servers[0].Variables)) assert.Equal(t, "https", h.Servers[0].Variables.GetOrZero("scheme").Default) assert.Len(t, h.Servers[0].Variables.GetOrZero("scheme").Enum, 2) assert.Equal(t, "https://{domain}.{host}.com", h.Servers[1].URL) assert.Equal(t, "this is our second API server, for all fun API things.", h.Servers[1].Description) - assert.Len(t, h.Servers[1].Variables, 2) + assert.Equal(t, 2, orderedmap.Len(h.Servers[1].Variables)) assert.Equal(t, "api", h.Servers[1].Variables.GetOrZero("domain").Default) assert.Equal(t, "pb33f.io", h.Servers[1].Variables.GetOrZero("host").Default) @@ -363,7 +363,7 @@ func testBurgerShop(t *testing.T, h *Document, checkLines bool) { ) assert.Equal(t, 2, orderedmap.Len(okResp.Links)) assert.Equal(t, "locateBurger", okResp.Links.GetOrZero("LocateBurger").OperationId) - assert.Len(t, burgersOp.Post.Security[0].Requirements, 1) + assert.Equal(t, 1, orderedmap.Len(burgersOp.Post.Security[0].Requirements)) assert.Len(t, burgersOp.Post.Security[0].Requirements.GetOrZero("OAuthScheme"), 2) assert.Equal(t, "read:burgers", burgersOp.Post.Security[0].Requirements.GetOrZero("OAuthScheme")[0]) assert.Len(t, burgersOp.Post.Servers, 1) diff --git a/datamodel/high/v3/response_test.go b/datamodel/high/v3/response_test.go index 749c6aa..738dc56 100644 --- a/datamodel/high/v3/response_test.go +++ b/datamodel/high/v3/response_test.go @@ -10,6 +10,7 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" ) @@ -42,10 +43,10 @@ links: r := NewResponse(&n) - assert.Len(t, r.Headers, 1) - assert.Len(t, r.Content, 1) + assert.Equal(t, 1, orderedmap.Len(r.Headers)) + assert.Equal(t, 1, orderedmap.Len(r.Content)) assert.Equal(t, "pizza!", r.Extensions["x-pizza-man"]) - assert.Len(t, r.Links, 1) + assert.Equal(t, 1, orderedmap.Len(r.Links)) assert.Equal(t, 1, r.GoLow().Description.KeyNode.Line) } diff --git a/datamodel/low/base/schema_test.go b/datamodel/low/base/schema_test.go index 81b9f1f..12cb132 100644 --- a/datamodel/low/base/schema_test.go +++ b/datamodel/low/base/schema_test.go @@ -5,6 +5,7 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "github.com/pb33f/libopenapi/resolver" "github.com/pb33f/libopenapi/utils" "github.com/stretchr/testify/assert" @@ -72,7 +73,7 @@ anyOf: anyOfB: type: string description: anyOfB description - example: 'anyOfBExp' + example: 'anyOfBExp' not: type: object description: a not thing @@ -84,7 +85,7 @@ not: notB: type: string description: notB description - example: 'notBExp' + example: 'notBExp' items: type: object description: an items thing @@ -134,11 +135,11 @@ properties: attribute: true wrapped: false x-pizza: love - additionalProperties: + additionalProperties: why: yes - thatIs: true + thatIs: true additionalProperties: true -required: +required: - them enum: - one @@ -171,7 +172,7 @@ func Test_Schema(t *testing.T) { assert.Equal(t, "something object", sch.Description.Value) assert.True(t, sch.AdditionalProperties.Value.(bool)) - assert.Len(t, sch.Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sch.Properties.Value)) v := sch.FindProperty("somethingB") assert.Equal(t, "https://pb33f.io", v.Value.Schema().ExternalDocs.Value.URL.Value) @@ -204,7 +205,7 @@ func Test_Schema(t *testing.T) { // check polymorphic values allOf f := sch.AllOf.Value[0].Value.Schema() assert.Equal(t, "an allof thing", f.Description.Value) - assert.Len(t, f.Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(f.Properties.Value)) v = f.FindProperty("allOfA") assert.NotNil(t, v) @@ -221,7 +222,7 @@ func Test_Schema(t *testing.T) { // check polymorphic values anyOf assert.Equal(t, "an anyOf thing", sch.AnyOf.Value[0].Value.Schema().Description.Value) - assert.Len(t, sch.AnyOf.Value[0].Value.Schema().Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sch.AnyOf.Value[0].Value.Schema().Properties.Value)) v = sch.AnyOf.Value[0].Value.Schema().FindProperty("anyOfA") assert.NotNil(t, v) @@ -235,7 +236,7 @@ func Test_Schema(t *testing.T) { // check polymorphic values oneOf assert.Equal(t, "a oneof thing", sch.OneOf.Value[0].Value.Schema().Description.Value) - assert.Len(t, sch.OneOf.Value[0].Value.Schema().Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sch.OneOf.Value[0].Value.Schema().Properties.Value)) v = sch.OneOf.Value[0].Value.Schema().FindProperty("oneOfA") assert.NotNil(t, v) @@ -249,7 +250,7 @@ func Test_Schema(t *testing.T) { // check values NOT assert.Equal(t, "a not thing", sch.Not.Value.Schema().Description.Value) - assert.Len(t, sch.Not.Value.Schema().Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sch.Not.Value.Schema().Properties.Value)) v = sch.Not.Value.Schema().FindProperty("notA") assert.NotNil(t, v) @@ -263,7 +264,7 @@ func Test_Schema(t *testing.T) { // check values Items assert.Equal(t, "an items thing", sch.Items.Value.A.Schema().Description.Value) - assert.Len(t, sch.Items.Value.A.Schema().Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sch.Items.Value.A.Schema().Properties.Value)) v = sch.Items.Value.A.Schema().FindProperty("itemsA") assert.NotNil(t, v) @@ -277,7 +278,7 @@ func Test_Schema(t *testing.T) { // check values PrefixItems assert.Equal(t, "an items thing", sch.PrefixItems.Value[0].Value.Schema().Description.Value) - assert.Len(t, sch.PrefixItems.Value[0].Value.Schema().Properties.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sch.PrefixItems.Value[0].Value.Schema().Properties.Value)) v = sch.PrefixItems.Value[0].Value.Schema().FindProperty("itemsA") assert.NotNil(t, v) @@ -956,7 +957,7 @@ func TestExtractSchema(t *testing.T) { assert.NoError(t, mErr) idx := index.NewSpecIndex(&iNode) - yml = `schema: + yml = `schema: type: object properties: aValue: @@ -974,7 +975,7 @@ func TestExtractSchema(t *testing.T) { func TestExtractSchema_DefaultPrimitive(t *testing.T) { yml := ` -schema: +schema: type: object default: 5` @@ -990,7 +991,7 @@ schema: func TestExtractSchema_ConstPrimitive(t *testing.T) { yml := ` -schema: +schema: type: object const: 5` @@ -1016,7 +1017,7 @@ func TestExtractSchema_Ref(t *testing.T) { assert.NoError(t, mErr) idx := index.NewSpecIndex(&iNode) - yml = `schema: + yml = `schema: $ref: '#/components/schemas/Something'` var idxNode yaml.Node @@ -1040,7 +1041,7 @@ func TestExtractSchema_Ref_Fail(t *testing.T) { assert.NoError(t, mErr) idx := index.NewSpecIndex(&iNode) - yml = `schema: + yml = `schema: $ref: '#/components/schemas/Missing'` var idxNode yaml.Node @@ -1061,7 +1062,7 @@ func TestExtractSchema_CheckChildPropCircular(t *testing.T) { - nothing Nothing: properties: - something: + something: $ref: '#/components/schemas/Something' required: - something diff --git a/datamodel/low/base/security_requirement_test.go b/datamodel/low/base/security_requirement_test.go index 05bee6e..396ab4f 100644 --- a/datamodel/low/base/security_requirement_test.go +++ b/datamodel/low/base/security_requirement_test.go @@ -4,9 +4,11 @@ package base import ( + "testing" + + "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" - "testing" ) func TestSecurityRequirement_Build(t *testing.T) { @@ -14,7 +16,7 @@ func TestSecurityRequirement_Build(t *testing.T) { yml := `one: - two - three -four: +four: - five - six` @@ -22,7 +24,7 @@ four: var idxNode yaml.Node _ = yaml.Unmarshal([]byte(yml), &idxNode) - yml2 := `four: + yml2 := `four: - six - five one: @@ -36,7 +38,7 @@ one: _ = sr.Build(nil, idxNode.Content[0], nil) _ = sr2.Build(nil, idxNode2.Content[0], nil) - assert.Len(t, sr.Requirements.Value, 2) + assert.Equal(t, 2, orderedmap.Len(sr.Requirements.Value)) assert.Len(t, sr.GetKeys(), 2) assert.Len(t, sr.FindRequirement("one"), 2) assert.Equal(t, sr.Hash(), sr2.Hash()) diff --git a/datamodel/low/v2/operation_test.go b/datamodel/low/v2/operation_test.go index f658358..8fedf0d 100644 --- a/datamodel/low/v2/operation_test.go +++ b/datamodel/low/v2/operation_test.go @@ -4,12 +4,14 @@ package v2 import ( + "testing" + "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" - "testing" ) func TestOperation_Build_ExternalDocs(t *testing.T) { @@ -180,7 +182,7 @@ security: assert.Equal(t, "theMagicCastle", n.GetOperationId().Value) assert.Len(t, n.GetParameters().Value, 1) assert.True(t, n.GetDeprecated().Value) - assert.Len(t, n.GetResponses().Value.(*Responses).Codes, 1) + assert.Equal(t, 1, orderedmap.Len(n.GetResponses().Value.(*Responses).Codes)) assert.Len(t, n.GetSecurity().Value, 1) assert.Len(t, n.GetExtensions(), 1) } diff --git a/datamodel/low/v2/security_scheme_test.go b/datamodel/low/v2/security_scheme_test.go index 81b0551..17907f0 100644 --- a/datamodel/low/v2/security_scheme_test.go +++ b/datamodel/low/v2/security_scheme_test.go @@ -4,11 +4,13 @@ package v2 import ( + "testing" + "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" - "testing" ) func TestSecurityScheme_Build_Borked(t *testing.T) { @@ -47,7 +49,7 @@ func TestSecurityScheme_Build_Scopes(t *testing.T) { err = n.Build(nil, idxNode.Content[0], idx) assert.NoError(t, err) - assert.Len(t, n.Scopes.Value.Values, 2) + assert.Equal(t, 2, orderedmap.Len(n.Scopes.Value.Values)) } diff --git a/datamodel/low/v2/swagger_test.go b/datamodel/low/v2/swagger_test.go index c099194..1ce4215 100644 --- a/datamodel/low/v2/swagger_test.go +++ b/datamodel/low/v2/swagger_test.go @@ -5,10 +5,12 @@ package v2 import ( "fmt" - "github.com/pb33f/libopenapi/datamodel" - "github.com/stretchr/testify/assert" "io/ioutil" "testing" + + "github.com/pb33f/libopenapi/datamodel" + "github.com/pb33f/libopenapi/orderedmap" + "github.com/stretchr/testify/assert" ) var doc *Swagger @@ -55,13 +57,13 @@ func TestCreateDocument(t *testing.T) { assert.Equal(t, "1.0.6", doc.Info.Value.Version.Value) assert.Equal(t, "petstore.swagger.io", doc.Host.Value) assert.Equal(t, "/v2", doc.BasePath.Value) - assert.Len(t, doc.Parameters.Value.Definitions, 1) + assert.Equal(t, 1, orderedmap.Len(doc.Parameters.Value.Definitions)) assert.Len(t, doc.Tags.Value, 3) assert.Len(t, doc.Schemes.Value, 2) - assert.Len(t, doc.Definitions.Value.Schemas, 6) - assert.Len(t, doc.SecurityDefinitions.Value.Definitions, 3) - assert.Len(t, doc.Paths.Value.PathItems, 15) - assert.Len(t, doc.Responses.Value.Definitions, 2) + assert.Equal(t, 6, orderedmap.Len(doc.Definitions.Value.Schemas)) + assert.Equal(t, 3, orderedmap.Len(doc.SecurityDefinitions.Value.Definitions)) + assert.Equal(t, 15, orderedmap.Len(doc.Paths.Value.PathItems)) + assert.Equal(t, 2, orderedmap.Len(doc.Responses.Value.Definitions)) assert.Equal(t, "http://swagger.io", doc.ExternalDocs.Value.URL.Value) assert.Equal(t, true, doc.FindExtension("x-pet").Value) assert.Equal(t, true, doc.FindExtension("X-Pet").Value) @@ -101,7 +103,7 @@ func TestCreateDocument_SecurityDefinitions(t *testing.T) { petStoreAuth := doc.SecurityDefinitions.Value.FindSecurityDefinition("petstore_auth") assert.Equal(t, "oauth2", petStoreAuth.Value.Type.Value) assert.Equal(t, "implicit", petStoreAuth.Value.Flow.Value) - assert.Len(t, petStoreAuth.Value.Scopes.Value.Values, 2) + assert.Equal(t, 2, orderedmap.Len(petStoreAuth.Value.Scopes.Value.Values)) assert.Equal(t, "read your pets", petStoreAuth.Value.Scopes.Value.FindScope("read:pets").Value) } @@ -109,7 +111,7 @@ func TestCreateDocument_Definitions(t *testing.T) { initTest() apiResp := doc.Definitions.Value.FindSchema("ApiResponse").Value.Schema() assert.NotNil(t, apiResp) - assert.Len(t, apiResp.Properties.Value, 3) + assert.Equal(t, 3, orderedmap.Len(apiResp.Properties.Value)) assert.Equal(t, "integer", apiResp.FindProperty("code").Value.Schema().Type.Value.A) pet := doc.Definitions.Value.FindSchema("Pet").Value.Schema() diff --git a/datamodel/low/v3/callback_test.go b/datamodel/low/v3/callback_test.go index c98389e..c2c0058 100644 --- a/datamodel/low/v3/callback_test.go +++ b/datamodel/low/v3/callback_test.go @@ -4,11 +4,13 @@ package v3 import ( + "testing" + "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" - "testing" ) func TestCallback_Build_Success(t *testing.T) { @@ -17,7 +19,7 @@ func TestCallback_Build_Success(t *testing.T) { post: requestBody: description: Callback payload - content: + content: 'application/json': schema: type: string @@ -36,7 +38,7 @@ func TestCallback_Build_Success(t *testing.T) { err = n.Build(nil, rootNode.Content[0], nil) assert.NoError(t, err) - assert.Len(t, n.Expression.Value, 1) + assert.Equal(t, 1, orderedmap.Len(n.Expression.Value)) } @@ -102,7 +104,7 @@ func TestCallback_Build_Using_InlineRef(t *testing.T) { err = n.Build(nil, rootNode.Content[0], idx) assert.NoError(t, err) - assert.Len(t, n.Expression.Value, 1) + assert.Equal(t, 1, orderedmap.Len(n.Expression.Value)) exp := n.FindExpression("{$request.query.queryUrl}") assert.NotNil(t, exp.Value) diff --git a/datamodel/low/v3/create_document_test.go b/datamodel/low/v3/create_document_test.go index 9174d16..9ed27d6 100644 --- a/datamodel/low/v3/create_document_test.go +++ b/datamodel/low/v3/create_document_test.go @@ -225,7 +225,7 @@ func TestCreateDocument_Info(t *testing.T) { func TestCreateDocument_WebHooks(t *testing.T) { initTest() - assert.Len(t, doc.Webhooks.Value, 1) + assert.Equal(t, 1, orderedmap.Len(doc.Webhooks.Value)) for pair := orderedmap.First(doc.Webhooks.Value); pair != nil; pair = pair.Next() { // a nice deep model should be available for us. assert.Equal(t, "Information about a new burger", @@ -255,7 +255,7 @@ func TestCreateDocument_Servers(t *testing.T) { // server 1 assert.Equal(t, "{scheme}://api.pb33f.io", server1.URL.Value) assert.NotEmpty(t, server1.Description.Value) - assert.Len(t, server1.Variables.Value, 1) + assert.Equal(t, 1, orderedmap.Len(server1.Variables.Value)) assert.Len(t, server1.FindVariable("scheme").Value.Enum, 2) assert.Equal(t, server1.FindVariable("scheme").Value.Default.Value, "https") assert.NotEmpty(t, server1.FindVariable("scheme").Value.Description.Value) @@ -263,7 +263,7 @@ func TestCreateDocument_Servers(t *testing.T) { // server 2 assert.Equal(t, "https://{domain}.{host}.com", server2.URL.Value) assert.NotEmpty(t, server2.Description.Value) - assert.Len(t, server2.Variables.Value, 2) + assert.Equal(t, 2, orderedmap.Len(server2.Variables.Value)) assert.Equal(t, "api", server2.FindVariable("domain").Value.Default.Value) assert.NotEmpty(t, server2.FindVariable("domain").Value.Description.Value) assert.NotEmpty(t, server2.FindVariable("host").Value.Description.Value) @@ -319,7 +319,7 @@ func TestCreateDocument_Tags(t *testing.T) { func TestCreateDocument_Paths(t *testing.T) { initTest() - assert.Len(t, doc.Paths.Value.PathItems, 5) + assert.Equal(t, 5, orderedmap.Len(doc.Paths.Value.PathItems)) burgerId := doc.Paths.Value.FindPath("/burgers/{burgerId}") assert.NotNil(t, burgerId) assert.Len(t, burgerId.Value.Get.Value.Parameters.Value, 2) @@ -335,7 +335,7 @@ func TestCreateDocument_Paths(t *testing.T) { encoding := pContent.Value.FindPropertyEncoding("burgerTheme") assert.NotNil(t, encoding.Value) - assert.Len(t, encoding.Value.Headers.Value, 1) + assert.Equal(t, 1, orderedmap.Len(encoding.Value.Headers.Value)) header := encoding.Value.FindHeader("someHeader") assert.NotNil(t, header.Value) @@ -357,8 +357,8 @@ func TestCreateDocument_Paths(t *testing.T) { content := requestBody.FindContent("application/json").Value assert.NotNil(t, content) - assert.Len(t, content.Schema.Value.Schema().Properties.Value, 4) - assert.Len(t, content.GetAllExamples(), 2) + assert.Equal(t, 4, orderedmap.Len(content.Schema.Value.Schema().Properties.Value)) + assert.Equal(t, 2, orderedmap.Len(content.GetAllExamples())) ex := content.FindExample("pbjBurger") assert.NotNil(t, ex.Value) @@ -388,14 +388,14 @@ func TestCreateDocument_Paths(t *testing.T) { // check responses responses := burgersPost.Responses.Value assert.NotNil(t, responses) - assert.Len(t, responses.Codes, 3) + assert.Equal(t, 3, orderedmap.Len(responses.Codes)) okCode := responses.FindResponseByCode("200") assert.NotNil(t, okCode.Value) assert.Equal(t, "A tasty burger for you to eat.", okCode.Value.Description.Value) // check headers are populated - assert.Len(t, okCode.Value.Headers.Value, 1) + assert.Equal(t, 1, orderedmap.Len(okCode.Value.Headers.Value)) okheader := okCode.Value.FindHeader("UseOil") assert.NotNil(t, okheader.Value) assert.Equal(t, "this is a header example for UseOil", okheader.Value.Description.Value) @@ -421,7 +421,7 @@ func TestCreateDocument_Paths(t *testing.T) { // check links links := okCode.Value.Links assert.NotNil(t, links.Value) - assert.Len(t, links.Value, 2) + assert.Equal(t, 2, orderedmap.Len(links.Value)) assert.Equal(t, "locateBurger", okCode.Value.FindLink("LocateBurger").Value.OperationId.Value) locateBurger := okCode.Value.FindLink("LocateBurger").Value diff --git a/renderer/mock_generator.go b/renderer/mock_generator.go index 5ab7994..db3e705 100644 --- a/renderer/mock_generator.go +++ b/renderer/mock_generator.go @@ -6,9 +6,11 @@ package renderer import ( "encoding/json" "fmt" - highbase "github.com/pb33f/libopenapi/datamodel/high/base" - "gopkg.in/yaml.v3" "reflect" + + highbase "github.com/pb33f/libopenapi/datamodel/high/base" + "github.com/pb33f/libopenapi/orderedmap" + "gopkg.in/yaml.v3" ) const Example = "Example" @@ -25,7 +27,7 @@ const ( // MockGenerator is used to generate mocks for high-level mockable structs or *base.Schema pointers. // The mock generator will attempt to generate a mock from a struct using the following fields: // - Example: any type, this is the default example to use if no examples are present. -// - Examples: map[string]*base.Example, this is a map of examples keyed by name. +// - Examples: orderedmap.Map[string, *base.Example], this is a map of examples keyed by name. // - Schema: *base.SchemaProxy, this is the schema to use if no examples are present. // // The mock generator will attempt to generate a mock from a *base.Schema pointer. @@ -59,7 +61,7 @@ func (mg *MockGenerator) SetPretty() { // GenerateMock generates a mock for a given high-level mockable struct. The mockable struct must contain the following fields: // Example: any type, this is the default example to use if no examples are present. -// Examples: map[string]*base.Example, this is a map of examples keyed by name. +// Examples: orderedmap.Map[string, *base.Example], this is a map of examples keyed by name. // Schema: *base.SchemaProxy, this is the schema to use if no examples are present. // The name parameter is optional, if provided, the mock generator will attempt to find an example with the given name. // If no name is provided, the first example will be used. @@ -98,18 +100,20 @@ func (mg *MockGenerator) GenerateMock(mock any, name string) ([]byte, error) { examplesValue := examples.Interface() if examplesValue != nil && !examples.IsNil() { - // cast examples to map[string]interface{} - examplesMap := examplesValue.(map[string]*highbase.Example) + // cast examples to orderedmap.Map[string, any] + examplesMap := examplesValue.(orderedmap.Map[string, *highbase.Example]) // if the name is not empty, try and find the example by name - for k, exp := range examplesMap { + for pair := orderedmap.First(examplesMap); pair != nil; pair = pair.Next() { + k, exp := pair.Key(), pair.Value() if k == name { return mg.renderMock(exp.Value), nil } } // if the name is empty, just return the first example - for _, exp := range examplesMap { + for pair := orderedmap.First(examplesMap); pair != nil; pair = pair.Next() { + exp := pair.Value() return mg.renderMock(exp.Value), nil } }