File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ package modify
2+
3+ import (
4+ "regexp"
5+
6+ "github.com/grokify/simplego/type/stringsutil"
7+
8+ oas3 "github.com/getkin/kin-openapi/openapi3"
9+ )
10+
11+ var rxOptionalDefault = regexp .MustCompile (`(?i)\boptional\b` )
12+
13+ func SpecSetSchemaPropertiesOptional (spec * oas3.Swagger , rxOptional * regexp.Regexp ) {
14+ if rxOptional == nil {
15+ return
16+ }
17+ for _ , schemaRef := range spec .Components .Schemas {
18+ if len (schemaRef .Ref ) == 0 && schemaRef .Value != nil {
19+ required := []string {}
20+ for propName , propRef := range schemaRef .Value .Properties {
21+ if len (propRef .Ref ) == 0 && propRef .Value != nil {
22+ if len (propRef .Value .Description ) > 0 &&
23+ ! rxOptional .MatchString (propRef .Value .Description ) {
24+ required = append (required , propName )
25+ }
26+ }
27+ }
28+ if len (required ) > 1 {
29+ required = stringsutil .SliceCondenseSpace (required , true , true )
30+ }
31+ schemaRef .Value .Required = required
32+ }
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments