Skip to content

Http-Date Trait Value Validation Bug Fix#1946

Closed
lewisjkl wants to merge 1 commit intosmithy-lang:mainfrom
lewisjkl:main
Closed

Http-Date Trait Value Validation Bug Fix#1946
lewisjkl wants to merge 1 commit intosmithy-lang:mainfrom
lewisjkl:main

Conversation

@lewisjkl
Copy link
Copy Markdown
Contributor

@lewisjkl lewisjkl commented Aug 23, 2023

Found an issue where if the http-date timestamp format was used in a trait, then the validation would always fail (because it was checked twice, each time with a different format).

e.g. the following would fail:

@trait
structure myTrait {
  @timestampFormat("http-date")
  httpDate: Timestamp
}

@myTrait({ httpDate: "Sun, 06 Nov 1994 08:49:37 GMT"  }) // Invalid string value, `Sun, 06 Nov 1994 08:49:37 GMT`, provided for timestamp, `smithy.api#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., "1985-04-12T23:20:50.52Z")
string Whatever

A workaround at the moment is to do:

@timestampFormat("http-date")
timestamp HttpDate

@trait
structure myTrait {
  httpDate: HttpDate
}

@myTrait({ httpDate: "Sun, 06 Nov 1994 08:49:37 GMT"  }) // no error
string Whatever

This PR contains a test that reproduces the issue and one way of fixing it (no problem if you all want to do it differently or suggest a different way to me).


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

YES

@lewisjkl lewisjkl requested a review from a team as a code owner August 23, 2023 22:48
mtdowling added a commit that referenced this pull request Aug 24, 2023
The NodeValidationVisitor vists shapes, members, and then the targets
of members. When visiting the target of a member, the context of the
referring member was lost, which meant a member with a timestampFormat
trait like http-date isn't something the target shape has access to,
which will cause validation to fail. We now pass in the referring
member as part of the validation context.

Closes #1946
@mtdowling
Copy link
Copy Markdown
Member

Thanks for the PR and proposed fix! I decided to fix this differently that doesn't need the creation of synthetic shapes: #1948

@mtdowling mtdowling closed this Aug 24, 2023
mtdowling added a commit that referenced this pull request Aug 24, 2023
The NodeValidationVisitor vists shapes, members, and then the targets
of members. When visiting the target of a member, the context of the
referring member was lost, which meant a member with a timestampFormat
trait like http-date isn't something the target shape has access to,
which will cause validation to fail. We now pass in the referring
member as part of the validation context.

Closes #1946
mtdowling added a commit that referenced this pull request Aug 24, 2023
The NodeValidationVisitor vists shapes, members, and then the targets
of members. When visiting the target of a member, the context of the
referring member was lost, which meant a member with a timestampFormat
trait like http-date isn't something the target shape has access to,
which will cause validation to fail. We now pass in the referring
member as part of the validation context.

Closes #1946
@lewisjkl
Copy link
Copy Markdown
Contributor Author

Thanks for the PR and proposed fix! I decided to fix this differently that doesn't need the creation of synthetic shapes: #1948

Great, thank you for such a quick turn around!

alextwoods pushed a commit to alextwoods/smithy that referenced this pull request Sep 15, 2023
The NodeValidationVisitor vists shapes, members, and then the targets
of members. When visiting the target of a member, the context of the
referring member was lost, which meant a member with a timestampFormat
trait like http-date isn't something the target shape has access to,
which will cause validation to fail. We now pass in the referring
member as part of the validation context.

Closes smithy-lang#1946
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.

2 participants