Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update IntervalAction to use the common Address #536

Merged
merged 2 commits into from
Mar 9, 2021

Conversation

weichou1229
Copy link
Member

Close #535

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/go-mod-core-contracts/blob/master/.github/Contributing.md.

What is the current behavior?

Issue Number: #535

What is the new behavior?

Since the common Address created, we can add it to the IntervalAction model and DTO.

Does this PR introduce a breaking change?

  • Yes
  • No

New Imports

  • Yes
  • No

Specific Instructions

Are there any specific instructions or things that should be known prior to reviewing?

Other information

Since the common Address created, we can add it to the IntervalAction model and DTO.

Close edgexfoundry#535

Signed-off-by: weichou <weichou1229@gmail.com>
Id string `json:"id,omitempty" validate:"omitempty,uuid"`
Name string `json:"name" validate:"edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
IntervalName string `json:"intervalName" validate:"edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
Address Address `json:"address" validate:"required"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the dive validation attribute to cause Address to be validated so don't have to manually call validate on Address??

Like we have done here for Readings in and Event:
https://github.com/edgexfoundry/go-mod-core-contracts/blob/master/v2/dtos/event.go#L30

Copy link
Member Author

@weichou1229 weichou1229 Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'dive' only works for slice and map, see https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Dive

In this case, the request DTO looks like:

  {
    "requestId": "e6e8a2f4-eb14-4649-9e2b-175247911369",
    "apiVersion":"v2",
    "action": {
        "apiVersion":"v2",
        "name": "query",
        "intervalName": "afternoon",
        "address":{
            "type": "REST",
            "host": "123.123.0.1",
            "port": 123,
            "httpMethod": "GET"
        }
            
    }
  }

Actually, I can success to verify the Address without call validation on the Address. But I need to verify the REST or MQTT protocol properties.
Currently, I didn't find any suitable tag for our use case so I wrote the Validate function, see https://github.com/edgexfoundry/go-mod-core-contracts/blob/master/v2/dtos/address.go#L25.

If we don't want to call validate on Address, we can

  1. Migrate the v1 validator to verify the deeper struct https://github.com/edgexfoundry/go-mod-core-contracts/blob/master/models/validator.go
  2. Or write a custom validation tag at https://github.com/edgexfoundry/go-mod-core-contracts/blob/master/v2/validator.go

v2/dtos/requests/intervalaction.go Show resolved Hide resolved
v2/dtos/intervalaction.go Show resolved Hide resolved
v2/dtos/requests/intervalaction.go Show resolved Hide resolved
v2/dtos/requests/intervalaction_test.go Outdated Show resolved Hide resolved
v2/dtos/requests/intervalaction_test.go Outdated Show resolved Hide resolved
Close edgexfoundry#535

Signed-off-by: weichou <weichou1229@gmail.com>
Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lenny-goodell lenny-goodell merged commit b029b98 into edgexfoundry:master Mar 9, 2021
This was referenced Mar 10, 2021
This was referenced Mar 15, 2021
@weichou1229 weichou1229 deleted the issue-535 branch July 16, 2021 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[V2 scheduler] Update IntervalAction to use the common Address
2 participants