@azure-tools/typespec-java 0.12.1 → 0.12.3

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.
@@ -28,6 +28,7 @@ export declare class CodeModelBuilder {
28
28
  private processRouteForPaged;
29
29
  private processLroMetadata;
30
30
  private processRouteForLongRunning;
31
+ private _armApiVersionParameter?;
31
32
  private processParameter;
32
33
  private addAcceptHeaderParameter;
33
34
  private processEtagHeaderParameters;
@@ -60,6 +61,8 @@ export declare class CodeModelBuilder {
60
61
  private processUrlSchema;
61
62
  private processObjectSchema;
62
63
  private getEffectiveSchemaType;
64
+ private dummyResourceSchema;
65
+ private dummyObjectSchema;
63
66
  private applyModelPropertyDecorators;
64
67
  private processModelProperty;
65
68
  private processFormatString;
@@ -93,9 +96,13 @@ export declare class CodeModelBuilder {
93
96
  get apiVersionParameter(): Parameter;
94
97
  private _apiVersionParameterInPath?;
95
98
  get apiVersionParameterInPath(): Parameter;
99
+ private isSubscriptionId;
100
+ private subscriptionIdParameter;
101
+ private _subscriptionParameter?;
96
102
  private propagateSchemaUsage;
97
103
  private trackSchemaUsage;
98
104
  private isArmLongRunningOperation;
105
+ private isArm;
99
106
  private isSchemaUsageEmpty;
100
107
  }
101
108
  //# sourceMappingURL=code-model-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAoBL,OAAO,EAGP,IAAI,EAEJ,KAAK,EASL,WAAW,EAOZ,MAAM,oBAAoB,CAAC;AAgC5B,OAAO,EACL,SAAS,EAIT,aAAa,EAUb,YAAY,EACZ,YAAY,EACZ,SAAS,EAKT,MAAM,EAIN,YAAY,EAeb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAUnD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAW9C,OAAO,EACL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B,IAAI,SAAS,CAMzC;IAED,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,uBAAuB;IAyB/B,OAAO,CAAC,sBAAsB,CAAC,CAAY;IAE3C,OAAO,CAAC,oBAAoB;IAiE5B,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,kBAAkB;CAiB3B"}
@@ -1,11 +1,12 @@
1
- import { getDoc, getEffectiveModelType, getFormat, getFriendlyName, getKnownValues, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isRecordModelType, isUnknownType, getDiscriminator, isNeverType, listServices, getNamespaceFullName, isNullType, getTypeName, getProjectedName, getService, getEncode, getOverloadedOperation, isErrorModel, } from "@typespec/compiler";
1
+ import { getDoc, getEffectiveModelType, getFormat, getFriendlyName, getKnownValues, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isRecordModelType, isUnknownType, getDiscriminator, isNeverType, listServices, getNamespaceFullName, isNullType, getTypeName, getProjectedName, getEncode, getOverloadedOperation, isErrorModel, walkPropertiesInherited, getService, } from "@typespec/compiler";
2
2
  import { getResourceOperation, getSegment } from "@typespec/rest";
3
- import { getAuthentication, getServers, getStatusCodeDescription, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, } from "@typespec/http";
3
+ import { getAuthentication, getServers, getStatusCodeDescription, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, isPathParam, } from "@typespec/http";
4
4
  import { getAddedOnVersions, getVersion } from "@typespec/versioning";
5
5
  import { isPollingLocation, getPagedResult, isFixed, getLroMetadata } from "@azure-tools/typespec-azure-core";
6
6
  import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, } from "@azure-tools/typespec-client-generator-core";
7
7
  import { fail } from "assert";
8
8
  import { AnySchema, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, DateTimeSchema, DateSchema, DictionarySchema, Discriminator, HttpHeader, HttpParameter, ImplementationLocation, NumberSchema, ObjectSchema, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, StringSchema, TimeSchema, Security, OAuth2SecurityScheme, KeySecurityScheme, OperationGroup, UriSchema, VirtualParameter, GroupSchema, GroupProperty, ApiVersion, SerializationStyle, Metadata, UnixTimeSchema, Language, } from "@autorest/codemodel";
9
+ import { KnownMediaType } from "@azure-tools/codegen";
9
10
  import { CodeModel } from "./common/code-model.js";
10
11
  import { Client as CodeModelClient, ObjectScheme } from "./common/client.js";
11
12
  import { ConvenienceApi, Operation as CodeModelOperation, Request } from "./common/operation.js";
@@ -21,6 +22,7 @@ import { ClientContext } from "./models.js";
21
22
  import { stringArrayContainsIgnoreCase, getJavaNamespace, getNamespace, pascalCase, logWarning, trace, } from "./utils.js";
22
23
  import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, isSameLiteralTypes, getAccess, getUsage, getUnionDescription, modelIs, getModelNameForProperty, isAllValueInteger, } from "./type-utils.js";
23
24
  import { getClientApiVersions, getServiceVersion, operationIsJsonMergePatch, isPayloadProperty, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, loadExamples, isLroNewPollingStrategy, operationIsMultipleContentTypes, cloneOperationParameter, operationIsMultipart, isKnownContentType, CONTENT_TYPE_KEY, } from "./operation-utils.js";
25
+ import { isArmCommonType } from "./type-utils.js";
24
26
  import pkg from "lodash";
25
27
  import { getExtensions } from "@typespec/openapi";
26
28
  const { isEqual } = pkg;
@@ -266,10 +268,14 @@ export class CodeModelBuilder {
266
268
  // deduplicate model name
267
269
  const nameCount = new Map();
268
270
  const deduplicateName = (schema) => {
269
- var _a, _b;
271
+ var _a, _b, _c, _d;
272
+ // skip models under "Azure.ResourceManager"
273
+ if (this.isArm() && ((_b = (_a = schema.language.default) === null || _a === void 0 ? void 0 : _a.namespace) === null || _b === void 0 ? void 0 : _b.startsWith("Azure.ResourceManager"))) {
274
+ return;
275
+ }
270
276
  const name = schema.language.default.name;
271
277
  // skip models under "com.azure.core."
272
- if (name && !((_b = (_a = schema.language.java) === null || _a === void 0 ? void 0 : _a.namespace) === null || _b === void 0 ? void 0 : _b.startsWith("com.azure.core."))) {
278
+ if (name && !((_d = (_c = schema.language.java) === null || _c === void 0 ? void 0 : _c.namespace) === null || _d === void 0 ? void 0 : _d.startsWith("com.azure.core."))) {
273
279
  if (!nameCount.has(name)) {
274
280
  nameCount.set(name, 1);
275
281
  }
@@ -337,9 +343,6 @@ export class CodeModelBuilder {
337
343
  apiVersion.version = service.version;
338
344
  codeModelClient.apiVersions.push(apiVersion);
339
345
  }
340
- else {
341
- throw new Error(`API version not available for client ${client.name}.`);
342
- }
343
346
  }
344
347
  // server
345
348
  let baseUri = "{endpoint}";
@@ -456,13 +459,7 @@ export class CodeModelBuilder {
456
459
  let apiComment = undefined;
457
460
  if (generateConvenienceApi) {
458
461
  // check if the convenience API need to be disabled for some special cases
459
- if (operationIsJsonMergePatch(op)) {
460
- // do not generate convenience method for JSON Merge Patch
461
- generateConvenienceApi = false;
462
- apiComment = `Convenience API is not generated, as operation '${op.operation.name}' is 'application/merge-patch+json'`;
463
- this.logWarning(apiComment);
464
- }
465
- else if (operationIsMultipart(op)) {
462
+ if (operationIsMultipart(op)) {
466
463
  // do not generate protocol method for multipart/form-data, as it be very hard for user to prepare the request body as BinaryData
467
464
  generateProtocolApi = false;
468
465
  apiComment = `Protocol API requires serialization of parts with content-disposition and data, as operation '${op.operation.name}' is 'multipart/form-data'`;
@@ -475,6 +472,12 @@ export class CodeModelBuilder {
475
472
  apiComment = `Convenience API is not generated, as operation '${op.operation.name}' is multiple content-type`;
476
473
  this.logWarning(apiComment);
477
474
  }
475
+ else if (operationIsJsonMergePatch(op) && !this.options["stream-style-serialization"]) {
476
+ // do not generate convenient method for json merge patch operation if stream-style-serialization is not enabled
477
+ generateConvenienceApi = false;
478
+ apiComment = `Convenience API is not generated, as operation '${op.operation.name}' is 'application/merge-patch+json' and stream-style-serialization is not enabled`;
479
+ this.logWarning(apiComment);
480
+ }
478
481
  // else {
479
482
  // const union = operationRefersUnion(this.program, op, this.typeUnionRefCache);
480
483
  // if (union) {
@@ -669,8 +672,26 @@ export class CodeModelBuilder {
669
672
  }
670
673
  processParameter(op, param, clientContext) {
671
674
  var _a;
672
- if (isApiVersion(this.sdkContext, param)) {
673
- const parameter = param.type === "query" ? this.apiVersionParameter : this.apiVersionParameterInPath;
675
+ if (clientContext.apiVersions && isApiVersion(this.sdkContext, param)) {
676
+ // pre-condition for "isApiVersion": the client supports ApiVersions
677
+ if (this.isArm()) {
678
+ // Currently we assume ARM tsp only have one client and one api-version.
679
+ // TODO: How will service define mixed api-versions(like those in Compute RP)?
680
+ const apiVersion = clientContext.apiVersions[0];
681
+ if (!this._armApiVersionParameter) {
682
+ this._armApiVersionParameter = this.createApiVersionParameter("api-version", param.type === "query" ? ParameterLocation.Query : ParameterLocation.Path, apiVersion);
683
+ clientContext.addGlobalParameter(this._armApiVersionParameter);
684
+ }
685
+ op.addParameter(this._armApiVersionParameter);
686
+ }
687
+ else {
688
+ const parameter = param.type === "query" ? this.apiVersionParameter : this.apiVersionParameterInPath;
689
+ op.addParameter(parameter);
690
+ clientContext.addGlobalParameter(parameter);
691
+ }
692
+ }
693
+ else if (this.isSubscriptionId(param)) {
694
+ const parameter = this.subscriptionIdParameter(param);
674
695
  op.addParameter(parameter);
675
696
  clientContext.addGlobalParameter(parameter);
676
697
  }
@@ -801,7 +822,7 @@ export class CodeModelBuilder {
801
822
  // parameters already include "accept" header
802
823
  return;
803
824
  }
804
- const produces = new Set(["application/json"]);
825
+ const produces = new Set();
805
826
  for (const resp of responses) {
806
827
  if (resp.responses && resp.responses.length > 0) {
807
828
  for (const response of resp.responses) {
@@ -809,6 +830,9 @@ export class CodeModelBuilder {
809
830
  }
810
831
  }
811
832
  }
833
+ if (produces.size === 0) {
834
+ produces.add("application/json");
835
+ }
812
836
  const acceptTypes = Array.from(produces.values()).join(", ");
813
837
  const acceptSchema = ((_c = this.codeModel.schemas.constants) === null || _c === void 0 ? void 0 : _c.find((it) => it.language.default.name === "accept" && it.value.value === acceptTypes)) ||
814
838
  this.codeModel.schemas.add(new ConstantSchema("accept", `Accept: ${acceptTypes}`, {
@@ -967,7 +991,7 @@ export class CodeModelBuilder {
967
991
  this.trackSchemaUsage(schema, { usage: [SchemaContext.JsonMergePatch] });
968
992
  }
969
993
  if (op.convenienceApi && operationIsMultipart(httpOperation)) {
970
- this.trackSchemaUsage(schema, { usage: [SchemaContext.MultipartFormData] });
994
+ this.trackSchemaUsage(schema, { serializationFormats: [KnownMediaType.Multipart] });
971
995
  }
972
996
  if (!schema.language.default.name && schema instanceof ObjectSchema) {
973
997
  // anonymous model
@@ -1097,7 +1121,7 @@ export class CodeModelBuilder {
1097
1121
  statusCodes: this.getStatusCodes(resp.statusCodes),
1098
1122
  headers: headers,
1099
1123
  mediaTypes: responseBody.contentTypes,
1100
- knownMediaType: "binary",
1124
+ knownMediaType: KnownMediaType.Binary,
1101
1125
  },
1102
1126
  },
1103
1127
  language: {
@@ -1260,7 +1284,9 @@ export class CodeModelBuilder {
1260
1284
  schema = this.processChoiceSchema(knownValues, this.getName(knownValues), false);
1261
1285
  }
1262
1286
  else {
1263
- const schemaNameHint = pascalCase(getModelNameForProperty(type)) + pascalCase(nameHint);
1287
+ const schemaNameHint = type.type.kind === "Scalar" && this.program.checker.isStdType(type.type)
1288
+ ? nameHint // std scalar won't need a nameHint
1289
+ : pascalCase(getModelNameForProperty(type)) + pascalCase(nameHint);
1264
1290
  schema = this.processSchema(type.type, schemaNameHint);
1265
1291
  }
1266
1292
  return this.applyModelPropertyDecorators(type, nameHint, schema);
@@ -1287,6 +1313,7 @@ export class CodeModelBuilder {
1287
1313
  processScalar(type, formatFromDerived, nameHint) {
1288
1314
  const scalarName = type.name;
1289
1315
  if (this.program.checker.isStdType(type)) {
1316
+ nameHint = scalarName;
1290
1317
  switch (scalarName) {
1291
1318
  case "string": {
1292
1319
  const format = formatFromDerived !== null && formatFromDerived !== void 0 ? formatFromDerived : getFormat(this.program, type);
@@ -1547,6 +1574,18 @@ export class CodeModelBuilder {
1547
1574
  processObjectSchema(type, name) {
1548
1575
  var _a, _b;
1549
1576
  const namespace = getNamespace(type);
1577
+ if ((this.isArm() &&
1578
+ (namespace === null || namespace === void 0 ? void 0 : namespace.startsWith("Azure.ResourceManager")) &&
1579
+ // there's ResourceListResult under Azure.ResourceManager namespace,
1580
+ // which shouldn't be considered Resource schema parent
1581
+ ((name === null || name === void 0 ? void 0 : name.startsWith("TrackedResource")) ||
1582
+ (name === null || name === void 0 ? void 0 : name.startsWith("ExtensionResource")) ||
1583
+ (name === null || name === void 0 ? void 0 : name.startsWith("ProxyResource")))) ||
1584
+ name === "ArmResource") {
1585
+ const objectSchema = this.dummyResourceSchema(type, name, namespace);
1586
+ this.codeModel.schemas.add(objectSchema);
1587
+ return objectSchema;
1588
+ }
1550
1589
  const objectSchema = new ObjectScheme(name, this.getDoc(type), {
1551
1590
  summary: this.getSummary(type),
1552
1591
  language: {
@@ -1622,7 +1661,14 @@ export class CodeModelBuilder {
1622
1661
  else if (isRecordModelType(this.program, type)) {
1623
1662
  // "pure" Record processed elsewhere
1624
1663
  // "mixed" Record that have properties, treat the model as "additionalProperties"
1625
- const parentSchema = this.processDictionarySchema(type, this.getName(type));
1664
+ /* type should have sourceModel, as
1665
+ model Type is Record<> {
1666
+ prop1: string
1667
+ }
1668
+ */
1669
+ const parentSchema = type.sourceModel
1670
+ ? this.processSchema(type.sourceModel, this.getName(type.sourceModel))
1671
+ : this.processDictionarySchema(type, this.getName(type));
1626
1672
  objectSchema.parents = new Relations();
1627
1673
  objectSchema.parents.immediate.push(parentSchema);
1628
1674
  pushDistinct(objectSchema.parents.all, parentSchema);
@@ -1665,18 +1711,47 @@ export class CodeModelBuilder {
1665
1711
  return objectSchema;
1666
1712
  }
1667
1713
  getEffectiveSchemaType(type) {
1714
+ var _a;
1668
1715
  const program = this.program;
1669
1716
  function isSchemaProperty(property) {
1670
1717
  return isPayloadProperty(program, property);
1671
1718
  }
1672
1719
  if (type.kind === "Model") {
1673
1720
  const effective = getEffectiveModelType(program, type, isSchemaProperty);
1674
- if (effective.name) {
1721
+ if (this.isArm() && ((_a = getNamespace(effective)) === null || _a === void 0 ? void 0 : _a.startsWith("Azure.ResourceManager"))) {
1722
+ // Catalog is TrackedResource<CatalogProperties>
1723
+ return type;
1724
+ }
1725
+ else if (effective.name) {
1675
1726
  return effective;
1676
1727
  }
1677
1728
  }
1678
1729
  return type;
1679
1730
  }
1731
+ dummyResourceSchema(type, name, namespace) {
1732
+ const resourceModelName = (name === null || name === void 0 ? void 0 : name.startsWith("TrackedResource")) ? "Resource" : "ProxyResource";
1733
+ const resource = this.dummyObjectSchema(type, resourceModelName, namespace);
1734
+ const declaredProperties = walkPropertiesInherited(type);
1735
+ for (const prop of declaredProperties) {
1736
+ resource.addProperty(this.processModelProperty(prop));
1737
+ }
1738
+ return resource;
1739
+ }
1740
+ dummyObjectSchema(type, name, namespace) {
1741
+ return new ObjectScheme(name, this.getDoc(type), {
1742
+ summary: this.getSummary(type),
1743
+ language: {
1744
+ default: {
1745
+ name: name,
1746
+ namespace: namespace,
1747
+ },
1748
+ java: {
1749
+ name: name,
1750
+ namespace: getJavaNamespace(namespace),
1751
+ },
1752
+ },
1753
+ });
1754
+ }
1680
1755
  applyModelPropertyDecorators(prop, nameHint, schema) {
1681
1756
  // if (schema instanceof StringSchema) {
1682
1757
  // const decorators = {
@@ -2012,10 +2087,10 @@ export class CodeModelBuilder {
2012
2087
  var _a;
2013
2088
  return ((_a = this._pollResultSchema) !== null && _a !== void 0 ? _a : (this._pollResultSchema = createPollOperationDetailsSchema(this.codeModel.schemas, this.stringSchema)));
2014
2089
  }
2015
- createApiVersionParameter(serializedName, parameterLocation) {
2090
+ createApiVersionParameter(serializedName, parameterLocation, value = "") {
2016
2091
  return new Parameter(serializedName, "Version parameter", this.codeModel.schemas.add(new ConstantSchema(serializedName, "API Version", {
2017
2092
  valueType: this.stringSchema,
2018
- value: new ConstantValue(""),
2093
+ value: new ConstantValue(value),
2019
2094
  })), {
2020
2095
  implementation: ImplementationLocation.Client,
2021
2096
  origin: ORIGIN_API_VERSION,
@@ -2039,8 +2114,34 @@ export class CodeModelBuilder {
2039
2114
  // TODO: hardcode as "apiVersion", as it is what we get from compiler
2040
2115
  (this._apiVersionParameterInPath = this.createApiVersionParameter("apiVersion", ParameterLocation.Path)));
2041
2116
  }
2042
- propagateSchemaUsage(schema) {
2117
+ isSubscriptionId(param) {
2043
2118
  var _a;
2119
+ return ("subscriptionId".toLocaleLowerCase() === ((_a = param === null || param === void 0 ? void 0 : param.name) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) &&
2120
+ param.param &&
2121
+ isArmCommonType(param.param) &&
2122
+ isPathParam(this.program, param.param));
2123
+ }
2124
+ subscriptionIdParameter(parameter) {
2125
+ if (!this._subscriptionParameter) {
2126
+ const param = parameter.param;
2127
+ const description = getDoc(this.program, param);
2128
+ this._subscriptionParameter = new Parameter("subscriptionId", description ? description : "The ID of the target subscription.", this.stringSchema, {
2129
+ implementation: ImplementationLocation.Client,
2130
+ required: true,
2131
+ protocol: {
2132
+ http: new HttpParameter(ParameterLocation.Path),
2133
+ },
2134
+ language: {
2135
+ default: {
2136
+ serializedName: "subscriptionId",
2137
+ },
2138
+ },
2139
+ });
2140
+ }
2141
+ return this._subscriptionParameter;
2142
+ }
2143
+ propagateSchemaUsage(schema) {
2144
+ var _a, _b;
2044
2145
  const processedSchemas = new Set();
2045
2146
  const innerApplySchemaUsage = (schema, schemaUsage) => {
2046
2147
  this.trackSchemaUsage(schema, schemaUsage);
@@ -2093,8 +2194,8 @@ export class CodeModelBuilder {
2093
2194
  };
2094
2195
  // Exclude context that not to be propagated
2095
2196
  const schemaUsage = {
2096
- usage: (_a = schema.usage) === null || _a === void 0 ? void 0 : _a.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.Anonymous && it !== SchemaContext.MultipartFormData),
2097
- serializationFormats: schema.serializationFormats,
2197
+ usage: (_a = schema.usage) === null || _a === void 0 ? void 0 : _a.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.Anonymous),
2198
+ serializationFormats: (_b = schema.serializationFormats) === null || _b === void 0 ? void 0 : _b.filter((it) => it !== KnownMediaType.Multipart),
2098
2199
  };
2099
2200
  // Propagate the usage of the initial schema itself
2100
2201
  innerPropagateSchemaUsage(schema, schemaUsage);
@@ -2109,6 +2210,9 @@ export class CodeModelBuilder {
2109
2210
  if (schemaUsage.usage) {
2110
2211
  pushDistinct((schema.usage = schema.usage || []), ...schemaUsage.usage);
2111
2212
  }
2213
+ if (schemaUsage.serializationFormats) {
2214
+ pushDistinct((schema.serializationFormats = schema.serializationFormats || []), ...schemaUsage.serializationFormats);
2215
+ }
2112
2216
  }
2113
2217
  else if (schema instanceof DictionarySchema) {
2114
2218
  this.trackSchemaUsage(schema.elementType, schemaUsage);
@@ -2119,7 +2223,10 @@ export class CodeModelBuilder {
2119
2223
  }
2120
2224
  isArmLongRunningOperation(program, op) {
2121
2225
  var _a;
2122
- return this.codeModel.arm && Boolean((_a = getExtensions(program, op)) === null || _a === void 0 ? void 0 : _a.get("x-ms-long-running-operation"));
2226
+ return this.isArm() && Boolean((_a = getExtensions(program, op)) === null || _a === void 0 ? void 0 : _a.get("x-ms-long-running-operation"));
2227
+ }
2228
+ isArm() {
2229
+ return this.codeModel.arm;
2123
2230
  }
2124
2231
  isSchemaUsageEmpty(schema) {
2125
2232
  if (schema instanceof ObjectSchema ||