Skip to content

Commit c606b55

Browse files
authored
make form required field order deterministic (#1008)
1 parent 2a0cad9 commit c606b55

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

openapi2conv/issue1008_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package openapi2conv
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestIssue1008(t *testing.T) {
12+
v2 := []byte(`
13+
swagger: '2.0'
14+
info:
15+
version: '1.10'
16+
title: title
17+
paths:
18+
"/ping":
19+
post:
20+
consumes:
21+
- multipart/form-data
22+
parameters:
23+
- name: zebra
24+
in: formData
25+
description: stripes
26+
required: true
27+
type: string
28+
- name: alpaca
29+
in: formData
30+
description: chewy
31+
required: true
32+
type: string
33+
- name: bee
34+
in: formData
35+
description: buzz
36+
required: true
37+
type: string
38+
responses:
39+
'200':
40+
description: OK
41+
`)
42+
43+
v3, err := v2v3YAML(v2)
44+
require.NoError(t, err)
45+
46+
err = v3.Validate(context.Background())
47+
require.NoError(t, err)
48+
assert.Equal(t, []string{"alpaca", "bee", "zebra"}, v3.Paths.Value("/ping").Post.RequestBody.Value.Content.Get("multipart/form-data").Schema.Value.Required)
49+
}

openapi2conv/openapi2_conv.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ func formDataBody(bodies map[string]*openapi3.SchemaRef, reqs map[string]bool, c
346346
bodies[s] = ref
347347
}
348348
}
349+
sort.Strings(requireds)
349350
schema := &openapi3.Schema{
350351
Type: &openapi3.Types{"object"},
351352
Properties: ToV3Schemas(bodies),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy