Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ef5236b
Update common.py
Rangababu-R Dec 13, 2021
9035521
clubbed validation error fixes
Rangababu-R Dec 15, 2021
c9a0695
Update openapiartgo.py
Rangababu-R Dec 16, 2021
c296e93
validation tests and fixes
Rangababu-R Dec 16, 2021
86a291a
added Clone Support
Rangababu-R Dec 21, 2021
289deac
iter validation
Rangababu-R Jan 6, 2022
c801fe2
skip_excep made private
Rangababu-R Jan 6, 2022
647ea8e
Error message change for validation
Rangababu-R Nov 17, 2021
6dd2248
Update openapiartgo.py
Rangababu-R Nov 17, 2021
6e3c22b
lower case
Rangababu-R Nov 18, 2021
85c1a3a
Update openapiartgo.py
Rangababu-R Jan 10, 2022
a75da53
Update common.py
Rangababu-R Jan 10, 2022
364caeb
Update common.py
Rangababu-R Jan 10, 2022
d64d460
Update common.py
Rangababu-R Jan 10, 2022
3b87193
Update common.py
Rangababu-R Jan 10, 2022
d41a119
Update common.py
Rangababu-R Jan 10, 2022
e06ecc9
Update common.py
Rangababu-R Jan 10, 2022
ea9e2a0
final_fix
Rangababu-R Jan 10, 2022
2e16a12
Comments addressed
Rangababu-R Jan 24, 2022
9a6a533
Update config.json
Rangababu-R Jan 24, 2022
4c2684d
py error msgs fix
Rangababu-R Jan 27, 2022
b2225fd
Python lint errors
Rangababu-R Feb 25, 2022
a606fa9
Deprecated warning message for properties
Rangababu-R Apr 4, 2022
8fef9d4
black format
Rangababu-R Apr 4, 2022
3e06df8
update
Rangababu-R Apr 5, 2022
44ca7a5
Black format
Rangababu-R Apr 5, 2022
21e8973
modified x-status from enum to object
Rangababu-R Apr 6, 2022
4c1061f
py_deprecate_update
Rangababu-R Apr 6, 2022
97b3da9
black fix
Rangababu-R Apr 6, 2022
d68c17e
golang update
Rangababu-R Apr 7, 2022
ceaab2e
lint fixes
Rangababu-R Apr 7, 2022
ca5c4d0
Update common.py
Rangababu-R Apr 21, 2022
13ec947
ut update
Rangababu-R Apr 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ __pycache__
/pkg/openapiart.go
/pkg/httpapi
_debug_bin
.env
.env2
10 changes: 7 additions & 3 deletions openapiart/bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,21 @@ def _resolve_x_status(self):
"""
import jsonpath_ng

# st = self._get_parser("$..x-status").find(self._content)
# if st:
# import pdb; pdb.set_trace()
for xstatus in self._get_parser("$..x-status").find(self._content):
if xstatus.value == "current":
if xstatus.value.get("status") == "current":
continue
print("resolving %s..." % (str(xstatus.full_path)))
parent_schema_object = jsonpath_ng.Parent().find(xstatus)[0].value
if "description" not in parent_schema_object:
parent_schema_object["description"] = "TBD"
parent_schema_object[
"description"
] = "Status: {status}\n{description}".format(
status=xstatus.value,
] = "Status: {status}\n{add_info}\n{description}".format(
status=xstatus.value.get("status"),
add_info=xstatus.value.get("additional_info", ""),
description=parent_schema_object["description"],
)

Expand Down
84 changes: 49 additions & 35 deletions openapiart/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type Api interface {
NewHttpTransport() HttpTransport
hasHttpTransport() bool
Close() error
GetApiWarnings() []string
ClearApiWarnings()
}

// NewGrpcTransport sets the underlying transport of the Api as grpc
Expand Down Expand Up @@ -137,6 +139,14 @@ func (api *api) hasHttpTransport() bool {
return api.http != nil
}

func (api *api) GetApiWarnings() []string {
return openapi_warnings
}

func (api *api) ClearApiWarnings() {
openapi_warnings = nil
}

// HttpRequestDoer will return True for HTTP transport
type httpRequestDoer interface {
Do(req *http.Request) (*http.Response, error)
Expand All @@ -161,48 +171,52 @@ func validationResult() error {
return nil
}

func validateMac(mac string) error {
var openapi_warnings []string

func deprecated(message string) {
openapi_warnings = append(openapi_warnings, message)
}

func validateMac(mac string, path string) error {
macSlice := strings.Split(mac, ":")
if len(macSlice) != 6 {
return fmt.Errorf(fmt.Sprintf("Invalid Mac address %s", mac))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid mac string, instead of `%s`", path, mac))
}
octInd := []string{"0th", "1st", "2nd", "3rd", "4th", "5th"}
for ind, val := range macSlice {
for _, val := range macSlice {
num, err := strconv.ParseUint(val, 16, 32)
if err != nil || num > 255 {
return fmt.Errorf(fmt.Sprintf("Invalid Mac address at %s octet in %s mac", octInd[ind], mac))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid mac string, instead of `%s`", path, mac))
}
}
return nil
}

func validateIpv4(ip string) error {
func validateIpv4(ip string, path string) error {
ipSlice := strings.Split(ip, ".")
if len(ipSlice) != 4 {
return fmt.Errorf(fmt.Sprintf("Invalid Ipv4 address %s", ip))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid ipv4 string, instead of `%s`", path, ip))
}
octInd := []string{"1st", "2nd", "3rd", "4th"}
for ind, val := range ipSlice {
for _, val := range ipSlice {
num, err := strconv.ParseUint(val, 10, 32)
if err != nil || num > 255 {
return fmt.Errorf(fmt.Sprintf("Invalid Ipv4 address at %s octet in %s ipv4", octInd[ind], ip))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid ipv4 string, instead of `%s`", path, ip))
}
}
return nil
}

func validateIpv6(ip string) error {
func validateIpv6(ip string, path string) error {
ip = strings.Trim(ip, " \t")
if strings.Count(ip, " ") > 0 || strings.Count(ip, ":") > 7 ||
strings.Count(ip, "::") > 1 || strings.Count(ip, ":::") > 0 ||
strings.Count(ip, ":") == 0 {
return fmt.Errorf(fmt.Sprintf("Invalid ipv6 address %s", ip))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid ipv6 string, instead of `%s`", path, ip))
}
if (string(ip[0]) == ":" && string(ip[:2]) != "::") || (string(ip[len(ip)-1]) == ":" && string(ip[len(ip)-2:]) != "::") {
return fmt.Errorf(fmt.Sprintf("Invalid ipv6 address %s", ip))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid ipv6 string, instead of `%s`", path, ip))
}
if strings.Count(ip, "::") == 0 && strings.Count(ip, ":") != 7 {
return fmt.Errorf(fmt.Sprintf("Invalid ipv6 address %s", ip))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid ipv6 string, instead of `%s`", path, ip))
}
if ip == "::" {
return nil
Expand All @@ -217,69 +231,69 @@ func validateIpv6(ip string) error {
r := strings.NewReplacer("::", ":0:")
ip = r.Replace(ip)
}
octInd := []string{"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th"}

ipSlice := strings.Split(ip, ":")

for ind, val := range ipSlice {
for _, val := range ipSlice {
num, err := strconv.ParseUint(val, 16, 64)
if err != nil || num > 65535 {
return fmt.Errorf(fmt.Sprintf("Invalid Ipv6 address at %s octet in %s ipv6", octInd[ind], ip))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid ipv6 string, instead of `%s`", path, ip))
}
}

return nil
}

func validateHex(hex string) error {
func validateHex(hex string, path string) error {
matched, err := regexp.MatchString(`^[0-9a-fA-F]+$|^0[x|X][0-9a-fA-F]+$`, hex)
if err != nil || !matched {
return fmt.Errorf(fmt.Sprintf("Invalid hex value %s", hex))
return fmt.Errorf(fmt.Sprintf("value of `%s` must be a valid hex string, instead of %s", path, hex))
}
return nil
}

func validateSlice(valSlice []string, sliceType string) error {
func validateSlice(valSlice []string, sliceType string, path string) error {
indices := []string{}
var err error
for i, val := range valSlice {
if sliceType == "mac" {
err = validateMac(val)
err = validateMac(val, path)
} else if sliceType == "ipv4" {
err = validateIpv4(val)
err = validateIpv4(val, path)

} else if sliceType == "ipv6" {
err = validateIpv6(val)
err = validateIpv6(val, path)
} else if sliceType == "hex" {
err = validateHex(val)
err = validateHex(val, path)
} else {
return fmt.Errorf(fmt.Sprintf("Invalid slice type received <%s>", sliceType))
return fmt.Errorf(fmt.Sprintf("invalid slice type received <%s>", sliceType))
}

if err != nil {
indices = append(indices, fmt.Sprintf("%d", i))
indices = append(indices,
fmt.Sprintf("value of `%s[%d]` must be a valid %s string, instead of `%s`", path, i, sliceType, val))
}
}
if len(indices) > 0 {
return fmt.Errorf(
fmt.Sprintf("Invalid %s addresses at indices %s", sliceType, strings.Join(indices, ",")),
strings.Join(indices, "\n"),
)
}
return nil
}

func validateMacSlice(mac []string) error {
return validateSlice(mac, "mac")
func validateMacSlice(mac []string, path string) error {
return validateSlice(mac, "mac", path)
}

func validateIpv4Slice(ip []string) error {
return validateSlice(ip, "ipv4")
func validateIpv4Slice(ip []string, path string) error {
return validateSlice(ip, "ipv4", path)
}

func validateIpv6Slice(ip []string) error {
return validateSlice(ip, "ipv6")
func validateIpv6Slice(ip []string, path string) error {
return validateSlice(ip, "ipv6", path)
}

func validateHexSlice(hex []string) error {
return validateSlice(hex, "hex")
func validateHexSlice(hex []string, path string) error {
return validateSlice(hex, "hex", path)
}
Loading