@azure-tools/typespec-java 0.12.3 → 0.13.1
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 +9 -1
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +40 -26
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/readme.md +1 -1
- package/target/emitter.jar +0 -0
|
@@ -23,6 +23,15 @@ export declare class CodeModelBuilder {
|
|
|
23
23
|
private deduplicateSchemaName;
|
|
24
24
|
private resolveSchemaUsage;
|
|
25
25
|
private processClients;
|
|
26
|
+
/**
|
|
27
|
+
* `@armProviderNamespace` currently will add a default server if not defined globally:
|
|
28
|
+
* https://github.com/Azure/typespec-azure/blob/8b8d7c05f168d9305a09691c4fedcb88f4a57652/packages/typespec-azure-resource-manager/src/namespace.ts#L121-L128
|
|
29
|
+
* TODO: if the synthesized server has the right hostParameter, we can use that insteadß
|
|
30
|
+
*
|
|
31
|
+
* @param server returned by getServers
|
|
32
|
+
* @returns whether it's synthesized by `@armProviderNamespace`
|
|
33
|
+
*/
|
|
34
|
+
private isArmSynthesizedServer;
|
|
26
35
|
private needToSkipProcessingOperation;
|
|
27
36
|
private processOperation;
|
|
28
37
|
private processRouteForPaged;
|
|
@@ -101,7 +110,6 @@ export declare class CodeModelBuilder {
|
|
|
101
110
|
private _subscriptionParameter?;
|
|
102
111
|
private propagateSchemaUsage;
|
|
103
112
|
private trackSchemaUsage;
|
|
104
|
-
private isArmLongRunningOperation;
|
|
105
113
|
private isArm;
|
|
106
114
|
private isSchemaUsageEmpty;
|
|
107
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"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|
|
|
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, } from "@azure-tools/typespec-client-generator-core";
|
|
6
|
+
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, getClientNameOverride, shouldFlattenProperty, } 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";
|
|
@@ -24,7 +24,6 @@ import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContains
|
|
|
24
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
25
|
import { isArmCommonType } from "./type-utils.js";
|
|
26
26
|
import pkg from "lodash";
|
|
27
|
-
import { getExtensions } from "@typespec/openapi";
|
|
28
27
|
const { isEqual } = pkg;
|
|
29
28
|
export class CodeModelBuilder {
|
|
30
29
|
constructor(program1, context) {
|
|
@@ -93,7 +92,7 @@ export class CodeModelBuilder {
|
|
|
93
92
|
}
|
|
94
93
|
processHost(server) {
|
|
95
94
|
const hostParameters = [];
|
|
96
|
-
if (server) {
|
|
95
|
+
if (server && !this.isArmSynthesizedServer(server)) {
|
|
97
96
|
server.parameters.forEach((it) => {
|
|
98
97
|
let parameter;
|
|
99
98
|
if (isApiVersion(this.sdkContext, it)) {
|
|
@@ -347,7 +346,7 @@ export class CodeModelBuilder {
|
|
|
347
346
|
// server
|
|
348
347
|
let baseUri = "{endpoint}";
|
|
349
348
|
const servers = getServers(this.program, client.service);
|
|
350
|
-
if (servers && servers.length === 1) {
|
|
349
|
+
if (servers && servers.length === 1 && !this.isArmSynthesizedServer(servers[0])) {
|
|
351
350
|
baseUri = servers[0].url;
|
|
352
351
|
}
|
|
353
352
|
const hostParameters = this.processHost((servers === null || servers === void 0 ? void 0 : servers.length) === 1 ? servers[0] : undefined);
|
|
@@ -370,19 +369,19 @@ export class CodeModelBuilder {
|
|
|
370
369
|
// operation group with no operation is skipped
|
|
371
370
|
if (operations.length > 0) {
|
|
372
371
|
const groupPath = operationGroup.groupPath.split(".");
|
|
373
|
-
let
|
|
372
|
+
let operationGroupName;
|
|
374
373
|
if (groupPath.length > 1) {
|
|
375
374
|
// groupPath should be in format of "OpenAIClient.Chat.Completions"
|
|
376
|
-
|
|
375
|
+
operationGroupName = groupPath.slice(1).join("");
|
|
377
376
|
}
|
|
378
377
|
else {
|
|
379
378
|
// protection
|
|
380
|
-
|
|
379
|
+
operationGroupName = operationGroup.type.name;
|
|
381
380
|
}
|
|
382
|
-
codeModelGroup = new OperationGroup(
|
|
381
|
+
codeModelGroup = new OperationGroup(operationGroupName);
|
|
383
382
|
for (const operation of operations) {
|
|
384
383
|
if (!this.needToSkipProcessingOperation(operation, clientContext)) {
|
|
385
|
-
codeModelGroup.addOperation(this.processOperation(
|
|
384
|
+
codeModelGroup.addOperation(this.processOperation(operationGroupName, operation, clientContext));
|
|
386
385
|
}
|
|
387
386
|
}
|
|
388
387
|
codeModelClient.operationGroups.push(codeModelGroup);
|
|
@@ -426,6 +425,17 @@ export class CodeModelBuilder {
|
|
|
426
425
|
}
|
|
427
426
|
return clients;
|
|
428
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* `@armProviderNamespace` currently will add a default server if not defined globally:
|
|
430
|
+
* https://github.com/Azure/typespec-azure/blob/8b8d7c05f168d9305a09691c4fedcb88f4a57652/packages/typespec-azure-resource-manager/src/namespace.ts#L121-L128
|
|
431
|
+
* TODO: if the synthesized server has the right hostParameter, we can use that insteadß
|
|
432
|
+
*
|
|
433
|
+
* @param server returned by getServers
|
|
434
|
+
* @returns whether it's synthesized by `@armProviderNamespace`
|
|
435
|
+
*/
|
|
436
|
+
isArmSynthesizedServer(server) {
|
|
437
|
+
return this.isArm() && (!server.parameters || server.parameters.size == 0);
|
|
438
|
+
}
|
|
429
439
|
needToSkipProcessingOperation(operation, clientContext) {
|
|
430
440
|
// don't generate protocol and convenience method for overloaded operations
|
|
431
441
|
// 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)
|
|
@@ -648,7 +658,7 @@ export class CodeModelBuilder {
|
|
|
648
658
|
return new LongRunningMetadata(false);
|
|
649
659
|
}
|
|
650
660
|
processRouteForLongRunning(op, operation, responses, lroMetadata) {
|
|
651
|
-
var _a, _b
|
|
661
|
+
var _a, _b;
|
|
652
662
|
if (lroMetadata.longRunning) {
|
|
653
663
|
op.extensions = (_a = op.extensions) !== null && _a !== void 0 ? _a : {};
|
|
654
664
|
op.extensions["x-ms-long-running-operation"] = true;
|
|
@@ -665,10 +675,6 @@ export class CodeModelBuilder {
|
|
|
665
675
|
}
|
|
666
676
|
}
|
|
667
677
|
}
|
|
668
|
-
if (this.isArmLongRunningOperation(this.program, operation)) {
|
|
669
|
-
op.extensions = (_c = op.extensions) !== null && _c !== void 0 ? _c : {};
|
|
670
|
-
op.extensions["x-ms-long-running-operation"] = true;
|
|
671
|
-
}
|
|
672
678
|
}
|
|
673
679
|
processParameter(op, param, clientContext) {
|
|
674
680
|
var _a;
|
|
@@ -954,7 +960,7 @@ export class CodeModelBuilder {
|
|
|
954
960
|
}
|
|
955
961
|
}
|
|
956
962
|
processParameterBody(op, httpOperation, body) {
|
|
957
|
-
var _a, _b, _c;
|
|
963
|
+
var _a, _b, _c, _d;
|
|
958
964
|
const parameters = httpOperation.operation.parameters;
|
|
959
965
|
const unknownRequestBody = op.requests[0].protocol.http.mediaTypes &&
|
|
960
966
|
op.requests[0].protocol.http.mediaTypes.length > 0 &&
|
|
@@ -993,7 +999,7 @@ export class CodeModelBuilder {
|
|
|
993
999
|
if (op.convenienceApi && operationIsMultipart(httpOperation)) {
|
|
994
1000
|
this.trackSchemaUsage(schema, { serializationFormats: [KnownMediaType.Multipart] });
|
|
995
1001
|
}
|
|
996
|
-
if (!schema.language.default.name
|
|
1002
|
+
if (schema instanceof ObjectSchema && !schema.language.default.name) {
|
|
997
1003
|
// anonymous model
|
|
998
1004
|
// name the schema for documentation
|
|
999
1005
|
schema.language.default.name = op.language.default.name + "Request";
|
|
@@ -1001,6 +1007,11 @@ export class CodeModelBuilder {
|
|
|
1001
1007
|
// name the parameter for documentation
|
|
1002
1008
|
parameter.language.default.name = "request";
|
|
1003
1009
|
}
|
|
1010
|
+
if ((_a = schema.serializationFormats) === null || _a === void 0 ? void 0 : _a.includes(KnownMediaType.Multipart)) {
|
|
1011
|
+
// TODO: anonymous model for multipart is not supported
|
|
1012
|
+
// at present, use the model with name given above
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1004
1015
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.Anonymous] });
|
|
1005
1016
|
if (op.convenienceApi && op.parameters) {
|
|
1006
1017
|
op.convenienceApi.requests = [];
|
|
@@ -1013,13 +1024,13 @@ export class CodeModelBuilder {
|
|
|
1013
1024
|
if (existParameter) {
|
|
1014
1025
|
// parameter
|
|
1015
1026
|
if (existParameter.implementation === ImplementationLocation.Method &&
|
|
1016
|
-
((
|
|
1027
|
+
((_c = (_b = existParameter.origin) === null || _b === void 0 ? void 0 : _b.startsWith("modelerfour:synthesized/")) !== null && _c !== void 0 ? _c : true)) {
|
|
1017
1028
|
request.parameters.push(cloneOperationParameter(existParameter));
|
|
1018
1029
|
}
|
|
1019
1030
|
}
|
|
1020
1031
|
else {
|
|
1021
1032
|
// property from anonymous model
|
|
1022
|
-
const existBodyProperty = (
|
|
1033
|
+
const existBodyProperty = (_d = schema.properties) === null || _d === void 0 ? void 0 : _d.find((it) => it.serializedName === serializedName);
|
|
1023
1034
|
if (existBodyProperty) {
|
|
1024
1035
|
request.parameters.push(new VirtualParameter(existBodyProperty.language.default.name, existBodyProperty.language.default.description, existBodyProperty.schema, {
|
|
1025
1036
|
originalParameter: parameter,
|
|
@@ -1820,12 +1831,15 @@ export class CodeModelBuilder {
|
|
|
1820
1831
|
let nullable = isNullableType(prop.type);
|
|
1821
1832
|
let extensions = undefined;
|
|
1822
1833
|
if (this.isSecret(prop)) {
|
|
1823
|
-
extensions = {
|
|
1824
|
-
|
|
1825
|
-
};
|
|
1834
|
+
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1835
|
+
extensions["x-ms-secret"] = true;
|
|
1826
1836
|
// if the property does not return in response, it had to be nullable
|
|
1827
1837
|
nullable = true;
|
|
1828
1838
|
}
|
|
1839
|
+
if (shouldFlattenProperty(this.sdkContext, prop)) {
|
|
1840
|
+
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1841
|
+
extensions["x-ms-client-flatten"] = true;
|
|
1842
|
+
}
|
|
1829
1843
|
return new Property(this.getName(prop), this.getDoc(prop), schema, {
|
|
1830
1844
|
summary: this.getSummary(prop),
|
|
1831
1845
|
required: !prop.optional,
|
|
@@ -1982,6 +1996,10 @@ export class CodeModelBuilder {
|
|
|
1982
1996
|
}
|
|
1983
1997
|
getName(target, nameHint = undefined) {
|
|
1984
1998
|
// TODO: once getLibraryName API in typespec-client-generator-core can get projected name from language and client, as well as can handle template case, use getLibraryName API
|
|
1999
|
+
const emitterClientName = getClientNameOverride(this.sdkContext, target);
|
|
2000
|
+
if (emitterClientName) {
|
|
2001
|
+
return emitterClientName;
|
|
2002
|
+
}
|
|
1985
2003
|
const languageProjectedName = getProjectedName(this.program, target, "java");
|
|
1986
2004
|
if (languageProjectedName) {
|
|
1987
2005
|
return languageProjectedName;
|
|
@@ -2221,12 +2239,8 @@ export class CodeModelBuilder {
|
|
|
2221
2239
|
this.trackSchemaUsage(schema.elementType, schemaUsage);
|
|
2222
2240
|
}
|
|
2223
2241
|
}
|
|
2224
|
-
isArmLongRunningOperation(program, op) {
|
|
2225
|
-
var _a;
|
|
2226
|
-
return this.isArm() && Boolean((_a = getExtensions(program, op)) === null || _a === void 0 ? void 0 : _a.get("x-ms-long-running-operation"));
|
|
2227
|
-
}
|
|
2228
2242
|
isArm() {
|
|
2229
|
-
return this.codeModel.arm;
|
|
2243
|
+
return Boolean(this.codeModel.arm);
|
|
2230
2244
|
}
|
|
2231
2245
|
isSchemaUsageEmpty(schema) {
|
|
2232
2246
|
if (schema instanceof ObjectSchema ||
|