Skip to content

Commit

Permalink
http-client-java, default flavor=azure, if package is typespec-java (m…
Browse files Browse the repository at this point in the history
…icrosoft#5384)

link microsoft#5380

- default flavor depends on package
- remove a (deprecated) emitter options
- enable `reportDiagnostics` from TCGC diagnostics (we may get one error
on
https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-inference,
I guess we can ignore that package for now)
- allow emitter runs on tsp without service -- this likely won't produce
anything expected though (I've run it on tsp with only models, TCGC did
not give me any model, even when I set access=public on them)
  • Loading branch information
weidongxu-microsoft authored Dec 17, 2024
1 parent 92749b7 commit ff550fa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
15 changes: 9 additions & 6 deletions packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ export class CodeModelBuilder {

const service = listServices(this.program)[0];
if (!service) {
this.logError("TypeSpec for HTTP must define a service.");
this.logWarning("TypeSpec for HTTP client should define a service.");
}
this.serviceNamespace = service.type;
this.serviceNamespace = service?.type ?? this.program.getGlobalNamespaceType();

this.namespace = getNamespaceFullName(this.serviceNamespace) || "Azure.Client";
this.namespace = getNamespaceFullName(this.serviceNamespace) || "Client";

const namespace1 = this.namespace;
this.typeNameOptions = {
Expand Down Expand Up @@ -238,6 +238,10 @@ export class CodeModelBuilder {
}

public async build(): Promise<CodeModel> {
if (this.program.hasError()) {
return this.codeModel;
}

this.sdkContext = await createSdkContext(this.emitterContext, "@typespec/http-client-java", {
versioning: { previewStringRegex: /$/ },
}); // include all versions and do the filter by ourselves
Expand All @@ -257,9 +261,8 @@ export class CodeModelBuilder {

this.codeModel.language.java!.namespace = this.baseJavaNamespace;

// TODO: reportDiagnostics from TCGC temporary disabled
// issue https://github.com/Azure/typespec-azure/issues/1675
// this.program.reportDiagnostics(this.sdkContext.diagnostics);
// potential problem https://github.com/Azure/typespec-azure/issues/1675
this.program.reportDiagnostics(this.sdkContext.diagnostics);

// auth
// TODO: it is not very likely, but different client could have different auth
Expand Down
19 changes: 12 additions & 7 deletions packages/http-client-java/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { JDK_NOT_FOUND_MESSAGE, validateDependencies } from "./validate.js";

export interface EmitterOptions {
namespace?: string;
"output-dir"?: string;
"package-dir"?: string;

flavor?: string;
Expand Down Expand Up @@ -57,12 +56,16 @@ export interface DevOptions {
"java-temp-dir"?: string; // working directory for java codegen, e.g. transformed code-model file
}

type CodeModelEmitterOptions = EmitterOptions & {
"output-dir": string;
arm?: boolean;
};

const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
type: "object",
additionalProperties: true,
properties: {
namespace: { type: "string", nullable: true },
"output-dir": { type: "string", nullable: true },
"package-dir": { type: "string", nullable: true },

flavor: { type: "string", nullable: true },
Expand Down Expand Up @@ -118,8 +121,7 @@ export async function $onEmit(context: EmitContext<EmitterOptions>) {
if (!program.hasError()) {
const options = context.options;
if (!options["flavor"]) {
if (options["package-dir"]?.toLocaleLowerCase().startsWith("azure")) {
// Azure package
if ($lib.name === "@azure-tools/typespec-java") {
options["flavor"] = "azure";
}
}
Expand All @@ -130,10 +132,13 @@ export async function $onEmit(context: EmitContext<EmitterOptions>) {
const __dirname = dirname(fileURLToPath(import.meta.url));
const moduleRoot = resolvePath(__dirname, "..", "..");

const outputPath = options["output-dir"] ?? context.emitterOutputDir;
options["output-dir"] = getNormalizedAbsolutePath(outputPath, undefined);
const outputPath = context.emitterOutputDir;
(options as CodeModelEmitterOptions)["output-dir"] = getNormalizedAbsolutePath(
outputPath,
undefined,
);

(options as any)["arm"] = codeModel.arm;
(options as CodeModelEmitterOptions).arm = codeModel.arm;

const codeModelFileName = resolvePath(outputPath, "./code-model.yaml");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@typespec/http-specs": "0.1.0-alpha.5",
"@azure-tools/azure-http-specs": "0.1.0-alpha.4",
"@typespec/http-client-java": "file:/../../typespec-http-client-java-0.1.4.tgz",
"@typespec/http-client-java": "file:../../typespec-http-client-java-0.1.5.tgz",
"@typespec/http-client-java-tests": "file:"
},
"overrides": {
Expand Down
4 changes: 2 additions & 2 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.

2 changes: 1 addition & 1 deletion packages/http-client-java/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typespec/http-client-java",
"version": "0.1.4",
"version": "0.1.5",
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
"keywords": [
"TypeSpec"
Expand Down

0 comments on commit ff550fa

Please sign in to comment.