@azure-tools/typespec-java 0.13.4 → 0.13.6

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.
@@ -61,6 +61,7 @@ export declare class CodeModelBuilder {
61
61
  private processChoiceSchema;
62
62
  private processConstantSchemaForLiteral;
63
63
  private processConstantSchemaForEnumMember;
64
+ private processConstantSchemaForUnionVariant;
64
65
  private processChoiceSchemaForUnion;
65
66
  private processUnixTimeSchema;
66
67
  private processDateTimeSchema;
@@ -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,EAUZ,MAAM,oBAAoB,CAAC;AAmC5B,OAAO,EACL,SAAS,EAIT,aAAa,EAUb,YAAY,EACZ,YAAY,EACZ,SAAS,EAKT,MAAM,EAIN,YAAY,EAeb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAUnD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAW9C,OAAO,EACL,eAAe,EAehB,MAAM,iBAAiB,CAAC;AAmBzB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,SAAS,CAAY;IAE7B,QAAQ,CAAC,WAAW,gCAAyF;IAC7G,QAAQ,CAAC,iBAAiB,sCAA6C;IAEvE,OAAO,CAAC,iBAAiB,CAAkD;gBAExD,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,cAAc,CAAC;IAyD7D,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC;IAkBxC,OAAO,CAAC,WAAW;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AO,CAAC,KAAK;IAIb,OAAO,CAAC,kBAAkB;CAiB3B"}
@@ -1,9 +1,9 @@
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, resolveEncodedName, isVoidType, } 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, isVoidType, } from "@typespec/compiler";
2
2
  import { getResourceOperation, getSegment } from "@typespec/rest";
3
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
- import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, getClientNameOverride, shouldFlattenProperty, } from "@azure-tools/typespec-client-generator-core";
6
+ import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, getClientNameOverride, shouldFlattenProperty, getWireName, } 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
9
  import { KnownMediaType } from "@azure-tools/codegen";
@@ -211,6 +211,7 @@ export class CodeModelBuilder {
211
211
  for (const client of clients) {
212
212
  const models = Array.from(client.service.models.values());
213
213
  Array.from(client.service.enums.values()).forEach((it) => models.push(it));
214
+ Array.from(client.service.unions.values()).forEach((it) => models.push(it));
214
215
  // lambda to mark model as public
215
216
  const modelAsPublic = (model) => {
216
217
  // check it does not contain Union
@@ -222,7 +223,7 @@ export class CodeModelBuilder {
222
223
  // )}' cannot be set as access=public, as it refers Union '${getUnionDescription(union, this.typeNameOptions)}'`;
223
224
  // throw new Error(errorMsg);
224
225
  // }
225
- const schema = this.processSchema(model, model.name);
226
+ const schema = this.processSchema(model, "");
226
227
  this.trackSchemaUsage(schema, {
227
228
  usage: [SchemaContext.Public],
228
229
  });
@@ -234,14 +235,14 @@ export class CodeModelBuilder {
234
235
  modelAsPublic(model);
235
236
  }
236
237
  else if (access === "internal") {
237
- const schema = this.processSchema(model, model.name);
238
+ const schema = this.processSchema(model, "");
238
239
  this.trackSchemaUsage(schema, {
239
240
  usage: [SchemaContext.Internal],
240
241
  });
241
242
  }
242
243
  const usage = getUsage(model);
243
244
  if (usage) {
244
- const schema = this.processSchema(model, model.name);
245
+ const schema = this.processSchema(model, "");
245
246
  this.trackSchemaUsage(schema, {
246
247
  usage: usage,
247
248
  });
@@ -1109,27 +1110,35 @@ export class CodeModelBuilder {
1109
1110
  processResponse(op, resp, candidateResponseSchema = undefined) {
1110
1111
  var _a, _b, _c, _d, _e, _f;
1111
1112
  // TODO: what to do if more than 1 response?
1113
+ // It happens when the response type is Union, on one status code.
1112
1114
  let response;
1113
1115
  let headers = undefined;
1114
- if (resp.responses && resp.responses.length > 0 && resp.responses[0].headers) {
1116
+ if (resp.responses && resp.responses.length > 0) {
1115
1117
  // headers
1116
1118
  headers = [];
1117
- for (const [key, header] of Object.entries(resp.responses[0].headers)) {
1118
- const schema = this.processSchema(header, key);
1119
- headers.push(new HttpHeader(key, schema, {
1120
- language: {
1121
- default: {
1122
- name: key,
1123
- description: this.getDoc(header),
1124
- },
1125
- },
1126
- }));
1119
+ for (const response of resp.responses.values()) {
1120
+ if (response.headers) {
1121
+ for (const [key, header] of Object.entries(response.headers)) {
1122
+ const schema = this.processSchema(header, key);
1123
+ headers.push(new HttpHeader(key, schema, {
1124
+ language: {
1125
+ default: {
1126
+ name: key,
1127
+ description: this.getDoc(header),
1128
+ },
1129
+ },
1130
+ }));
1131
+ }
1132
+ }
1127
1133
  }
1128
1134
  }
1135
+ let responseBody = undefined;
1129
1136
  let bodyType = undefined;
1130
1137
  let trackConvenienceApi = (_a = op.convenienceApi) !== null && _a !== void 0 ? _a : false;
1131
1138
  if (resp.responses && resp.responses.length > 0 && resp.responses[0].body) {
1132
- const responseBody = resp.responses[0].body;
1139
+ responseBody = resp.responses[0].body;
1140
+ }
1141
+ if (responseBody) {
1133
1142
  const unknownResponseBody = responseBody.contentTypes.length > 0 && !isKnownContentType(responseBody.contentTypes);
1134
1143
  bodyType = this.findResponseBody(responseBody.type);
1135
1144
  if (unknownResponseBody && bodyType.kind === "Scalar" && bodyType.name === "bytes") {
@@ -1287,7 +1296,6 @@ export class CodeModelBuilder {
1287
1296
  case "String":
1288
1297
  return this.processConstantSchemaForLiteral(type, nameHint);
1289
1298
  case "Number":
1290
- // TODO: float
1291
1299
  return this.processConstantSchemaForLiteral(type, nameHint);
1292
1300
  case "Boolean":
1293
1301
  return this.processConstantSchemaForLiteral(type, nameHint);
@@ -1326,6 +1334,14 @@ export class CodeModelBuilder {
1326
1334
  case "EnumMember":
1327
1335
  // e.g. "type: TypeEnum.EnumValue1"
1328
1336
  return this.processConstantSchemaForEnumMember(type, this.getName(type));
1337
+ case "UnionVariant":
1338
+ // e.g. "type: Union.Variant1"
1339
+ if (type.type.kind === "String" || type.type.kind === "Number" || type.type.kind === "Boolean") {
1340
+ return this.processConstantSchemaForUnionVariant(type, this.getName(type));
1341
+ }
1342
+ else {
1343
+ throw new Error(`Unsupported type reference to UnionVariant.`);
1344
+ }
1329
1345
  }
1330
1346
  throw new Error(`Unrecognized type: '${type.kind}'.`);
1331
1347
  }
@@ -1523,6 +1539,15 @@ export class CodeModelBuilder {
1523
1539
  value: new ConstantValue((_a = type.value) !== null && _a !== void 0 ? _a : type.name),
1524
1540
  }));
1525
1541
  }
1542
+ processConstantSchemaForUnionVariant(type, name) {
1543
+ var _a;
1544
+ const valueType = this.processSchema(type.union, this.getName(type.union));
1545
+ return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
1546
+ summary: this.getSummary(type),
1547
+ valueType: valueType,
1548
+ value: new ConstantValue((_a = type.type.value) !== null && _a !== void 0 ? _a : type.name),
1549
+ }));
1550
+ }
1526
1551
  processChoiceSchemaForUnion(type, variants, name) {
1527
1552
  // variants is Literal
1528
1553
  const kindSet = new Set(variants.map((it) => it.type.kind));
@@ -1591,7 +1616,7 @@ export class CodeModelBuilder {
1591
1616
  }));
1592
1617
  }
1593
1618
  processObjectSchema(type, name) {
1594
- var _a, _b;
1619
+ var _a, _b, _c;
1595
1620
  const namespace = getNamespace(type);
1596
1621
  if ((this.isArm() &&
1597
1622
  (namespace === null || namespace === void 0 ? void 0 : namespace.startsWith("Azure.ResourceManager")) &&
@@ -1697,20 +1722,27 @@ export class CodeModelBuilder {
1697
1722
  const parentWithDiscriminator = objectSchema.parents.all.find((it) => it instanceof ObjectSchema && it.discriminator);
1698
1723
  if (parentWithDiscriminator) {
1699
1724
  discriminatorPropertyName = parentWithDiscriminator.discriminator.propertyName;
1700
- const discriminatorProperty = Array.from(type.properties.values()).find((it) => it.name === discriminatorPropertyName && (it.type.kind === "String" || it.type.kind === "EnumMember"));
1725
+ const discriminatorProperty = Array.from(type.properties.values()).find((it) => it.name === discriminatorPropertyName &&
1726
+ (it.type.kind === "String" || it.type.kind === "EnumMember" || it.type.kind === "UnionVariant"));
1701
1727
  if (discriminatorProperty) {
1702
1728
  if (discriminatorProperty.type.kind === "String") {
1703
- // value of StringLiteral of the discriminator property
1729
+ // value as StringLiteral
1704
1730
  objectSchema.discriminatorValue = discriminatorProperty.type.value;
1705
1731
  }
1706
1732
  else if (discriminatorProperty.type.kind === "EnumMember") {
1707
- // value of EnumMember of the discriminator property
1708
- // lint requires value be string, not number
1733
+ // value as EnumMember
1734
+ // lint requires value be string
1709
1735
  objectSchema.discriminatorValue =
1710
1736
  (_a = discriminatorProperty.type.value) !== null && _a !== void 0 ? _a : discriminatorProperty.type.name;
1711
1737
  }
1738
+ else if (discriminatorProperty.type.kind === "UnionVariant") {
1739
+ // value as UnionVariant
1740
+ objectSchema.discriminatorValue =
1741
+ (_b = discriminatorProperty.type.type.value) !== null && _b !== void 0 ? _b : discriminatorProperty.type.name;
1742
+ }
1712
1743
  }
1713
1744
  else {
1745
+ // it is possible that the property is Union, e.g. 'kind: "type1" | "type2"'; but such Type appears not to be a concrete model.
1714
1746
  // fallback to name of the Model
1715
1747
  objectSchema.discriminatorValue = name;
1716
1748
  }
@@ -1726,7 +1758,7 @@ export class CodeModelBuilder {
1726
1758
  objectSchema.addProperty(this.processModelProperty(prop));
1727
1759
  }
1728
1760
  // process all children
1729
- (_b = type.derivedModels) === null || _b === void 0 ? void 0 : _b.filter(modelContainsDerivedModel).forEach((it) => this.processSchema(it, this.getName(it)));
1761
+ (_c = type.derivedModels) === null || _c === void 0 ? void 0 : _c.filter(modelContainsDerivedModel).forEach((it) => this.processSchema(it, this.getName(it)));
1730
1762
  return objectSchema;
1731
1763
  }
1732
1764
  getEffectiveSchemaType(type) {
@@ -1929,6 +1961,7 @@ export class CodeModelBuilder {
1929
1961
  }));
1930
1962
  }
1931
1963
  getUnionVariantName(type, option) {
1964
+ var _a;
1932
1965
  switch (type.kind) {
1933
1966
  case "Scalar": {
1934
1967
  const scalarName = type.name;
@@ -1977,6 +2010,8 @@ export class CodeModelBuilder {
1977
2010
  return pascalCase(type.valueAsString);
1978
2011
  case "Boolean":
1979
2012
  return pascalCase(type.value ? "True" : "False");
2013
+ case "Union":
2014
+ return (_a = type.name) !== null && _a !== void 0 ? _a : "Union";
1980
2015
  default:
1981
2016
  throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
1982
2017
  }
@@ -2036,17 +2071,14 @@ export class CodeModelBuilder {
2036
2071
  this.logWarning(`Rename anonymous TypeSpec ${target.kind} to '${newName}'`);
2037
2072
  return newName;
2038
2073
  }
2074
+ if (typeof target.name === "symbol") {
2075
+ return "";
2076
+ }
2039
2077
  return target.name || "";
2040
2078
  }
2041
2079
  getSerializedName(target) {
2042
- // First get projected name, if not found, call resolveEncodedName
2043
- // TODO: deprecate getProjectedName
2044
- const jsonProjectedName = getProjectedName(this.program, target, "json");
2045
- if (jsonProjectedName) {
2046
- return jsonProjectedName;
2047
- }
2048
- // TODO: the MIME better be from SchemaUsage.serializationFormats. However, at this step, the values is not propagated to inner models.
2049
- return resolveEncodedName(this.program, target, "application/json");
2080
+ // TODO: currently this is only for JSON
2081
+ return getWireName(this.sdkContext, target);
2050
2082
  }
2051
2083
  isReadOnly(target) {
2052
2084
  // const key = isKey(this.program, target);