@azure-tools/typespec-java 0.15.6 → 0.15.8
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.
- package/dist/src/code-model-builder.d.ts +6 -0
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +65 -30
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/emitter.d.ts +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +1 -0
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/type-utils.d.ts +1 -1
- package/dist/src/type-utils.d.ts.map +1 -1
- package/dist/src/type-utils.js +7 -3
- package/dist/src/type-utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/target/emitter.jar +0 -0
|
@@ -14,6 +14,7 @@ export declare class CodeModelBuilder {
|
|
|
14
14
|
readonly schemaCache: ProcessingCache<Type, Schema>;
|
|
15
15
|
readonly typeUnionRefCache: Map<Type, Union | null | undefined>;
|
|
16
16
|
private operationExamples;
|
|
17
|
+
private apiVersion;
|
|
17
18
|
constructor(program1: Program, context: EmitContext<EmitterOptions>);
|
|
18
19
|
build(): Promise<CodeModel>;
|
|
19
20
|
private processHost;
|
|
@@ -35,6 +36,11 @@ export declare class CodeModelBuilder {
|
|
|
35
36
|
*/
|
|
36
37
|
private isArmSynthesizedServer;
|
|
37
38
|
private needToSkipProcessingOperation;
|
|
39
|
+
private existsAtCurrentVersion;
|
|
40
|
+
/**
|
|
41
|
+
* Whether we support advanced versioning in non-breaking fashion.
|
|
42
|
+
*/
|
|
43
|
+
private supportsAdvancedVersioning;
|
|
38
44
|
private processOperation;
|
|
39
45
|
private processRouteForPaged;
|
|
40
46
|
private processLroMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAoBL,OAA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zC;IAED,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,uBAAuB;IAyB/B,OAAO,CAAC,sBAAsB,CAAC,CAAY;IAE3C,OAAO,CAAC,oBAAoB;IAuE5B,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,kBAAkB;CAiB3B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getDoc, getEffectiveModelType, getFormat, getFriendlyName, getKnownValues, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isRecordModelType, isUnknownType, getDiscriminator, isNeverType, listServices, getNamespaceFullName, isNullType, getTypeName, getProjectedName, getEncode, getOverloadedOperation, walkPropertiesInherited, isVoidType, isErrorModel, } 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
|
-
import { getAddedOnVersions, getVersion } from "@typespec/versioning";
|
|
4
|
+
import { Availability, getAddedOnVersions, getAvailabilityMap, getVersion } from "@typespec/versioning";
|
|
5
5
|
import { isPollingLocation, getPagedResult, isFixed, getLroMetadata, getUnionAsEnum, } from "@azure-tools/typespec-azure-core";
|
|
6
|
-
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, getClientNameOverride, shouldFlattenProperty, getWireName, } from "@azure-tools/typespec-client-generator-core";
|
|
6
|
+
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, getClientNameOverride, shouldFlattenProperty, getWireName, getDefaultApiVersion, } 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";
|
|
@@ -20,7 +20,7 @@ import { PreNamer } from "./prenamer/prenamer.js";
|
|
|
20
20
|
import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
|
|
21
21
|
import { ClientContext } from "./models.js";
|
|
22
22
|
import { stringArrayContainsIgnoreCase, getJavaNamespace, getNamespace, pascalCase, logWarning, trace, } from "./utils.js";
|
|
23
|
-
import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, getAccess, getUsage, getUnionDescription, modelIs,
|
|
23
|
+
import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, getAccess, getUsage, getUnionDescription, modelIs, getNamePrefixForProperty, isAllValueInteger, } from "./type-utils.js";
|
|
24
24
|
import { getServiceVersion, operationIsJsonMergePatch, isPayloadProperty, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, loadExamples, isLroNewPollingStrategy, operationIsMultipleContentTypes, cloneOperationParameter, operationIsMultipart, isKnownContentType, CONTENT_TYPE_KEY, } from "./operation-utils.js";
|
|
25
25
|
import { isArmCommonType } from "./type-utils.js";
|
|
26
26
|
import pkg from "lodash";
|
|
@@ -85,6 +85,11 @@ export class CodeModelBuilder {
|
|
|
85
85
|
}
|
|
86
86
|
async build() {
|
|
87
87
|
this.operationExamples = await loadExamples(this.program, this.options);
|
|
88
|
+
if (this.sdkContext.arm) {
|
|
89
|
+
// ARM
|
|
90
|
+
this.codeModel.arm = true;
|
|
91
|
+
this.options["group-etag-headers"] = false;
|
|
92
|
+
}
|
|
88
93
|
const clients = this.processClients();
|
|
89
94
|
this.processModels(clients);
|
|
90
95
|
this.processSchemaUsage();
|
|
@@ -327,12 +332,6 @@ export class CodeModelBuilder {
|
|
|
327
332
|
processClients() {
|
|
328
333
|
var _a, _b;
|
|
329
334
|
const clients = listClients(this.sdkContext);
|
|
330
|
-
for (const client of clients) {
|
|
331
|
-
if (client.arm) {
|
|
332
|
-
this.codeModel.arm = true;
|
|
333
|
-
this.options["group-etag-headers"] = false;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
335
|
// preprocess group-etag-headers
|
|
337
336
|
this.options["group-etag-headers"] = (_a = this.options["group-etag-headers"]) !== null && _a !== void 0 ? _a : true;
|
|
338
337
|
for (const client of clients) {
|
|
@@ -352,6 +351,7 @@ export class CodeModelBuilder {
|
|
|
352
351
|
apiVersion.version = version.value;
|
|
353
352
|
codeModelClient.apiVersions.push(apiVersion);
|
|
354
353
|
}
|
|
354
|
+
this.apiVersion = getDefaultApiVersion(this.sdkContext, client.service);
|
|
355
355
|
}
|
|
356
356
|
// server
|
|
357
357
|
let baseUri = "{endpoint}";
|
|
@@ -447,6 +447,9 @@ export class CodeModelBuilder {
|
|
|
447
447
|
return this.isArm() && (!server.parameters || server.parameters.size == 0);
|
|
448
448
|
}
|
|
449
449
|
needToSkipProcessingOperation(operation, clientContext) {
|
|
450
|
+
if (!this.existsAtCurrentVersion(operation)) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
450
453
|
// don't generate protocol and convenience method for overloaded operations
|
|
451
454
|
// issue link: https://github.com/Azure/autorest.java/issues/1958#issuecomment-1562558219 we will support generate overload methods for non-union type in future (TODO issue: https://github.com/Azure/autorest.java/issues/2160)
|
|
452
455
|
if (getOverloadedOperation(this.program, operation)) {
|
|
@@ -455,6 +458,25 @@ export class CodeModelBuilder {
|
|
|
455
458
|
}
|
|
456
459
|
return false;
|
|
457
460
|
}
|
|
461
|
+
existsAtCurrentVersion(type) {
|
|
462
|
+
var _a;
|
|
463
|
+
const availabilityMap = getAvailabilityMap(this.program, type);
|
|
464
|
+
// if unversioned then everything exists
|
|
465
|
+
if (!availabilityMap ||
|
|
466
|
+
!this.apiVersion ||
|
|
467
|
+
this.supportsAdvancedVersioning() // if supports non-breaking versioning, then it always exists
|
|
468
|
+
) {
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
const availability = availabilityMap.get((_a = this.apiVersion) === null || _a === void 0 ? void 0 : _a.name);
|
|
472
|
+
return availability === Availability.Added || availability === Availability.Available;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Whether we support advanced versioning in non-breaking fashion.
|
|
476
|
+
*/
|
|
477
|
+
supportsAdvancedVersioning() {
|
|
478
|
+
return Boolean(this.options["advanced-versioning"]);
|
|
479
|
+
}
|
|
458
480
|
processOperation(groupName, operation, clientContext) {
|
|
459
481
|
var _a, _b, _c;
|
|
460
482
|
const op = ignoreDiagnostics(getHttpOperation(this.program, operation));
|
|
@@ -536,7 +558,9 @@ export class CodeModelBuilder {
|
|
|
536
558
|
// host
|
|
537
559
|
clientContext.hostParameters.forEach((it) => codeModelOperation.addParameter(it));
|
|
538
560
|
// parameters
|
|
539
|
-
op.parameters.parameters
|
|
561
|
+
op.parameters.parameters
|
|
562
|
+
.filter((param) => this.existsAtCurrentVersion(param.param))
|
|
563
|
+
.map((it) => this.processParameter(codeModelOperation, it, clientContext));
|
|
540
564
|
// "accept" header
|
|
541
565
|
this.addAcceptHeaderParameter(codeModelOperation, op.responses);
|
|
542
566
|
// body
|
|
@@ -696,13 +720,13 @@ export class CodeModelBuilder {
|
|
|
696
720
|
}
|
|
697
721
|
}
|
|
698
722
|
processParameter(op, param, clientContext) {
|
|
699
|
-
var _a;
|
|
723
|
+
var _a, _b;
|
|
700
724
|
if (clientContext.apiVersions && isApiVersion(this.sdkContext, param)) {
|
|
701
725
|
// pre-condition for "isApiVersion": the client supports ApiVersions
|
|
702
726
|
if (this.isArm()) {
|
|
703
727
|
// Currently we assume ARM tsp only have one client and one api-version.
|
|
704
728
|
// TODO: How will service define mixed api-versions(like those in Compute RP)?
|
|
705
|
-
const apiVersion =
|
|
729
|
+
const apiVersion = (_a = this.apiVersion) === null || _a === void 0 ? void 0 : _a.value;
|
|
706
730
|
if (!this._armApiVersionParameter) {
|
|
707
731
|
this._armApiVersionParameter = this.createApiVersionParameter("api-version", param.type === "query" ? ParameterLocation.Query : ParameterLocation.Path, apiVersion);
|
|
708
732
|
clientContext.addGlobalParameter(this._armApiVersionParameter);
|
|
@@ -722,7 +746,7 @@ export class CodeModelBuilder {
|
|
|
722
746
|
}
|
|
723
747
|
else if (SPECIAL_HEADER_NAMES.has(param.name.toLowerCase())) {
|
|
724
748
|
// special headers
|
|
725
|
-
op.specialHeaders = (
|
|
749
|
+
op.specialHeaders = (_b = op.specialHeaders) !== null && _b !== void 0 ? _b : [];
|
|
726
750
|
if (!stringArrayContainsIgnoreCase(op.specialHeaders, param.name)) {
|
|
727
751
|
op.specialHeaders.push(param.name);
|
|
728
752
|
}
|
|
@@ -748,8 +772,7 @@ export class CodeModelBuilder {
|
|
|
748
772
|
schema instanceof UriSchema) {
|
|
749
773
|
extensions = { "x-ms-skip-url-encoding": true };
|
|
750
774
|
}
|
|
751
|
-
|
|
752
|
-
if (this.options["dev-options"] && this.options["dev-options"]["support-versioning"]) {
|
|
775
|
+
if (this.supportsAdvancedVersioning()) {
|
|
753
776
|
// versioning
|
|
754
777
|
const addedOn = getAddedOnVersions(this.program, param.param);
|
|
755
778
|
if (addedOn) {
|
|
@@ -1332,7 +1355,7 @@ export class CodeModelBuilder {
|
|
|
1332
1355
|
else {
|
|
1333
1356
|
const schemaNameHint = type.type.kind === "Scalar" && this.program.checker.isStdType(type.type)
|
|
1334
1357
|
? nameHint // std scalar won't need a nameHint
|
|
1335
|
-
: pascalCase(
|
|
1358
|
+
: pascalCase(getNamePrefixForProperty(type)) + pascalCase(nameHint);
|
|
1336
1359
|
schema = this.processSchema(type.type, schemaNameHint);
|
|
1337
1360
|
}
|
|
1338
1361
|
return this.applyModelPropertyDecorators(type, nameHint, schema);
|
|
@@ -1775,7 +1798,8 @@ export class CodeModelBuilder {
|
|
|
1775
1798
|
for (const prop of type.properties.values()) {
|
|
1776
1799
|
if (prop.name === discriminatorPropertyName || // skip the discriminator property
|
|
1777
1800
|
isNeverType(prop.type) || // skip property of type "never"
|
|
1778
|
-
!isPayloadProperty(this.program, prop)
|
|
1801
|
+
!isPayloadProperty(this.program, prop) ||
|
|
1802
|
+
!this.existsAtCurrentVersion(prop)) {
|
|
1779
1803
|
continue;
|
|
1780
1804
|
}
|
|
1781
1805
|
objectSchema.addProperty(this.processModelProperty(prop));
|
|
@@ -1807,7 +1831,9 @@ export class CodeModelBuilder {
|
|
|
1807
1831
|
const resource = this.dummyObjectSchema(type, resourceModelName, namespace);
|
|
1808
1832
|
const declaredProperties = walkPropertiesInherited(type);
|
|
1809
1833
|
for (const prop of declaredProperties) {
|
|
1810
|
-
|
|
1834
|
+
if (this.existsAtCurrentVersion(type)) {
|
|
1835
|
+
resource.addProperty(this.processModelProperty(prop));
|
|
1836
|
+
}
|
|
1811
1837
|
}
|
|
1812
1838
|
return resource;
|
|
1813
1839
|
}
|
|
@@ -1863,27 +1889,36 @@ export class CodeModelBuilder {
|
|
|
1863
1889
|
// }
|
|
1864
1890
|
const format = getFormat(this.program, prop);
|
|
1865
1891
|
if (format) {
|
|
1892
|
+
// TODO: deprecate format
|
|
1866
1893
|
if (prop.type.kind === "Scalar" && schema instanceof StringSchema) {
|
|
1867
1894
|
schema = this.processFormatString(prop.type, format, nameHint);
|
|
1868
1895
|
}
|
|
1869
1896
|
}
|
|
1870
|
-
else
|
|
1897
|
+
else {
|
|
1898
|
+
// encode
|
|
1871
1899
|
const encode = getEncode(this.program, prop);
|
|
1872
1900
|
if (encode) {
|
|
1873
|
-
|
|
1874
|
-
|
|
1901
|
+
let type = prop.type;
|
|
1902
|
+
if (prop.type.kind === "Union" && isNullableType(prop.type)) {
|
|
1903
|
+
const nonNullVariants = Array.from(prop.type.variants.values()).filter((it) => !isNullType(it.type));
|
|
1904
|
+
type = nonNullVariants[0].type;
|
|
1875
1905
|
}
|
|
1876
|
-
|
|
1877
|
-
(
|
|
1878
|
-
|
|
1879
|
-
return this.processUnixTimeSchema(prop.type, nameHint);
|
|
1906
|
+
if (type && type.kind === "Scalar") {
|
|
1907
|
+
if (encode.encoding === "seconds" && hasScalarAsBase(type, "duration")) {
|
|
1908
|
+
schema = this.processDurationSchema(type, nameHint, getDurationFormat(encode));
|
|
1880
1909
|
}
|
|
1881
|
-
else
|
|
1882
|
-
|
|
1910
|
+
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231" || encode.encoding === "unixTimestamp") &&
|
|
1911
|
+
(hasScalarAsBase(type, "utcDateTime") || hasScalarAsBase(type, "offsetDateTime"))) {
|
|
1912
|
+
if (encode.encoding === "unixTimestamp") {
|
|
1913
|
+
return this.processUnixTimeSchema(type, nameHint);
|
|
1914
|
+
}
|
|
1915
|
+
else {
|
|
1916
|
+
return this.processDateTimeSchema(type, nameHint, encode.encoding === "rfc7231");
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
else if (encode.encoding === "base64url" && hasScalarAsBase(type, "bytes")) {
|
|
1920
|
+
return this.processByteArraySchema(type, nameHint, true);
|
|
1883
1921
|
}
|
|
1884
|
-
}
|
|
1885
|
-
else if (encode.encoding === "base64url" && hasScalarAsBase(prop.type, "bytes")) {
|
|
1886
|
-
return this.processByteArraySchema(prop.type, nameHint, true);
|
|
1887
1922
|
}
|
|
1888
1923
|
}
|
|
1889
1924
|
}
|