Skip to content

Conversation

@XiaofeiCao
Copy link
Member

@XiaofeiCao XiaofeiCao commented Nov 28, 2025

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Nov 28, 2025
$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.

@github-actions
Copy link
Contributor

No changes needing a change description found.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Nov 28, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@XiaofeiCao XiaofeiCao changed the title mgmt, fix unix time mock [http-client-java]mgmt, fix unix time mock Nov 28, 2025
@XiaofeiCao XiaofeiCao marked this pull request as ready for review November 28, 2025 08:07
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of add a wireType, is it solvable by adding a case in public static String convertLiteralToClientValue(IType wireType, String literalInWireType) ?

I think it kind of convert the objectValue to clientValue (e.g. in this case, convert the epoch to datetime string).

Copy link
Contributor

@weidongxu-microsoft weidongxu-microsoft Dec 1, 2025

Choose a reason for hiding this comment

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

The bug maybe there?

The code maybe need to be this

literalValue = Instant.ofEpochSecond(Long.parseLong(Integer.parseInt(literalValue)).atOffset(ZoneOffset.UTC).toString()

Copy link
Member Author

@XiaofeiCao XiaofeiCao Dec 1, 2025

Choose a reason for hiding this comment

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

Yeah, we could do this. Though seems we still need wireType here. Any better ways to pass in the information?

public void accept(ExampleNode node, String getterCode) {
if (node instanceof LiteralNode) {
node.getClientType().addImportsTo(imports, false);
IType wireType = ((LiteralNode) node).getWireType();
addEqualsAssertion(
wireType.convertToClientType(node.getObjectValue() == null
? wireType.defaultValueExpression()
: wireType.defaultValueExpression(
// We are already using wireType, thus wire value should be used, instead of client value.
String.valueOf(node.getObjectValue()))),
getterCode, node.getClientType().asNullable() == ClassType.BOOLEAN);

Original code is:

public void accept(ExampleNode node, String getterCode) {
if (node instanceof LiteralNode) {
node.getClientType().addImportsTo(imports, false);
addEqualsAssertion(node.getClientType().defaultValueExpression(((LiteralNode) node).getLiteralsValue()),
getterCode, node.getClientType().asNullable() == ClassType.BOOLEAN);

Which is buggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:java Issue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mgmt generated test, fix OffsetDateTime mock value

3 participants