-
Notifications
You must be signed in to change notification settings - Fork 647
Feature/type generator #6
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
Conversation
d4f59cb to
7f953e5
Compare
8412151 to
1c2ae53
Compare
packages/service-model/lib/Shape.ts
Outdated
| @@ -0,0 +1,291 @@ | |||
| import {isArrayOf} from "./isArrayOf"; | |||
| import {isObjectMapOf} from "./isObjectMapOf"; | |||
| import {XmlNamespace} from "../../types/protocol"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should reference the @aws/types package, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup.
packages/service-model/lib/Shape.ts
Outdated
| export type Type = 'boolean'|'byte'|'timestamp'|'character'|'double'|'float'|'integer'|'long'|'short'|'string'|'blob'|'list'|'map'|'structure'; | ||
|
|
||
| interface ShapeDef { | ||
| readonly type: Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: semicolon missing
packages/service-model/lib/Shape.ts
Outdated
|
|
||
| export type Type = 'boolean'|'byte'|'timestamp'|'character'|'double'|'float'|'integer'|'long'|'short'|'string'|'blob'|'list'|'map'|'structure'; | ||
|
|
||
| interface ShapeDef { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll probably need to extend this class when generating declarations (might need to make most if not all interfaces exported).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an abstraction layer over the service models and wouldn't be used outside of this package. I'll sprinkle comments throughout to clarify.
| && ['undefined', 'boolean'].indexOf(typeof arg.deprecated) > -1; | ||
| } | ||
|
|
||
| export interface Blob extends ShapeDef { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to change the names of some of the exported interfaces. I'm not sure what TypeScript will do when it tries to export DOM types (Blob) or standard JavaScript classes (Boolean), when a user is also specifying that they are importing the DOM types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users can alias if they need to.
packages/service-model/lib/Shape.ts
Outdated
| } | ||
|
|
||
| export function isStructureMember(arg: any): arg is StructureMember { | ||
| return isMember(<StructureMember>arg) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have to cast <StructureMember> here? I thought since isStructureMember identifies arg as StructureMember if the method returns true, that's all that's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the cast, the compiler was throwing errors, though I'm not sure why.
1c2ae53 to
7a0bb12
Compare
| shapes: { | ||
| ConsumedCapacity: { | ||
| type: 'structure', | ||
| members: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, is it possible to have a structure without any members, aside from an input/output shape?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not explicitly forbidden, but I don't think any services have empty structures. They could be used as sigils (do one thing if an object exists; do another if it is null), but I don't think that's a common pattern.
| }); | ||
|
|
||
| it( | ||
| 'should reject objects where a "documentation" property is present and not a string', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have a test that it accepts a model with documentation as a string as well. Can it be null/undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is undefined is every other test. It cannot be null.
| isOperation, | ||
| } from "../../lib/ApiModel/Operation"; | ||
|
|
||
| describe('isHttpTraitDefinition', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imethod and requestUri are both required, right? If so, can we add a test that fails if either is missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but it's just exercising the same code path as the tests above. If a required parameter is not present, it is a type mismatch (undefined instead of string). Presence/absence is equivalent to any other type assertion.
| ); | ||
|
|
||
| it( | ||
| 'should reject objects where a "documentation" property is present and not a boolean', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of reject cases here, which is great, but can we also include the accepts cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
| expect(isServiceMetadata(Object.assign( | ||
| {}, | ||
| minimalValidServiceMetadata, | ||
| {apiVersion: 1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apiVersion should be endpointPrefix
| expect(isServiceMetadata(Object.assign( | ||
| {}, | ||
| minimalValidServiceMetadata, | ||
| {endpointPrefix: 1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endpointPrefix should be protocol
| expect(isServiceMetadata(Object.assign( | ||
| {}, | ||
| minimalValidServiceMetadata, | ||
| {signatureVersion: 1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also validate that the signature version is one of a set of types? (e.g. v4, v2, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and we do the same for protocol. I'll add a check to make sure we're rejecting strings that are not a valid signature version or protocol.
(Side note: we are currently rejecting 'v2' and will need to get special permission to allow it.)
| }); | ||
|
|
||
| it( | ||
| 'should reject objects where a "documentation" property is present and not a string', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these fields aren't in the minimalValidStructureMember, we should have accepts cases as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
| } | ||
| }); | ||
|
|
||
| it('should return true for all other shapes', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
| }); | ||
|
|
||
| it( | ||
| 'should reject objects where "members" is not an object map of StructureMembers', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an example where members is an object map of StructureMembers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
7a0bb12 to
7d5d274
Compare
| ); | ||
|
|
||
| it( | ||
| 'should return true when an operation uses the shape as its input', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> output
| ); | ||
|
|
||
| it( | ||
| 'should return true when an operation uses the shape as its input', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> errors?
| ); | ||
|
|
||
| it( | ||
| 'should return false for shapes not referenced directly by operations', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is it intended that isReferencedByOperation only looks at top-level shapes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. The parser calls this function along with isMember to determine if a shape is referenced either as a member of another shape or as a shape hung onto an operation. The implementation (and usage) follow the semantics of a service model.
I should find out what the TSDoc equivalent of YARD's @api private is and use it on most of this package...
7d5d274 to
175542b
Compare
chrisradek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
This PR includes #3 as it relies on the types defined there.
Still writing tests and working on removing the dependency on
tsfmt.