Skip to content

Conversation

@jeskew
Copy link
Contributor

@jeskew jeskew commented Apr 28, 2017

This PR includes #3 as it relies on the types defined there.

Still writing tests and working on removing the dependency on tsfmt.

@jeskew jeskew requested a review from chrisradek April 28, 2017 23:11
@jeskew jeskew changed the title [WIP] Feature/type generator Feature/type generator May 1, 2017
@jeskew jeskew force-pushed the feature/type-generator branch from d4f59cb to 7f953e5 Compare May 8, 2017 20:50
@jeskew jeskew force-pushed the feature/type-generator branch 2 times, most recently from 8412151 to 1c2ae53 Compare May 10, 2017 05:21
@@ -0,0 +1,291 @@
import {isArrayOf} from "./isArrayOf";
import {isObjectMapOf} from "./isObjectMapOf";
import {XmlNamespace} from "../../types/protocol";
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup.

export type Type = 'boolean'|'byte'|'timestamp'|'character'|'double'|'float'|'integer'|'long'|'short'|'string'|'blob'|'list'|'map'|'structure';

interface ShapeDef {
readonly type: Type
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: semicolon missing


export type Type = 'boolean'|'byte'|'timestamp'|'character'|'double'|'float'|'integer'|'long'|'short'|'string'|'blob'|'list'|'map'|'structure';

interface ShapeDef {
Copy link
Contributor

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).

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

}

export function isStructureMember(arg: any): arg is StructureMember {
return isMember(<StructureMember>arg) &&
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jeskew jeskew force-pushed the feature/type-generator branch from 1c2ae53 to 7a0bb12 Compare May 14, 2017 07:58
shapes: {
ConsumedCapacity: {
type: 'structure',
members: {},
Copy link
Contributor

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?

Copy link
Contributor Author

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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}
Copy link
Contributor

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}
Copy link
Contributor

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}
Copy link
Contributor

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)

Copy link
Contributor Author

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',
Copy link
Contributor

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.

Copy link
Contributor Author

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', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

should return false?

Copy link
Contributor Author

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',
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@jeskew jeskew force-pushed the feature/type-generator branch from 7a0bb12 to 7d5d274 Compare May 16, 2017 20:15
);

it(
'should return true when an operation uses the shape as its input',
Copy link
Contributor

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',
Copy link
Contributor

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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...

@jeskew jeskew force-pushed the feature/type-generator branch from 7d5d274 to 175542b Compare May 19, 2017 19:59
Copy link
Contributor

@chrisradek chrisradek left a comment

Choose a reason for hiding this comment

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

:shipit:

@jeskew jeskew merged commit 60f422c into master May 19, 2017
@jeskew jeskew deleted the feature/type-generator branch May 27, 2017 21:42
trivikr referenced this pull request in trivikr/aws-sdk-js-v3 Dec 10, 2018
@lock
Copy link

lock bot commented Sep 26, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants