Skip to content

Enum shapes #1088

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5ef1d93
Add enum shape class and necessary supports
JordonPhillips Feb 9, 2022
52bc929
Add intEnum shape class
JordonPhillips Feb 10, 2022
573ce2b
Add enum and intEnum relationships
JordonPhillips Feb 10, 2022
91878bc
Make enum shape's enum trait synthetic
JordonPhillips Feb 10, 2022
f5c9f8c
Support loading enums in ast
JordonPhillips Feb 10, 2022
a378379
Set enum value trait automatically
JordonPhillips Feb 10, 2022
00aa523
Support loading enums in idl
JordonPhillips Feb 10, 2022
fd10fc5
Add more loader tests
JordonPhillips Feb 10, 2022
3f6beae
Change enum shape category to new enum category
JordonPhillips Feb 10, 2022
6443547
Support model transformer conversion for enums
JordonPhillips Feb 10, 2022
9071fd3
Add EnumValidator
JordonPhillips Feb 14, 2022
4b3ba2a
Add a simple transformer from string to enum
JordonPhillips Feb 14, 2022
d160648
Let model assembler set shapes version
JordonPhillips Feb 14, 2022
031a3d2
Restrict enum shapes to 2.0
JordonPhillips Feb 14, 2022
5edfb17
Make enums be selectable by parent types
JordonPhillips Feb 14, 2022
deccfe7
Add unit test for toSet with subclassing
JordonPhillips Feb 14, 2022
6e4208f
Deprecate enum trait
JordonPhillips Feb 15, 2022
5dca4c7
Disallow applying enum traits to enum shapes
JordonPhillips Feb 15, 2022
72f8f62
Add more enum trait conversion tests
JordonPhillips Feb 15, 2022
ba6eeb0
Support mixins for enum shapes
JordonPhillips Feb 16, 2022
0c3cd5e
Add enum design doc
JordonPhillips Feb 16, 2022
0a314dc
Change shape type categories to match design
JordonPhillips Feb 16, 2022
52bb6ef
Update enum design doc
JordonPhillips Feb 18, 2022
8e59464
Update enum error messages
JordonPhillips Feb 18, 2022
35c1802
Add ability to synthesize enum names
JordonPhillips Feb 22, 2022
d26d24d
Warn when a string can't be converted to enum
JordonPhillips Feb 22, 2022
a374018
Add isShapeType method to ShapeType
JordonPhillips Feb 22, 2022
f8f6efa
Add isShapeTypeSupported to Version
JordonPhillips Feb 22, 2022
d0f6af2
Fix typo: targetsUnion -> targetsUnit
JordonPhillips Feb 22, 2022
dc67daf
Update ModelAssembler docs for unparsed shapes
JordonPhillips Feb 22, 2022
3725c1f
Remove unnecessary members duplication in idl ser
JordonPhillips Feb 22, 2022
879e2bb
Re-privatize enum definitions
JordonPhillips Feb 22, 2022
4d38efd
Add override annotations for NamedMembers methods
JordonPhillips Feb 22, 2022
2dc22b8
Add getEnumValues methods to enum shapes
JordonPhillips Feb 22, 2022
5dbad8b
Add enumDefault trait
JordonPhillips Feb 22, 2022
51a2d95
Set node cache on enum value trait
JordonPhillips Feb 22, 2022
c167f42
Add transformer to downgrade enums
JordonPhillips Feb 22, 2022
e1deac4
Convert enumValue to a document trait
JordonPhillips Feb 24, 2022
46fbfd5
Implement pr feedback
JordonPhillips Feb 24, 2022
a8965b7
Use feature array for changeShapeType
JordonPhillips Feb 25, 2022
d0664f5
Hide away enum conversion guts
JordonPhillips Feb 25, 2022
c7a1aaf
Call out enumValue defaulting in design
JordonPhillips Feb 25, 2022
f27baad
Give specific error for fractions in enumValue
JordonPhillips Feb 25, 2022
bb1d7cf
Move ChangeShapeTypeOption out of ModelTransformer
JordonPhillips Feb 25, 2022
f574098
Clarify enum value defaulting
JordonPhillips Feb 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.transform.ModelTransformer;

/**
* {@code changeType} is used to change the type of one or more shapes.
Expand Down Expand Up @@ -80,7 +81,13 @@ protected Model transformWithConfig(TransformContext context, Config config) {
throw new SmithyBuildException(getName() + ": shapeTypes must not be empty");
}

if (config.getSynthesizeEnumNames()) {
return context.getTransformer().changeShapeType(
context.getModel(), config.getShapeTypes(),
ModelTransformer.ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES);
}

return context.getTransformer().changeShapeType(
context.getModel(), config.getShapeTypes(), config.getSynthesizeEnumNames());
context.getModel(), config.getShapeTypes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,17 @@ public Model changeShapeType(Model model, Map<ShapeId, ShapeType> shapeToType) {
*
* @param model Model to transform.
* @param shapeToType Map of shape IDs to the new type to use for the shape.
* @param synthesizeEnumNames Whether enums without names should have names synthesized if possible.
* @param changeShapeTypeOptions An array of options to enable when changing types.
* @return Returns the transformed model.
* @throws ModelTransformException if an incompatible type transform is attempted.
*/
public Model changeShapeType(Model model, Map<ShapeId, ShapeType> shapeToType, boolean synthesizeEnumNames) {
return new ChangeShapeType(shapeToType, synthesizeEnumNames).transform(this, model);
public Model changeShapeType(
Model model,
Map<ShapeId, ShapeType> shapeToType,
ChangeShapeTypeOption... changeShapeTypeOptions
) {
boolean synthesizeNames = ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES.hasFeature(changeShapeTypeOptions);
return new ChangeShapeType(shapeToType, synthesizeNames).transform(this, model);
}

/**
Expand Down Expand Up @@ -617,4 +622,24 @@ public Model createDedicatedInputAndOutput(Model model, String inputSuffix, Stri
public Model flattenAndRemoveMixins(Model model) {
return new FlattenAndRemoveMixins().transform(this, model);
}

/**
* Options that can be enabled when changing shape types.
*/
public enum ChangeShapeTypeOption {
/**
* Enables synthesizing enum names when changing a string shape to an enum shape and the
* string shape's {@link EnumTrait} doesn't have names.
*/
SYNTHESIZE_ENUM_NAMES;

boolean hasFeature(ChangeShapeTypeOption[] haystack) {
for (ChangeShapeTypeOption feature : haystack) {
if (feature == this) {
return true;
}
}
return false;
}
}
}