-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscriminator.go
40 lines (37 loc) · 1.16 KB
/
discriminator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package chioas
import (
"errors"
"github.com/go-andiamo/chioas/yaml"
)
// Discriminator is a representation of the OAS discriminator object
type Discriminator struct {
// PropertyName is the OAS property name for the discriminator
PropertyName string
// Mapping holds mappings between payload values (of the specified property) and schema names or references
Mapping map[string]string
// Extensions is extension OAS yaml properties
Extensions Extensions
// Additional is any additional OAS spec yaml to be written
Additional Additional
// Comment is any comment(s) to appear in the OAS spec yaml
Comment string
}
func (d *Discriminator) writeYaml(w yaml.Writer) {
if d.PropertyName == "" {
w.SetError(errors.New("discriminator without property name"))
return
}
w.WriteTagStart(tagNameDiscriminator).
WriteComments(d.Comment).
WriteTagValue(tagNamePropertyName, d.PropertyName)
if d.Mapping != nil && len(d.Mapping) > 0 {
w.WriteTagStart(tagNameMapping)
for k, v := range d.Mapping {
w.WriteTagValue(k, refCheck(tagNameSchemas, v, w))
}
w.WriteTagEnd()
}
writeExtensions(d.Extensions, w)
writeAdditional(d.Additional, d, w)
w.WriteTagEnd()
}