Skip to content

Commit 0004a83

Browse files
authored
Merge pull request #10 from TykTechnologies/feat/TT-16408/add-full-exclusiveMaximum-and-exclusiveMinimum-support
[TT-16408] add full exclusive maximum and exclusive minimum support
2 parents cca3537 + ea2bc6a commit 0004a83

File tree

5 files changed

+1010
-76
lines changed

5 files changed

+1010
-76
lines changed

openapi2conv/openapi2_conv.go

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,25 @@ func ToV3Parameter(components *openapi3.Components, parameter *openapi2.Paramete
261261
required = []string{parameter.Name}
262262
}
263263
schemaRef := &openapi3.SchemaRef{Value: &openapi3.Schema{
264-
Description: parameter.Description,
265-
Type: typ,
266-
Extensions: stripNonExtensions(parameter.Extensions),
267-
Format: format,
268-
Enum: parameter.Enum,
269-
Min: parameter.Minimum,
270-
Max: parameter.Maximum,
271-
ExclusiveMin: parameter.ExclusiveMin,
272-
ExclusiveMax: parameter.ExclusiveMax,
273-
MinLength: parameter.MinLength,
274-
MaxLength: parameter.MaxLength,
275-
Default: parameter.Default,
276-
MinItems: parameter.MinItems,
277-
MaxItems: parameter.MaxItems,
278-
Pattern: parameter.Pattern,
279-
AllowEmptyValue: parameter.AllowEmptyValue,
280-
UniqueItems: parameter.UniqueItems,
281-
MultipleOf: parameter.MultipleOf,
282-
Required: required,
264+
Description: parameter.Description,
265+
Type: typ,
266+
Extensions: stripNonExtensions(parameter.Extensions),
267+
Format: format,
268+
Enum: parameter.Enum,
269+
Min: parameter.Minimum,
270+
Max: parameter.Maximum,
271+
ExclusiveMinBool: &parameter.ExclusiveMin,
272+
ExclusiveMaxBool: &parameter.ExclusiveMax,
273+
MinLength: parameter.MinLength,
274+
MaxLength: parameter.MaxLength,
275+
Default: parameter.Default,
276+
MinItems: parameter.MinItems,
277+
MaxItems: parameter.MaxItems,
278+
Pattern: parameter.Pattern,
279+
AllowEmptyValue: parameter.AllowEmptyValue,
280+
UniqueItems: parameter.UniqueItems,
281+
MultipleOf: parameter.MultipleOf,
282+
Required: required,
283283
}}
284284
if parameter.Items != nil {
285285
schemaRef.Value.Items = ToV3SchemaRef(parameter.Items)
@@ -494,8 +494,8 @@ func ToV3SchemaRef(schema *openapi2.SchemaRef) *openapi3.SchemaRef {
494494
Example: schema.Value.Example,
495495
ExternalDocs: schema.Value.ExternalDocs,
496496
UniqueItems: schema.Value.UniqueItems,
497-
ExclusiveMin: schema.Value.ExclusiveMin,
498-
ExclusiveMax: schema.Value.ExclusiveMax,
497+
ExclusiveMinBool: &schema.Value.ExclusiveMin,
498+
ExclusiveMaxBool: &schema.Value.ExclusiveMax,
499499
ReadOnly: schema.Value.ReadOnly,
500500
WriteOnly: schema.Value.WriteOnly,
501501
AllowEmptyValue: schema.Value.AllowEmptyValue,
@@ -867,19 +867,17 @@ func FromV3SchemaRef(schema *openapi3.SchemaRef, components *openapi3.Components
867867
break
868868
}
869869
}
870-
return nil, &openapi2.Parameter{
871-
In: "formData",
872-
Name: originalName,
873-
Description: schema.Value.Description,
874-
Type: paramType,
875-
Enum: schema.Value.Enum,
876-
Minimum: schema.Value.Min,
877-
Maximum: schema.Value.Max,
878-
ExclusiveMin: schema.Value.ExclusiveMin,
879-
ExclusiveMax: schema.Value.ExclusiveMax,
880-
MinLength: schema.Value.MinLength,
881-
MaxLength: schema.Value.MaxLength,
882-
Default: schema.Value.Default,
870+
param := &openapi2.Parameter{
871+
In: "formData",
872+
Name: originalName,
873+
Description: schema.Value.Description,
874+
Type: paramType,
875+
Enum: schema.Value.Enum,
876+
Minimum: schema.Value.Min,
877+
Maximum: schema.Value.Max,
878+
MinLength: schema.Value.MinLength,
879+
MaxLength: schema.Value.MaxLength,
880+
Default: schema.Value.Default,
883881
// Items: schema.Value.Items,
884882
MinItems: schema.Value.MinItems,
885883
MaxItems: schema.Value.MaxItems,
@@ -889,6 +887,13 @@ func FromV3SchemaRef(schema *openapi3.SchemaRef, components *openapi3.Components
889887
Extensions: stripNonExtensions(schema.Value.Extensions),
890888
Required: required,
891889
}
890+
if schema.Value.ExclusiveMinBool != nil {
891+
param.ExclusiveMin = *schema.Value.ExclusiveMinBool
892+
}
893+
if schema.Value.ExclusiveMaxBool != nil {
894+
param.ExclusiveMax = *schema.Value.ExclusiveMaxBool
895+
}
896+
return nil, param
892897
}
893898
}
894899

@@ -903,8 +908,6 @@ func FromV3SchemaRef(schema *openapi3.SchemaRef, components *openapi3.Components
903908
Example: schema.Value.Example,
904909
ExternalDocs: schema.Value.ExternalDocs,
905910
UniqueItems: schema.Value.UniqueItems,
906-
ExclusiveMin: schema.Value.ExclusiveMin,
907-
ExclusiveMax: schema.Value.ExclusiveMax,
908911
ReadOnly: schema.Value.ReadOnly,
909912
WriteOnly: schema.Value.WriteOnly,
910913
AllowEmptyValue: schema.Value.AllowEmptyValue,
@@ -926,6 +929,13 @@ func FromV3SchemaRef(schema *openapi3.SchemaRef, components *openapi3.Components
926929
AdditionalProperties: schema.Value.AdditionalProperties,
927930
}
928931

932+
if schema.Value.ExclusiveMinBool != nil {
933+
v2Schema.ExclusiveMin = *schema.Value.ExclusiveMinBool
934+
}
935+
if schema.Value.ExclusiveMaxBool != nil {
936+
v2Schema.ExclusiveMax = *schema.Value.ExclusiveMaxBool
937+
}
938+
929939
if v := schema.Value.Items; v != nil {
930940
v2Schema.Items, _ = FromV3SchemaRef(v, components)
931941
}
@@ -1031,30 +1041,34 @@ func FromV3RequestBodyFormData(mediaType *openapi3.MediaType) openapi2.Parameter
10311041
v2Items, _ = FromV3SchemaRef(val.Items, nil)
10321042
}
10331043
parameter := &openapi2.Parameter{
1034-
Name: propName,
1035-
Description: val.Description,
1036-
Type: typ,
1037-
In: "formData",
1038-
Extensions: stripNonExtensions(val.Extensions),
1039-
Enum: val.Enum,
1040-
ExclusiveMin: val.ExclusiveMin,
1041-
ExclusiveMax: val.ExclusiveMax,
1042-
MinLength: val.MinLength,
1043-
MaxLength: val.MaxLength,
1044-
Default: val.Default,
1045-
Items: v2Items,
1046-
MinItems: val.MinItems,
1047-
MaxItems: val.MaxItems,
1048-
Maximum: val.Max,
1049-
Minimum: val.Min,
1050-
Pattern: val.Pattern,
1044+
Name: propName,
1045+
Description: val.Description,
1046+
Type: typ,
1047+
In: "formData",
1048+
Extensions: stripNonExtensions(val.Extensions),
1049+
Enum: val.Enum,
1050+
MinLength: val.MinLength,
1051+
MaxLength: val.MaxLength,
1052+
Default: val.Default,
1053+
Items: v2Items,
1054+
MinItems: val.MinItems,
1055+
MaxItems: val.MaxItems,
1056+
Maximum: val.Max,
1057+
Minimum: val.Min,
1058+
Pattern: val.Pattern,
10511059
// CollectionFormat: val.CollectionFormat,
10521060
// Format: val.Format,
10531061
AllowEmptyValue: val.AllowEmptyValue,
10541062
Required: required,
10551063
UniqueItems: val.UniqueItems,
10561064
MultipleOf: val.MultipleOf,
10571065
}
1066+
if val.ExclusiveMinBool != nil {
1067+
parameter.ExclusiveMin = *val.ExclusiveMinBool
1068+
}
1069+
if val.ExclusiveMaxBool != nil {
1070+
parameter.ExclusiveMax = *val.ExclusiveMaxBool
1071+
}
10581072
parameters = append(parameters, parameter)
10591073
}
10601074
return parameters

0 commit comments

Comments
 (0)