diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index b1d967337a..691af914bd 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -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 = { @@ -238,6 +238,10 @@ export class CodeModelBuilder { } public async build(): Promise { + 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 @@ -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 diff --git a/packages/http-client-java/emitter/src/emitter.ts b/packages/http-client-java/emitter/src/emitter.ts index 625e87e957..ca4246c473 100644 --- a/packages/http-client-java/emitter/src/emitter.ts +++ b/packages/http-client-java/emitter/src/emitter.ts @@ -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; @@ -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 = { 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 }, @@ -118,8 +121,7 @@ export async function $onEmit(context: EmitContext) { 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"; } } @@ -130,10 +132,13 @@ export async function $onEmit(context: EmitContext) { 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"); diff --git a/packages/http-client-java/generator/http-client-generator-test/package.json b/packages/http-client-java/generator/http-client-generator-test/package.json index 65332739e6..a8ca8b4145 100644 --- a/packages/http-client-java/generator/http-client-generator-test/package.json +++ b/packages/http-client-java/generator/http-client-generator-test/package.json @@ -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": { diff --git a/packages/http-client-java/package-lock.json b/packages/http-client-java/package-lock.json index 5bbcfa2a3d..33bb25f262 100644 --- a/packages/http-client-java/package-lock.json +++ b/packages/http-client-java/package-lock.json @@ -1,12 +1,12 @@ { "name": "@typespec/http-client-java", - "version": "0.1.4", + "version": "0.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@typespec/http-client-java", - "version": "0.1.4", + "version": "0.1.5", "license": "MIT", "dependencies": { "@autorest/codemodel": "~4.20.0", diff --git a/packages/http-client-java/package.json b/packages/http-client-java/package.json index b75e74490d..5367482a48 100644 --- a/packages/http-client-java/package.json +++ b/packages/http-client-java/package.json @@ -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"