-
Notifications
You must be signed in to change notification settings - Fork 913
Duplicate all eventstream event shapes + add new legacy event modes #6052
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
33f0010
00608dd
8224ea1
4b748f4
1237efa
5b35d92
9e7e110
21afe11
87b40d8
1c9ee94
e7f09cf
6da34e2
f6a8603
a2d0ce2
3baee8d
ac3d591
84ccbbf
ce71369
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.codegen.customization.processors; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor; | ||
import software.amazon.awssdk.codegen.model.config.customization.LegacyEventGenerationMode; | ||
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; | ||
import software.amazon.awssdk.codegen.model.service.ServiceModel; | ||
import software.amazon.awssdk.codegen.model.service.Shape; | ||
import software.amazon.awssdk.codegen.naming.NamingStrategy; | ||
import software.amazon.awssdk.utils.Logger; | ||
|
||
/** | ||
* Processor for eventstreams that ensures that all eventstream event shapes are unique - for each eventstream/event it creates a | ||
* new shape with a unique name constructed from the EventStream and Event shape names: `[ShapeName][EventStreamName]`. Any legacy | ||
* eventstream/events (configured with the useLegacyEventGenerationScheme customization) are skipped. When an event shape is | ||
* shared between multiple eventstreams, it causes SDK generation/compilation failures. The top level shape POJO implements the | ||
* event stream interface for each stream and the return type of the sdkEventType method conflicts. | ||
*/ | ||
public final class EventStreamUniqueEventShapesProcessor implements CodegenCustomizationProcessor { | ||
private static final Logger log = Logger.loggerFor(EventStreamUniqueEventShapesProcessor.class); | ||
|
||
private final Map<String, Map<String, LegacyEventGenerationMode>> useLegacyEventGenerationScheme; | ||
private final NamingStrategy namingStrategy; | ||
|
||
public EventStreamUniqueEventShapesProcessor( | ||
Map<String, Map<String, LegacyEventGenerationMode>> useLegacyEventGenerationScheme, | ||
NamingStrategy namingStrategy) { | ||
this.useLegacyEventGenerationScheme = useLegacyEventGenerationScheme; | ||
this.namingStrategy = namingStrategy; | ||
} | ||
|
||
@Override | ||
public void preprocess(ServiceModel serviceModel) { | ||
Map<String, Shape> newEventShapes = new HashMap<>(); | ||
serviceModel.getShapes().forEach((name, shape) -> { | ||
if (!shape.isEventstream()) { | ||
return; | ||
} | ||
|
||
preprocessEventStream(serviceModel, name, shape, newEventShapes); | ||
}); | ||
serviceModel.getShapes().putAll(newEventShapes); | ||
} | ||
|
||
private void preprocessEventStream(ServiceModel serviceModel, String eventStreamName, Shape eventStreamShape, Map<String, | ||
Shape> newEventShapes) { | ||
Map<String, LegacyEventGenerationMode> eventLegacyModes = useLegacyEventGenerationScheme | ||
.getOrDefault(eventStreamName, Collections.emptyMap()); | ||
|
||
eventStreamShape.getMembers().forEach((memberName, member) -> { | ||
String eventShapeName = member.getShape(); | ||
Shape memberTargetShape = serviceModel.getShape(eventShapeName); | ||
LegacyEventGenerationMode legacyEventGenerationMode = eventLegacyModes | ||
.getOrDefault(memberName, LegacyEventGenerationMode.DISABLED); | ||
|
||
if (memberTargetShape.isEvent() && legacyEventGenerationMode == LegacyEventGenerationMode.DISABLED) { | ||
String newShapeName = namingStrategy.getUniqueEventStreamEventShapeName(member, eventStreamName); | ||
if (serviceModel.getShapes().containsKey(newShapeName)) { | ||
log.warn(() -> String.format("Shape name conflict, unable to create a new unique event shape name for %s in" | ||
+ " eventstream %s because %s already exists in the model. Skipping.", | ||
eventShapeName, eventStreamName, newShapeName)); | ||
} else { | ||
log.debug(() -> String.format("Creating new, unique, event shape for %s in eventstream %s: %s", | ||
eventShapeName, eventStreamName, newShapeName)); | ||
newEventShapes.put(newShapeName, memberTargetShape); | ||
member.setShape(newShapeName); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void postprocess(IntermediateModel intermediateModel) { | ||
// no-op | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.codegen.model.config.customization; | ||
|
||
/** | ||
* Legacy event generation modes. | ||
*/ | ||
public enum LegacyEventGenerationMode { | ||
DISABLED, | ||
NO_EVENT_SUBCLASS, // old legacy - do not generate subclasses of events | ||
NO_UNIQUE_EVENT_NAMES // new legacy - do not duplicate event shapes to ensure unique events | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; | ||
import software.amazon.awssdk.codegen.model.intermediate.MemberModel; | ||
import software.amazon.awssdk.codegen.model.intermediate.Metadata; | ||
import software.amazon.awssdk.codegen.model.service.Member; | ||
import software.amazon.awssdk.codegen.model.service.ServiceModel; | ||
import software.amazon.awssdk.codegen.model.service.Shape; | ||
import software.amazon.awssdk.utils.Logger; | ||
|
@@ -411,6 +412,12 @@ public String getUnionEnumTypeName(MemberModel memberModel) { | |
return screamCase(memberModel.getName()); | ||
} | ||
|
||
@Override | ||
public String getUniqueEventStreamEventShapeName(Member eventMember, String eventStreamName) { | ||
return eventMember.getShape() + eventStreamName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking: is it necessary to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? The parameter name RE: the parameter name, theres no reason it couldn't be RE: applying capitalization to the existing shape name - Thats a good question - I was assuming that the existing shape name has already been validated (and any divergence from standard is intended and should be preserved). |
||
} | ||
|
||
|
||
private String rewriteInvalidMemberName(String memberName, Shape parentShape) { | ||
if (isJavaKeyword(memberName) || isDisallowedNameForShape(memberName, parentShape)) { | ||
return Utils.unCapitalize(memberName + CONFLICTING_NAME_SUFFIX); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"useLegacyEventGenerationScheme": { | ||
"EventStream": ["EventOne"] | ||
"EventStream": {"EventOne": "NO_EVENT_SUBCLASS"} | ||
}, | ||
"underscoresInNameBehavior": "ALLOW" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"useLegacyEventGenerationScheme": { | ||
"EventStream": ["EventOne", "secondEventOne"] | ||
} | ||
"EventStream": {"EventOne": "NO_EVENT_SUBCLASS", "secondEventOne": "NO_EVENT_SUBCLASS"} | ||
}, | ||
"underscoresInNameBehavior": "ALLOW" | ||
} |
Uh oh!
There was an error while loading. Please reload this page.