@azure-tools/typespec-java 0.27.9 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,37 @@
1
- import { AnySchema, BinarySchema, BooleanSchema, NumberSchema, ObjectSchema, Schema, StringSchema } from "@autorest/codemodel";
1
+ import { AnySchema, BinarySchema, BooleanSchema, License, NumberSchema, ObjectSchema, Schema, StringSchema } from "@autorest/codemodel";
2
2
  import { SdkType } from "@azure-tools/typespec-client-generator-core";
3
- import { EmitContext, Program, Type, Union } from "@typespec/compiler";
3
+ import { EmitContext, Program } from "@typespec/compiler";
4
4
  import { CodeModel } from "./common/code-model.js";
5
- import { EmitterOptions } from "./lib.js";
5
+ import { DevOptions, EmitterOptions } from "./options.js";
6
6
  import { ProcessingCache } from "./type-utils.js";
7
+ export interface EmitterOptionsDev {
8
+ flavor?: string;
9
+ namespace?: string;
10
+ "service-name"?: string;
11
+ "service-versions"?: string[];
12
+ license?: License;
13
+ "generate-samples"?: boolean;
14
+ "generate-tests"?: boolean;
15
+ "partial-update"?: boolean;
16
+ "models-subpackage"?: string;
17
+ "custom-types"?: string;
18
+ "custom-types-subpackage"?: string;
19
+ "customization-class"?: string;
20
+ "skip-special-headers"?: string[];
21
+ "enable-subclient"?: boolean;
22
+ "group-etag-headers"?: boolean;
23
+ "enable-sync-stack"?: boolean;
24
+ "stream-style-serialization"?: boolean;
25
+ "use-object-for-unknown"?: boolean;
26
+ polling?: any;
27
+ "api-version"?: string;
28
+ "advanced-versioning"?: boolean;
29
+ "service-version-exclude-preview"?: boolean;
30
+ "dev-options"?: DevOptions;
31
+ "output-dir": string;
32
+ arm?: boolean;
33
+ "license-header"?: string;
34
+ }
7
35
  export declare class CodeModelBuilder {
8
36
  private program;
9
37
  private typeNameOptions;
@@ -15,8 +43,8 @@ export declare class CodeModelBuilder {
15
43
  private codeModel;
16
44
  private emitterContext;
17
45
  private serviceNamespace;
46
+ private readonly javaNamespaceCache;
18
47
  readonly schemaCache: ProcessingCache<SdkType, Schema>;
19
- readonly typeUnionRefCache: Map<Type, Union | null | undefined>;
20
48
  private apiVersion;
21
49
  constructor(program1: Program, context: EmitContext<EmitterOptions>);
22
50
  build(): Promise<CodeModel>;
@@ -30,7 +58,6 @@ export declare class CodeModelBuilder {
30
58
  private processClients;
31
59
  private processClient;
32
60
  private listSubClientsUnderClient;
33
- private listServiceMethodsUnderClient;
34
61
  /**
35
62
  * Filter api-versions for "ServiceVersion".
36
63
  * TODO(xiaofei) pending TCGC design: https://github.com/Azure/typespec-azure/issues/965
@@ -95,6 +122,7 @@ export declare class CodeModelBuilder {
95
122
  private getConvenienceApiName;
96
123
  private getBaseJavaNamespace;
97
124
  private getJavaNamespace;
125
+ private escapeJavaNamespace;
98
126
  private trace;
99
127
  private _stringSchema?;
100
128
  get stringSchema(): StringSchema;
@@ -111,6 +139,7 @@ export declare class CodeModelBuilder {
111
139
  private _pollResultSchema?;
112
140
  get pollResultSchema(): ObjectSchema;
113
141
  private createApiVersionParameter;
142
+ private isApiVersionParameter;
114
143
  private _apiVersionParameter?;
115
144
  private _apiVersionParameterInPath?;
116
145
  private _apiVersionParameterInHeader?;
@@ -1 +1 @@
1
- {"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIT,YAAY,EACZ,aAAa,EAeb,YAAY,EAEZ,YAAY,EAOZ,MAAM,EAMN,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAwBL,OAAO,EAOR,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,WAAW,EAKX,OAAO,EACP,IAAI,EAEJ,KAAK,EAQN,MAAM,oBAAoB,CAAC;AAiB5B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AASnD,OAAO,EAAE,cAAc,EAAgD,MAAM,UAAU,CAAC;AAcxF,OAAO,EAIL,eAAe,EAShB,MAA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I,YAAY,CAOhC;IAED,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,IAAI,YAAY,IAAI,YAAY,CAO/B;IAED,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,IAAI,aAAa,IAAI,aAAa,CAOjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,IAAI,SAAS,IAAI,SAAS,CAIzB;IAED,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED,OAAO,CAAC,iBAAiB,CAAC,CAAe;IACzC,IAAI,gBAAgB,IAAI,YAAY,CAQnC;IAED,OAAO,CAAC,yBAAyB;IA8BjC,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,oBAAoB,CAAC,CAAY;IACzC,OAAO,CAAC,0BAA0B,CAAC,CAAY;IAC/C,OAAO,CAAC,4BAA4B,CAAC,CAAY;IACjD,OAAO,CAAC,uBAAuB,CAAC,CAAY;IAE5C,OAAO,CAAC,sBAAsB;IAiC9B,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,uBAAuB;IAwB/B,OAAO,CAAC,sBAAsB,CAAC,CAAY;IAE3C,OAAO,CAAC,oBAAoB;IA4F5B,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,KAAK;CAGd"}
@@ -1,4 +1,4 @@
1
- import { AnySchema, ApiVersion, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, DateSchema, DateTimeSchema, DictionarySchema, Discriminator, GroupProperty, GroupSchema, HttpHeader, HttpParameter, ImplementationLocation, KeySecurityScheme, Language, Metadata, NumberSchema, OAuth2SecurityScheme, ObjectSchema, OperationGroup, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, Security, SerializationStyle, StringSchema, TimeSchema, UnixTimeSchema, UriSchema, VirtualParameter, } from "@autorest/codemodel";
1
+ import { AnySchema, ApiVersion, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, DateSchema, DateTimeSchema, DictionarySchema, Discriminator, GroupProperty, GroupSchema, HttpHeader, HttpParameter, ImplementationLocation, KeySecurityScheme, Language, License, Metadata, NumberSchema, OAuth2SecurityScheme, ObjectSchema, OperationGroup, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, Security, SerializationStyle, StringSchema, TimeSchema, UnixTimeSchema, UriSchema, VirtualParameter, } from "@autorest/codemodel";
2
2
  import { KnownMediaType } from "@azure-tools/codegen";
3
3
  import { createSdkContext, getAllModels, getHttpOperationParameter, isSdkBuiltInKind, isSdkIntKind, } from "@azure-tools/typespec-client-generator-core";
4
4
  import { NoTarget, getDoc, getNamespaceFullName, getOverloadedOperation, getSummary, isArrayModelType, isRecordModelType, listServices, } from "@typespec/compiler";
@@ -17,18 +17,19 @@ import { OrSchema } from "./common/schemas/relationship.js";
17
17
  import { DurationSchema } from "./common/schemas/time.js";
18
18
  import { SchemaContext } from "./common/schemas/usage.js";
19
19
  import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
20
- import { LIB_NAME, createDiagnostic, reportDiagnostic } from "./lib.js";
20
+ import { createDiagnostic, reportDiagnostic } from "./lib.js";
21
21
  import { ClientContext } from "./models.js";
22
22
  import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
23
+ import { LIB_NAME } from "./options.js";
23
24
  import { BYTES_KNOWN_ENCODING, DATETIME_KNOWN_ENCODING, DURATION_KNOWN_ENCODING, ProcessingCache, getAccess, getDurationFormat, getNonNullSdkType, getPropertySerializedName, getUnionDescription, getUsage, modelIs, pushDistinct, } from "./type-utils.js";
24
- import { DiagnosticError, getNamespace, isStableApiVersion, pascalCase, removeClientSuffix, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
25
+ import { DiagnosticError, escapeJavaKeywords, getNamespace, isStableApiVersion, pascalCase, removeClientSuffix, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
25
26
  const { isEqual } = pkg;
26
27
  const AZURE_CORE_FOUNDATIONS_ERROR_ID = "Azure.Core.Foundations.Error";
27
28
  export class CodeModelBuilder {
28
29
  constructor(program1, context) {
29
30
  var _a, _b;
31
+ this.javaNamespaceCache = new Map();
30
32
  this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
31
- this.typeUnionRefCache = new Map(); // Union means it ref a Union type, null means it does not ref any Union, undefined means type visited but not completed
32
33
  this.options = context.options;
33
34
  this.program = program1;
34
35
  this.emitterContext = context;
@@ -78,6 +79,17 @@ export class CodeModelBuilder {
78
79
  additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@override"],
79
80
  versioning: { previewStringRegex: /$/ },
80
81
  }); // include all versions and do the filter by ourselves
82
+ this.program.reportDiagnostics(this.sdkContext.diagnostics);
83
+ // license
84
+ if (this.sdkContext.sdkPackage.licenseInfo) {
85
+ this.codeModel.info.license = new License(this.sdkContext.sdkPackage.licenseInfo.name, {
86
+ url: this.sdkContext.sdkPackage.licenseInfo.link,
87
+ extensions: {
88
+ header: this.sdkContext.sdkPackage.licenseInfo.header,
89
+ company: this.sdkContext.sdkPackage.licenseInfo.company,
90
+ },
91
+ });
92
+ }
81
93
  // java namespace
82
94
  if (this.options.namespace) {
83
95
  // legacy mode, clientNamespace from TCGC will be ignored
@@ -92,8 +104,6 @@ export class CodeModelBuilder {
92
104
  this.baseJavaNamespace = this.getBaseJavaNamespace();
93
105
  }
94
106
  this.codeModel.language.java.namespace = this.baseJavaNamespace;
95
- // potential problem https://github.com/Azure/typespec-azure/issues/1675
96
- this.program.reportDiagnostics(this.sdkContext.diagnostics);
97
107
  // auth
98
108
  // TODO: it is not very likely, but different client could have different auth
99
109
  const auth = getAuthentication(this.program, this.serviceNamespace);
@@ -116,7 +126,7 @@ export class CodeModelBuilder {
116
126
  let parameter;
117
127
  sdkPathParameters.forEach((arg) => {
118
128
  var _a;
119
- if (arg.isApiVersionParam) {
129
+ if (this.isApiVersionParameter(arg)) {
120
130
  parameter = this.createApiVersionParameter(arg.name, ParameterLocation.Uri);
121
131
  }
122
132
  else {
@@ -136,9 +146,8 @@ export class CodeModelBuilder {
136
146
  serializedName: arg.serializedName,
137
147
  },
138
148
  },
139
- // TODO: deprecate this logic of string/url for x-ms-skip-url-encoding
140
149
  extensions: {
141
- "x-ms-skip-url-encoding": schema instanceof UriSchema,
150
+ "x-ms-skip-url-encoding": arg.allowReserved,
142
151
  },
143
152
  clientDefaultValue: arg.clientDefaultValue,
144
153
  });
@@ -428,7 +437,7 @@ export class CodeModelBuilder {
428
437
  const enableSubclient = Boolean(this.options["enable-subclient"]);
429
438
  // preprocess operation groups and operations
430
439
  // operations without operation group
431
- const serviceMethodsWithoutSubClient = this.listServiceMethodsUnderClient(client);
440
+ const serviceMethodsWithoutSubClient = client.methods;
432
441
  let codeModelGroup = new OperationGroup("");
433
442
  codeModelGroup.language.default.crossLanguageDefinitionId = client.crossLanguageDefinitionId;
434
443
  for (const serviceMethod of serviceMethodsWithoutSubClient) {
@@ -450,7 +459,7 @@ export class CodeModelBuilder {
450
459
  else {
451
460
  // operations under operation groups
452
461
  for (const subClient of subClients) {
453
- const serviceMethods = this.listServiceMethodsUnderClient(subClient);
462
+ const serviceMethods = subClient.methods;
454
463
  // operation group with no operation is skipped
455
464
  if (serviceMethods.length > 0) {
456
465
  codeModelGroup = new OperationGroup(subClient.name);
@@ -505,9 +514,8 @@ export class CodeModelBuilder {
505
514
  listSubClientsUnderClient(client, includeNestedSubClients) {
506
515
  const isRootClient = !client.parent;
507
516
  const subClients = [];
508
- for (const method of client.methods) {
509
- if (method.kind === "clientaccessor") {
510
- const subClient = method.response;
517
+ if (client.children) {
518
+ for (const subClient of client.children) {
511
519
  if (!isRootClient) {
512
520
  // if it is not root client, append the parent client's name
513
521
  subClient.name =
@@ -523,15 +531,6 @@ export class CodeModelBuilder {
523
531
  }
524
532
  return subClients;
525
533
  }
526
- listServiceMethodsUnderClient(client) {
527
- const methods = [];
528
- for (const method of client.methods) {
529
- if (method.kind !== "clientaccessor") {
530
- methods.push(method);
531
- }
532
- }
533
- return methods;
534
- }
535
534
  /**
536
535
  * Filter api-versions for "ServiceVersion".
537
536
  * TODO(xiaofei) pending TCGC design: https://github.com/Azure/typespec-azure/issues/965
@@ -589,7 +588,6 @@ export class CodeModelBuilder {
589
588
  const operationName = sdkMethod.name;
590
589
  const httpOperation = sdkMethod.operation;
591
590
  const operationId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
592
- const operationGroup = this.codeModel.getOperationGroup(groupName);
593
591
  const operationExamples = this.getOperationExample(sdkMethod);
594
592
  const codeModelOperation = new CodeModelOperation(operationName, (_a = sdkMethod.doc) !== null && _a !== void 0 ? _a : "", {
595
593
  operationId: operationId,
@@ -711,7 +709,6 @@ export class CodeModelBuilder {
711
709
  this.processRouteForPaged(codeModelOperation, sdkMethod);
712
710
  // check for long-running operation
713
711
  this.processRouteForLongRunning(codeModelOperation, lroMetadata);
714
- operationGroup.addOperation(codeModelOperation);
715
712
  return codeModelOperation;
716
713
  }
717
714
  processRouteForPaged(op, sdkMethod) {
@@ -920,7 +917,7 @@ export class CodeModelBuilder {
920
917
  }
921
918
  processParameter(op, param, clientContext) {
922
919
  var _a, _b, _c;
923
- if (clientContext.apiVersions && param.isApiVersionParam && param.kind !== "cookie") {
920
+ if (clientContext.apiVersions && this.isApiVersionParameter(param) && param.kind !== "cookie") {
924
921
  // pre-condition for "isApiVersion": the client supports ApiVersions
925
922
  if (this.isArm()) {
926
923
  // Currently we assume ARM tsp only have one client and one api-version.
@@ -2042,7 +2039,6 @@ export class CodeModelBuilder {
2042
2039
  extensions["x-ms-mutability"] = mutability;
2043
2040
  }
2044
2041
  if (prop.kind === "property" && prop.serializationOptions.multipart) {
2045
- // TODO: handle MultipartOptions.isMulti
2046
2042
  if ((_a = prop.serializationOptions.multipart) === null || _a === void 0 ? void 0 : _a.isFilePart) {
2047
2043
  schema = this.processMultipartFormDataFilePropertySchema(prop);
2048
2044
  }
@@ -2294,7 +2290,7 @@ export class CodeModelBuilder {
2294
2290
  if (!baseJavaNamespace) {
2295
2291
  baseJavaNamespace = this.namespace;
2296
2292
  }
2297
- return baseJavaNamespace.toLowerCase();
2293
+ return this.escapeJavaNamespace(baseJavaNamespace.toLowerCase());
2298
2294
  }
2299
2295
  getJavaNamespace(type = undefined) {
2300
2296
  // clientNamespace from TCGC
@@ -2344,7 +2340,27 @@ export class CodeModelBuilder {
2344
2340
  return this.baseJavaNamespace;
2345
2341
  }
2346
2342
  else {
2347
- return clientNamespace.toLowerCase();
2343
+ return this.escapeJavaNamespace(clientNamespace.toLowerCase());
2344
+ }
2345
+ }
2346
+ escapeJavaNamespace(namespace) {
2347
+ if (this.javaNamespaceCache.has(namespace)) {
2348
+ return this.javaNamespaceCache.get(namespace);
2349
+ }
2350
+ else {
2351
+ const processedJavaNamespace = namespace
2352
+ .split(".")
2353
+ .map((segment) => escapeJavaKeywords(segment, "namespace"))
2354
+ .join(".");
2355
+ if (processedJavaNamespace !== namespace) {
2356
+ reportDiagnostic(this.program, {
2357
+ code: "invalid-java-namespace",
2358
+ format: { namespace: namespace, processedNamespace: processedJavaNamespace },
2359
+ target: NoTarget,
2360
+ });
2361
+ }
2362
+ this.javaNamespaceCache.set(namespace, processedJavaNamespace);
2363
+ return processedJavaNamespace;
2348
2364
  }
2349
2365
  }
2350
2366
  trace(msg) {
@@ -2396,6 +2412,9 @@ export class CodeModelBuilder {
2396
2412
  },
2397
2413
  });
2398
2414
  }
2415
+ isApiVersionParameter(param) {
2416
+ return param.isApiVersionParam;
2417
+ }
2399
2418
  getApiVersionParameter(param) {
2400
2419
  // apiVersionParameter is cached by param.kind
2401
2420
  // we didn't expect Azure service have more than 1 type of api-version, and certainly not more than 1 of each kind.