Skip to content

Commit 0ea6d35

Browse files
authored
Add support for Timestamp(String and Double) for smithy codegen (#3195)
* add timestamp support for smithy codegen
1 parent bc3beb2 commit 0ea6d35

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tools/code-generation/smithy/codegen/cpp-smoke-tests-codegen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/GenericCodegenAdapter.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface GenericCodegenAdapter<SHAPE, DATA> {
2727

2828
public boolean isList(DATA d);
2929

30+
public boolean isDouble(DATA d);
31+
3032
public boolean isFloatShape( SHAPE s);
3133

3234
public boolean isBooleanShape(SHAPE s);
@@ -41,6 +43,10 @@ public interface GenericCodegenAdapter<SHAPE, DATA> {
4143

4244
public boolean isEnumShape( SHAPE s);
4345

46+
public boolean isTimestampShape(SHAPE s);
47+
48+
public boolean isDoubleShape( SHAPE s);
49+
4450
public List<DATA> getList(DATA d);
4551

4652
public Map<String, DATA> getMap(DATA d);
@@ -55,6 +61,8 @@ public interface GenericCodegenAdapter<SHAPE, DATA> {
5561

5662
public Integer getInteger(DATA d);
5763

64+
public Double getDouble(DATA d);
65+
5866
public String getShapeName(SHAPE s);
5967

6068
public void recordContainerForImport(SHAPE s);
@@ -191,6 +199,21 @@ else if (isString(value) && isEnumShape(shape))
191199
String shapeName = getShapeName(shape);
192200
functionName = String.format("{%s::%s}",shapeName,value);
193201
}
202+
else if(isTimestampShape(shape))
203+
{
204+
if(isString(value))
205+
{
206+
functionName = String.format("\"%s\"",value);
207+
}
208+
else if(isDouble(value))
209+
{
210+
functionName = String.format("{(double)%s}",value);
211+
}
212+
else
213+
{
214+
throw new RuntimeException("unsupported timestamp shape format");
215+
}
216+
}
194217
else
195218
{
196219
throw new RuntimeException(String.format("shape not supported:%s",shape));

tools/code-generation/smithy/codegen/cpp-smoke-tests-codegen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/SmithyCodegenAdapter.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,29 @@ public boolean isList(Node d)
126126
return d.isArrayNode();
127127
}
128128

129+
@Override
130+
public boolean isDouble(Node d)
131+
{
132+
if(d.isNumberNode())
133+
{
134+
double v = d.asNumberNode().get().asBigDecimal().get().doubleValue();
135+
return Double.isFinite(v) && !Double.isNaN(v) ;
136+
}
137+
return false;
138+
}
139+
129140
@Override
130141
public boolean isFloatShape( Shape s)
131142
{
132143
return s.getType() == ShapeType.FLOAT;
133144
}
134145

146+
@Override
147+
public boolean isDoubleShape( Shape s)
148+
{
149+
return s.getType() == ShapeType.DOUBLE;
150+
}
151+
135152
@Override
136153
public boolean isBooleanShape(Shape s)
137154
{
@@ -168,6 +185,12 @@ public boolean isEnumShape( Shape s)
168185
return s.getType() == ShapeType.ENUM;
169186
}
170187

188+
@Override
189+
public boolean isTimestampShape(Shape s)
190+
{
191+
return s.getType() == ShapeType.TIMESTAMP;
192+
}
193+
171194
@Override
172195
public List<Node> getList(Node d)
173196
{
@@ -198,6 +221,12 @@ public Float getFloat(Node d)
198221
return d.asNumberNode().get().asBigDecimal().get().floatValue();
199222
}
200223

224+
@Override
225+
public Double getDouble(Node d)
226+
{
227+
return d.asNumberNode().get().asBigDecimal().get().doubleValue();
228+
}
229+
201230
@Override
202231
public Integer getInteger(Node d)
203232
{

0 commit comments

Comments
 (0)