Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-java"
---

Replace `js-yaml` with `yaml` for code-model serialization and drop `lodash` in favor of a built-in array comparison.
6 changes: 3 additions & 3 deletions packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ import {
import { getSegment } from "@typespec/rest";
import { getAddedOnVersions } from "@typespec/versioning";
import { fail } from "assert";
import pkg from "lodash";
import {
Client as CodeModelClient,
EncodedProperty,
Expand Down Expand Up @@ -174,7 +173,6 @@ import {
isStableApiVersionString,
resolveApiVersionOption,
} from "./versioning-utils.js";
const { isEqual } = pkg;

export interface EmitterOptionsDev {
flavor?: string;
Expand Down Expand Up @@ -844,7 +842,9 @@ export class CodeModelBuilder {
// first client, set it to sharedApiVersions
sharedApiVersions = apiVersions;
} else {
apiVersionSameForAllClients = isEqual(sharedApiVersions, apiVersions);
apiVersionSameForAllClients =
sharedApiVersions.length === apiVersions.length &&
sharedApiVersions.every((it, index) => it === apiVersions[index]);
}
if (!apiVersionSameForAllClients) {
break;
Expand Down
8 changes: 6 additions & 2 deletions packages/http-client-java/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
resolvePath,
} from "@typespec/compiler";
import { promises } from "fs";
import { dump } from "js-yaml";
import { dirname } from "path";
import { fileURLToPath } from "url";
import { stringify } from "yaml";
import { CodeModelBuilder, EmitterOptionsDev } from "./code-model-builder.js";
import { CodeModel } from "./common/code-model.js";
import { LibName, reportDiagnostic } from "./lib.js";
Expand Down Expand Up @@ -76,7 +76,11 @@ export async function $onEmit(context: EmitContext<EmitterOptions>) {
}
});

await program.host.writeFile(codeModelFileName, dump(codeModel));
// Serialize as YAML 1.1 to match the Java generator's consumer, SnakeYAML, which is a
// YAML 1.1 parser. YAML 1.2 (the `yaml` package default) drops implicit types that 1.1
// keeps, so date-like strings (e.g. api-version "2025-01-02"), yes/no, and base-60
// numbers would be emitted unquoted and then re-typed on read (e.g. into a Date).
await program.host.writeFile(codeModelFileName, stringify(codeModel, { version: "1.1" }));

trace(program, `Code model file written to ${codeModelFileName}`);

Expand Down
75 changes: 12 additions & 63 deletions packages/http-client-java/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions packages/http-client-java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
},
"dependencies": {
"@autorest/codemodel": "~4.20.1",
"js-yaml": "^4.2.0",
"lodash": "~4.18.1"
"yaml": "^2.8.3"
},
"devDependencies": {
"@azure-tools/typespec-autorest": "0.69.1",
Expand All @@ -76,8 +75,6 @@
"@azure-tools/typespec-client-generator-core": "0.69.1",
"@microsoft/api-extractor": "^7.58.9",
"@microsoft/api-extractor-model": "^7.33.8",
"@types/js-yaml": "~4.0.9",
"@types/lodash": "~4.17.24",
"@types/node": "~26.0.1",
"@typespec/compiler": "1.13.0",
"@typespec/events": "0.83.0",
Expand Down
Loading