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

Fix Swagger serialization #34

Merged
merged 1 commit into from
Sep 9, 2017
Merged

Fix Swagger serialization #34

merged 1 commit into from
Sep 9, 2017

Conversation

joeduffy
Copy link
Member

@joeduffy joeduffy commented Sep 9, 2017

The Swagger spec object can contain embedded computed objects, so
we actually can't compute its value entirely promptly anymore. (Previously
we JSON serialized it using our custom runtime implementation, which
apparently tolerated unavailable computed values.) This change properly
mapValue-ifies the serialization logic, in all its ugly glory. Unfortunately,
this also means we can't promptly compute the hash based entirely on the
values, which is used for resource object ID calculation. For now, we will
just skip the non-prompt parts; this will lead to false hash collisions, but
anything else would be super hacky and all of this will get better imminently
once the current round of changes land and we can tackle pulumi/pulumi#331.

The Swagger spec object can contain embedded computed objects, so
we actually can't compute its value entirely promptly anymore.  (Previously
we JSON serialized it using our custom runtime implementation, which
apparently tolerated unavailable computed values.)  This change properly
mapValue-ifies the serialization logic, in all its ugly glory.  Unfortunately,
this also means we can't promptly compute the hash based entirely on the
values, which is used for resource object ID calculation.  For now, we will
just skip the non-prompt parts; this will lead to false hash collisions, but
anything else would be super hacky and all of this will get better imminently
once the current round of changes land and we can tackle pulumi/pulumi#331.
@@ -59,6 +59,47 @@ interface SwaggerSpec {
"x-amazon-apigateway-binary-media-types"?: string[];
}

// jsonStringifySwaggerSpec creates a JSON string out of a Swagger spec object. This is required versus an
// ordinary JSON.stringify because the spec contains computed values.
function jsonStringifySwaggerSpec(spec: SwaggerSpec): { json: string | fabric.Computed<string>, hash: string } {
Copy link
Member

Choose a reason for hiding this comment

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

Curious - why does this need to support the case of returning a string instead of just always returning a fabric.Computed<string>? Not that it really matters assuming we undo all of this after pulumi/pulumi#331.

Copy link
Member Author

Choose a reason for hiding this comment

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

If there are no methods, there would be no computeds, and because Property isn't public there's no way to create a zero initialized one without resorting to internal runtime APIs. Obviously if we kept any of this, we'd need to fix this, but as you say, we aren't.

@joeduffy joeduffy merged commit 7ed5da0 into master Sep 9, 2017
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.

None yet

2 participants