Skip to content

Commit

Permalink
make form required field order deterministic (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill authored Aug 30, 2024
1 parent 2a0cad9 commit c606b55
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions openapi2conv/issue1008_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package openapi2conv

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIssue1008(t *testing.T) {
v2 := []byte(`
swagger: '2.0'
info:
version: '1.10'
title: title
paths:
"/ping":
post:
consumes:
- multipart/form-data
parameters:
- name: zebra
in: formData
description: stripes
required: true
type: string
- name: alpaca
in: formData
description: chewy
required: true
type: string
- name: bee
in: formData
description: buzz
required: true
type: string
responses:
'200':
description: OK
`)

v3, err := v2v3YAML(v2)
require.NoError(t, err)

err = v3.Validate(context.Background())
require.NoError(t, err)
assert.Equal(t, []string{"alpaca", "bee", "zebra"}, v3.Paths.Value("/ping").Post.RequestBody.Value.Content.Get("multipart/form-data").Schema.Value.Required)
}
1 change: 1 addition & 0 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func formDataBody(bodies map[string]*openapi3.SchemaRef, reqs map[string]bool, c
bodies[s] = ref
}
}
sort.Strings(requireds)
schema := &openapi3.Schema{
Type: &openapi3.Types{"object"},
Properties: ToV3Schemas(bodies),
Expand Down

0 comments on commit c606b55

Please sign in to comment.