Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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 @@ -10,10 +10,16 @@
*/
public class LiteralNode extends ExampleNode {

private final IType wireType;
private String literalsValue;

public LiteralNode(IType clientType, Object objectValue) {
this(clientType, null, objectValue);
}

public LiteralNode(IType clientType, IType wireType, Object objectValue) {
super(clientType, objectValue);
this.wireType = wireType;
}

public String getLiteralsValue() {
Expand All @@ -24,4 +30,8 @@ public LiteralNode setLiteralsValue(String literalsValue) {
this.literalsValue = literalsValue;
return this;
}

public IType getWireType() {
return wireType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ private void addEqualsAssertion(String expected, String code, boolean booleanAss
public void accept(ExampleNode node, String getterCode) {
if (node instanceof LiteralNode) {
node.getClientType().addImportsTo(imports, false);
IType wireType = ((LiteralNode) node).getWireType();

addEqualsAssertion(node.getClientType().defaultValueExpression(((LiteralNode) node).getLiteralsValue()),
addEqualsAssertion(
wireType
.convertToClientType(wireType.defaultValueExpression(((LiteralNode) node).getLiteralsValue())),
getterCode, node.getClientType().asNullable() == ClassType.BOOLEAN);
} else if (node instanceof ObjectNode) {
// additionalProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static ExampleNode parseNode(IType type, IType wireType, Object objectVal
*/
private static ExampleNode defaultNode(IType clientType, IType wireType, Object exampleValue) {
ExampleNode node;
LiteralNode literalNode = new LiteralNode(clientType, exampleValue);
LiteralNode literalNode = new LiteralNode(clientType, wireType, exampleValue);
node = literalNode;

if (exampleValue != null) {
Expand Down Expand Up @@ -292,7 +292,8 @@ public static ExampleNode parseNodeFromParameter(ProxyMethodExample example, Met
if (ClassType.CONTEXT.equals(methodParameter.getClientMethodParameter().getClientType())) {
node = new LiteralNode(ClassType.CONTEXT, "").setLiteralsValue("");
} else {
node = new LiteralNode(methodParameter.getClientMethodParameter().getClientType(), null);
node = new LiteralNode(methodParameter.getClientMethodParameter().getClientType(),
methodParameter.getClientMethodParameter().getWireType(), null);
}
} else {
node = parseNodeFromMethodParameter(methodParameter, exampleValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public static Object jsonFromType(int depth, IType type) {
} else if (type == ClassType.STRING) {
return randomString();
} else if (type.asNullable() == ClassType.UNIX_TIME_LONG) {
return RANDOM.nextLong() & Long.MAX_VALUE;
// use nextInt to avoid exceeding unixTime limit
return RANDOM.nextInt() & Long.MAX_VALUE;
} else if (type == ClassType.DATE_TIME) {
return randomDateTime().toString();
} else if (type == ClassType.DATE_TIME_RFC_1123) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private static ExampleNode parseNodeFromModelProperty(ProxyMethodExample example
ProxyMethodExample.ParameterValue parameterValue = ModelExampleUtil.findParameter(example, serializedName);
ExampleNode node;
if (parameterValue == null) {
node = new LiteralNode(modelProperty.getClientType(), null);
node = new LiteralNode(modelProperty.getClientType(), modelProperty.getWireType(), null);
} else {
List<String> jsonPropertyNames = modelProperty.getSerializedNames();

Expand All @@ -544,7 +544,7 @@ private static ExampleNode parseNodeFromModelProperty(ProxyMethodExample example
node = ModelExampleUtil.parseNode(modelProperty.getClientType(), modelProperty.getWireType(),
childObjectValue);
} else {
node = new LiteralNode(modelProperty.getClientType(), null);
node = new LiteralNode(modelProperty.getClientType(), modelProperty.getWireType(), null);
}
}
return node;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore ARM generated tests with random mock values
src/test/java/tsptest/**/generated
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ $generateScript = {
$tspOptions += " --option ""@typespec/http-client-java.float32-as-double=false"""
$tspOptions += " --option ""@typespec/http-client-java.uuid-as-string=false"""
} elseif ($tspFile -match "tsp[\\/]arm-stream-style-serialization.tsp") {
# for mgmt, do not generate tests due to random mock values
$tspOptions += " --option ""@typespec/http-client-java.generate-tests=false"""
Copy link
Member Author

@XiaofeiCao XiaofeiCao Nov 28, 2025

Choose a reason for hiding this comment

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

Generate mock tests to at least ensure compilation pass. Generated tests will be git-ignored and won't be checked-in.

# test service-name
$tspOptions += " --option ""@typespec/http-client-java.service-name=Arm Resource Provider"""
# test property-include-always
Expand Down
Loading
Loading