@azure-tools/typespec-java 0.7.2 → 0.7.4
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 +4 -3
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +107 -120
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/common/operation.d.ts +1 -10
- package/dist/src/common/operation.d.ts.map +1 -1
- package/dist/src/common/operation.js +0 -5
- package/dist/src/common/operation.js.map +1 -1
- package/dist/src/emitter.d.ts +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/models.d.ts +5 -2
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/models.js +19 -1
- package/dist/src/models.js.map +1 -1
- package/dist/src/operation-utils.d.ts +17 -0
- package/dist/src/operation-utils.d.ts.map +1 -0
- package/dist/src/operation-utils.js +160 -0
- package/dist/src/operation-utils.js.map +1 -0
- package/dist/src/type-utils.d.ts +31 -0
- package/dist/src/type-utils.d.ts.map +1 -0
- package/dist/src/type-utils.js +112 -0
- package/dist/src/type-utils.js.map +1 -0
- package/dist/src/utils.d.ts +3 -44
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +11 -246
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/target/azure-typespec-extension-jar-with-dependencies.jar +0 -0
|
@@ -3,7 +3,7 @@ import { AnySchema, BooleanSchema, NumberSchema, ObjectSchema, Parameter, Schema
|
|
|
3
3
|
import { CodeModel } from "./common/code-model.js";
|
|
4
4
|
import { Operation as CodeModelOperation } from "./common/operation.js";
|
|
5
5
|
import { EmitterOptions } from "./emitter.js";
|
|
6
|
-
import { ProcessingCache } from "./utils.js";
|
|
6
|
+
import { ProcessingCache } from "./type-utils.js";
|
|
7
7
|
export declare class CodeModelBuilder {
|
|
8
8
|
private program;
|
|
9
9
|
private typeNameOptions;
|
|
@@ -19,6 +19,7 @@ export declare class CodeModelBuilder {
|
|
|
19
19
|
private processHost;
|
|
20
20
|
private processAuth;
|
|
21
21
|
private processClients;
|
|
22
|
+
private needToSkipProcessingOperation;
|
|
22
23
|
private processOperation;
|
|
23
24
|
private processRouteForPaged;
|
|
24
25
|
private processLroMetadata;
|
|
@@ -44,6 +45,7 @@ export declare class CodeModelBuilder {
|
|
|
44
45
|
private processChoiceSchema;
|
|
45
46
|
private processChoiceSchemaForLiteral;
|
|
46
47
|
private processChoiceSchemaForUnion;
|
|
48
|
+
private processUnixTimeSchema;
|
|
47
49
|
private processDateTimeSchema;
|
|
48
50
|
private processDateSchema;
|
|
49
51
|
private processTimeSchema;
|
|
@@ -57,8 +59,6 @@ export declare class CodeModelBuilder {
|
|
|
57
59
|
private processUnionSchema;
|
|
58
60
|
private processBinarySchema;
|
|
59
61
|
private getUnionVariantName;
|
|
60
|
-
private isNullableType;
|
|
61
|
-
private isSameLiteralTypes;
|
|
62
62
|
private getDefaultValue;
|
|
63
63
|
private getDoc;
|
|
64
64
|
private getSummary;
|
|
@@ -68,6 +68,7 @@ export declare class CodeModelBuilder {
|
|
|
68
68
|
private isSecret;
|
|
69
69
|
private getConvenienceApiName;
|
|
70
70
|
private logWarning;
|
|
71
|
+
private trace;
|
|
71
72
|
private _stringSchema?;
|
|
72
73
|
get stringSchema(): StringSchema;
|
|
73
74
|
private _integerSchema?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAmBL,SAAS,EACT,OAAO,EAGP,IAAI,
|
|
1
|
+
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAmBL,SAAS,EACT,OAAO,EAGP,IAAI,EAWJ,WAAW,EAMZ,MAAM,oBAAoB,CAAC;AA8B5B,OAAO,EACL,SAAS,EA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/B,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED,OAAO,CAAC,iBAAiB,CAAC,CAAe;IACzC,IAAI,gBAAgB,IAAI,YAAY,CAKnC;IAED,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,oBAAoB,CAAC,CAAY;IACzC,IAAI,mBAAmB,IAAI,SAAS,CAKnC;IAED,OAAO,CAAC,0BAA0B,CAAC,CAAY;IAC/C,IAAI,yBAAyB,IAAI,SAAS,CAMzC;IAED,OAAO,CAAC,oBAAoB;IA6D5B,OAAO,CAAC,gBAAgB;CAkBzB"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { getDoc, getEffectiveModelType, getFormat, getFriendlyName, getKnownValues, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isRecordModelType, isUnknownType, getDiscriminator, isNeverType, listServices, getNamespaceFullName, isNullType,
|
|
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";
|
|
2
2
|
import { getResourceOperation, getSegment } from "@typespec/rest";
|
|
3
3
|
import { getAuthentication, getServers, getStatusCodeDescription, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, } from "@typespec/http";
|
|
4
|
-
import { getVersion } from "@typespec/versioning";
|
|
5
|
-
import { isPollingLocation, getPagedResult,
|
|
4
|
+
import { getAddedOnVersions, getVersion } from "@typespec/versioning";
|
|
5
|
+
import { isPollingLocation, getPagedResult, isFixed, getLroMetadata } from "@azure-tools/typespec-azure-core";
|
|
6
6
|
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, } from "@azure-tools/typespec-client-generator-core";
|
|
7
7
|
import { fail } from "assert";
|
|
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, } from "@autorest/codemodel";
|
|
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, } from "@autorest/codemodel";
|
|
9
9
|
import { CodeModel } from "./common/code-model.js";
|
|
10
10
|
import { Client as CodeModelClient } from "./common/client.js";
|
|
11
|
-
import { ConvenienceApi, Operation as CodeModelOperation,
|
|
11
|
+
import { ConvenienceApi, Operation as CodeModelOperation, Request } from "./common/operation.js";
|
|
12
12
|
import { SchemaContext } from "./common/schemas/usage.js";
|
|
13
13
|
import { ChoiceSchema, SealedChoiceSchema } from "./common/schemas/choice.js";
|
|
14
14
|
import { ConstantSchema, ConstantValue } from "./common/schemas/constant.js";
|
|
@@ -18,7 +18,9 @@ import { DurationSchema } from "./common/schemas/time.js";
|
|
|
18
18
|
import { PreNamer } from "./prenamer/prenamer.js";
|
|
19
19
|
import { createPollResultSchema } from "./external-schemas.js";
|
|
20
20
|
import { ClientContext } from "./models.js";
|
|
21
|
-
import {
|
|
21
|
+
import { stringArrayContainsIgnoreCase, getJavaNamespace, getNamespace, pascalCase, logWarning, trace, } from "./utils.js";
|
|
22
|
+
import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, isSameLiteralTypes, } from "./type-utils.js";
|
|
23
|
+
import { getClientApiVersions, getServiceVersion, operationContainsJsonMergePatch, isPayloadProperty, originApiVersion, specialHeaderNames, loadExamples, isLroNewPollingStrategy, operationIsMultipleContentTypes, } from "./operation-utils.js";
|
|
22
24
|
import pkg from "lodash";
|
|
23
25
|
const { isEqual } = pkg;
|
|
24
26
|
export class CodeModelBuilder {
|
|
@@ -158,7 +160,17 @@ export class CodeModelBuilder {
|
|
|
158
160
|
break;
|
|
159
161
|
case "http":
|
|
160
162
|
{
|
|
161
|
-
|
|
163
|
+
const schemeOrApiKeyPrefix = scheme.scheme;
|
|
164
|
+
if (schemeOrApiKeyPrefix === "basic" || schemeOrApiKeyPrefix === "bearer") {
|
|
165
|
+
this.logWarning(`{scheme.scheme} auth method is currently not supported.`);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const keyScheme = new KeySecurityScheme({
|
|
169
|
+
name: "authorization",
|
|
170
|
+
});
|
|
171
|
+
keyScheme.prefix = schemeOrApiKeyPrefix; // TODO (weidxu): modify KeySecurityScheme, after design stable
|
|
172
|
+
securitySchemes.push(keyScheme);
|
|
173
|
+
}
|
|
162
174
|
}
|
|
163
175
|
break;
|
|
164
176
|
}
|
|
@@ -211,12 +223,14 @@ export class CodeModelBuilder {
|
|
|
211
223
|
}
|
|
212
224
|
const hostParameters = this.processHost((servers === null || servers === void 0 ? void 0 : servers.length) === 1 ? servers[0] : undefined);
|
|
213
225
|
codeModelClient.addGlobalParameters(hostParameters);
|
|
214
|
-
const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters);
|
|
226
|
+
const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters, codeModelClient.apiVersions);
|
|
215
227
|
const operationGroups = listOperationGroups(this.sdkContext, client);
|
|
216
228
|
const operationWithoutGroup = listOperationsInOperationGroup(this.sdkContext, client);
|
|
217
229
|
let codeModelGroup = new OperationGroup("");
|
|
218
230
|
for (const operation of operationWithoutGroup) {
|
|
219
|
-
|
|
231
|
+
if (!this.needToSkipProcessingOperation(operation)) {
|
|
232
|
+
codeModelGroup.addOperation(this.processOperation("", operation, clientContext));
|
|
233
|
+
}
|
|
220
234
|
}
|
|
221
235
|
if (((_a = codeModelGroup.operations) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
222
236
|
codeModelClient.operationGroups.push(codeModelGroup);
|
|
@@ -225,7 +239,9 @@ export class CodeModelBuilder {
|
|
|
225
239
|
const operations = listOperationsInOperationGroup(this.sdkContext, operationGroup);
|
|
226
240
|
codeModelGroup = new OperationGroup(operationGroup.type.name);
|
|
227
241
|
for (const operation of operations) {
|
|
228
|
-
|
|
242
|
+
if (!this.needToSkipProcessingOperation(operation)) {
|
|
243
|
+
codeModelGroup.addOperation(this.processOperation(operationGroup.type.name, operation, clientContext));
|
|
244
|
+
}
|
|
229
245
|
}
|
|
230
246
|
codeModelClient.operationGroups.push(codeModelGroup);
|
|
231
247
|
}
|
|
@@ -266,7 +282,15 @@ export class CodeModelBuilder {
|
|
|
266
282
|
}
|
|
267
283
|
}
|
|
268
284
|
}
|
|
269
|
-
|
|
285
|
+
needToSkipProcessingOperation(operation) {
|
|
286
|
+
// don't generate protocol and convenience method for overloaded operations
|
|
287
|
+
// 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)
|
|
288
|
+
if (getOverloadedOperation(this.program, operation)) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
processOperation(groupName, operation, clientContext) {
|
|
270
294
|
var _a, _b, _c;
|
|
271
295
|
const op = ignoreDiagnostics(getHttpOperation(this.program, operation));
|
|
272
296
|
const operationGroup = this.codeModel.getOperationGroup(groupName);
|
|
@@ -282,8 +306,16 @@ export class CodeModelBuilder {
|
|
|
282
306
|
: undefined,
|
|
283
307
|
},
|
|
284
308
|
});
|
|
285
|
-
if (
|
|
309
|
+
if (operationContainsJsonMergePatch(op)) {
|
|
286
310
|
// do not generate convenience method for JSON Merge Patch
|
|
311
|
+
this.trace(`Operation '${op.operation.name}' contains 'application/merge-patch+json'`);
|
|
312
|
+
}
|
|
313
|
+
else if (operationIsMultipleContentTypes(op)) {
|
|
314
|
+
// and multiple content types
|
|
315
|
+
// issue link: https://github.com/Azure/autorest.java/issues/1958#issuecomment-1562558219
|
|
316
|
+
this.trace(`Operation '${op.operation.name}' is multiple content-type`);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
287
319
|
const convenienceApiName = this.getConvenienceApiName(operation);
|
|
288
320
|
if (convenienceApiName && !isInternal(this.sdkContext, operation)) {
|
|
289
321
|
codeModelOperation.convenienceApi = new ConvenienceApi(convenienceApiName);
|
|
@@ -292,10 +324,6 @@ export class CodeModelBuilder {
|
|
|
292
324
|
// check for generating protocol api or not
|
|
293
325
|
codeModelOperation.generateProtocolApi =
|
|
294
326
|
shouldGenerateProtocol(this.sdkContext, operation) && !isInternal(this.sdkContext, operation);
|
|
295
|
-
if (!fromLinkedOperation) {
|
|
296
|
-
// cache for later reference from operationLinks
|
|
297
|
-
this.operationCache.set(operation, codeModelOperation);
|
|
298
|
-
}
|
|
299
327
|
codeModelOperation.addRequest(new Request({
|
|
300
328
|
protocol: {
|
|
301
329
|
http: {
|
|
@@ -336,10 +364,8 @@ export class CodeModelBuilder {
|
|
|
336
364
|
}
|
|
337
365
|
}
|
|
338
366
|
}
|
|
339
|
-
//
|
|
340
|
-
const lroMetadata =
|
|
341
|
-
? new LongRunningMetadata(false)
|
|
342
|
-
: this.processLroMetadata(codeModelOperation, groupName, op, clientContext);
|
|
367
|
+
// lro metadata
|
|
368
|
+
const lroMetadata = this.processLroMetadata(codeModelOperation, op);
|
|
343
369
|
// responses
|
|
344
370
|
const candidateResponseSchema = lroMetadata.pollResultType; // candidate: response body type of pollingOperation
|
|
345
371
|
op.responses.map((it) => this.processResponse(codeModelOperation, it, candidateResponseSchema));
|
|
@@ -375,23 +401,18 @@ export class CodeModelBuilder {
|
|
|
375
401
|
}
|
|
376
402
|
}
|
|
377
403
|
}
|
|
378
|
-
processLroMetadata(op,
|
|
379
|
-
var _a;
|
|
404
|
+
processLroMetadata(op, httpOperation) {
|
|
380
405
|
const operation = httpOperation.operation;
|
|
381
|
-
let pollingSchema = undefined;
|
|
382
|
-
let finalSchema = undefined;
|
|
383
|
-
let pollingFoundInOperationLinks = false;
|
|
384
406
|
const lroMetadata = getLroMetadata(this.program, operation);
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
lroMetadata.statusMonitorStep &&
|
|
390
|
-
isLroMetadataSupported(operation, lroMetadata)) {
|
|
407
|
+
// needs lroMetadata.statusMonitorStep, as getLroMetadata would return for @pollingOperation operation
|
|
408
|
+
if (lroMetadata && lroMetadata.pollingInfo && lroMetadata.statusMonitorStep) {
|
|
409
|
+
let pollingSchema = undefined;
|
|
410
|
+
let finalSchema = undefined;
|
|
391
411
|
const verb = httpOperation.verb;
|
|
392
412
|
const useNewPollStrategy = isLroNewPollingStrategy(operation, lroMetadata);
|
|
393
413
|
let pollingStrategy = undefined;
|
|
394
414
|
if (useNewPollStrategy) {
|
|
415
|
+
// use new experimental OperationLocationPollingStrategy
|
|
395
416
|
pollingStrategy = new Metadata({
|
|
396
417
|
language: {
|
|
397
418
|
java: {
|
|
@@ -407,19 +428,16 @@ export class CodeModelBuilder {
|
|
|
407
428
|
pollingSchema = this.pollResultSchema;
|
|
408
429
|
}
|
|
409
430
|
else {
|
|
410
|
-
if (lroMetadata.
|
|
411
|
-
getNamespace(lroMetadata.
|
|
431
|
+
if (lroMetadata.pollingInfo.responseModel.name === "OperationStatus" &&
|
|
432
|
+
getNamespace(lroMetadata.pollingInfo.responseModel) === "Azure.Core.Foundations") {
|
|
412
433
|
pollingSchema = this.pollResultSchema;
|
|
413
434
|
}
|
|
414
435
|
else {
|
|
415
|
-
pollingSchema = this.processSchema(lroMetadata.
|
|
436
|
+
pollingSchema = this.processSchema(lroMetadata.pollingInfo.responseModel, "pollResult");
|
|
416
437
|
}
|
|
417
438
|
}
|
|
418
439
|
// finalSchema
|
|
419
|
-
if (
|
|
420
|
-
finalSchema = this.processSchema(lroMetadata.finalStep.responseModel, "finalResult");
|
|
421
|
-
}
|
|
422
|
-
else if (verb !== "delete" && lroMetadata.logicalResult) {
|
|
440
|
+
if (verb !== "delete" && lroMetadata.logicalResult) {
|
|
423
441
|
finalSchema = this.processSchema(lroMetadata.logicalResult, "finalResult");
|
|
424
442
|
}
|
|
425
443
|
// track usage
|
|
@@ -438,50 +456,7 @@ export class CodeModelBuilder {
|
|
|
438
456
|
op.lroMetadata = new LongRunningMetadata(true, pollingSchema, finalSchema, pollingStrategy);
|
|
439
457
|
return op.lroMetadata;
|
|
440
458
|
}
|
|
441
|
-
|
|
442
|
-
const operationLinks = getOperationLinks(this.program, operation);
|
|
443
|
-
if (operationLinks) {
|
|
444
|
-
op.operationLinks = {};
|
|
445
|
-
for (const [linkType, linkOperation] of operationLinks) {
|
|
446
|
-
if (linkType === "polling" || linkType === "final") {
|
|
447
|
-
// some TypeSpec writes pollingOperation without the operation
|
|
448
|
-
pollingFoundInOperationLinks = true;
|
|
449
|
-
}
|
|
450
|
-
if (linkOperation.linkedOperation) {
|
|
451
|
-
// process linked operation, if not processed
|
|
452
|
-
let linkedOperation = this.operationCache.get(linkOperation.linkedOperation);
|
|
453
|
-
if (!linkedOperation) {
|
|
454
|
-
linkedOperation = this.processOperation(groupName, linkOperation.linkedOperation, clientContext, true);
|
|
455
|
-
}
|
|
456
|
-
const opLink = new OperationLink(linkedOperation);
|
|
457
|
-
// parameters of operation link
|
|
458
|
-
if (linkOperation.parameters) {
|
|
459
|
-
opLink.parameters = this.processSchema(linkOperation.parameters, "parameters");
|
|
460
|
-
}
|
|
461
|
-
op.operationLinks[linkType] = opLink;
|
|
462
|
-
const getResponse = (linkedOp) => {
|
|
463
|
-
if (linkedOp.responses) {
|
|
464
|
-
const response = linkedOp.responses.find((it) => { var _a, _b, _c; return (_c = (_b = (_a = it.protocol) === null || _a === void 0 ? void 0 : _a.http) === null || _b === void 0 ? void 0 : _b.statusCodes) === null || _c === void 0 ? void 0 : _c.includes("200"); });
|
|
465
|
-
if (response && response instanceof SchemaResponse) {
|
|
466
|
-
const schema = response.schema;
|
|
467
|
-
if (op.convenienceApi) {
|
|
468
|
-
this.trackSchemaUsage(schema, { usage: [SchemaContext.ConvenienceApi] });
|
|
469
|
-
}
|
|
470
|
-
return schema;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return undefined;
|
|
474
|
-
};
|
|
475
|
-
if (linkType === "polling") {
|
|
476
|
-
pollingSchema = getResponse(linkedOperation);
|
|
477
|
-
}
|
|
478
|
-
else if (linkType === "final") {
|
|
479
|
-
finalSchema = getResponse(linkedOperation);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return new LongRunningMetadata(pollingFoundInOperationLinks, pollingSchema, finalSchema);
|
|
459
|
+
return new LongRunningMetadata(false);
|
|
485
460
|
}
|
|
486
461
|
processRouteForLongRunning(op, responses, lroMetadata) {
|
|
487
462
|
var _a, _b;
|
|
@@ -537,21 +512,39 @@ export class CodeModelBuilder {
|
|
|
537
512
|
schema instanceof UriSchema) {
|
|
538
513
|
extensions = { "x-ms-skip-url-encoding": true };
|
|
539
514
|
}
|
|
515
|
+
// currently under dev-options.support-versioning
|
|
516
|
+
if (this.options["dev-options"] && this.options["dev-options"]["support-versioning"]) {
|
|
517
|
+
// versioning
|
|
518
|
+
const addedOn = getAddedOnVersions(this.program, param.param);
|
|
519
|
+
if (addedOn) {
|
|
520
|
+
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
521
|
+
extensions["x-ms-versioning-added"] = clientContext.getAddedVersions(addedOn);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
540
524
|
// format if array
|
|
541
525
|
let style = undefined;
|
|
542
526
|
let explode = undefined;
|
|
543
527
|
if (param.param.type.kind === "Model" && isArrayModelType(this.program, param.param.type)) {
|
|
544
528
|
if (param.type === "query") {
|
|
545
529
|
const queryParamOptions = getQueryParamOptions(this.program, param.param);
|
|
530
|
+
// TODO (weidxu): remove "as string" after http lib fix the type of queryParamOptions.format
|
|
546
531
|
switch (queryParamOptions === null || queryParamOptions === void 0 ? void 0 : queryParamOptions.format) {
|
|
547
532
|
case "csv":
|
|
548
533
|
style = SerializationStyle.Simple;
|
|
549
534
|
break;
|
|
535
|
+
case "ssv":
|
|
536
|
+
style = SerializationStyle.SpaceDelimited;
|
|
537
|
+
break;
|
|
538
|
+
case "tsv":
|
|
539
|
+
style = SerializationStyle.TabDelimited;
|
|
540
|
+
break;
|
|
541
|
+
case "pipes":
|
|
542
|
+
style = SerializationStyle.PipeDelimited;
|
|
543
|
+
break;
|
|
550
544
|
case "multi":
|
|
551
545
|
style = SerializationStyle.Form;
|
|
552
546
|
explode = true;
|
|
553
547
|
break;
|
|
554
|
-
// TODO there is bug in @typespec/http that ssv etc. is not in queryParamOptions.format
|
|
555
548
|
default:
|
|
556
549
|
if (queryParamOptions === null || queryParamOptions === void 0 ? void 0 : queryParamOptions.format) {
|
|
557
550
|
this.logWarning(`Unrecognized query parameter format: '${queryParamOptions === null || queryParamOptions === void 0 ? void 0 : queryParamOptions.format}'.`);
|
|
@@ -573,7 +566,7 @@ export class CodeModelBuilder {
|
|
|
573
566
|
}
|
|
574
567
|
}
|
|
575
568
|
}
|
|
576
|
-
const nullable =
|
|
569
|
+
const nullable = isNullableType(param.param.type);
|
|
577
570
|
const parameter = new Parameter(this.getName(param.param), this.getDoc(param.param), schema, {
|
|
578
571
|
summary: this.getSummary(param.param),
|
|
579
572
|
implementation: ImplementationLocation.Method,
|
|
@@ -833,7 +826,7 @@ export class CodeModelBuilder {
|
|
|
833
826
|
}
|
|
834
827
|
if (match) {
|
|
835
828
|
schema = candidateResponseSchema;
|
|
836
|
-
this.
|
|
829
|
+
this.trace(`Replace TypeSpec model '${this.getName(bodyType)}' with '${candidateResponseSchema.language.default.name}'`);
|
|
837
830
|
}
|
|
838
831
|
}
|
|
839
832
|
}
|
|
@@ -1014,10 +1007,14 @@ export class CodeModelBuilder {
|
|
|
1014
1007
|
if (encode.encoding === "seconds" && hasScalarAsBase(type, "duration")) {
|
|
1015
1008
|
return this.processDurationSchema(type, nameHint, getDurationFormat(encode));
|
|
1016
1009
|
}
|
|
1017
|
-
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231") &&
|
|
1010
|
+
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231" || encode.encoding === "unixTimestamp") &&
|
|
1018
1011
|
(hasScalarAsBase(type, "utcDateTime") || hasScalarAsBase(type, "offsetDateTime"))) {
|
|
1019
|
-
|
|
1020
|
-
|
|
1012
|
+
if (encode.encoding === "unixTimestamp") {
|
|
1013
|
+
return this.processUnixTimeSchema(type, nameHint);
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
return this.processDateTimeSchema(type, nameHint, encode.encoding === "rfc7231");
|
|
1017
|
+
}
|
|
1021
1018
|
}
|
|
1022
1019
|
else if (encode.encoding === "base64url" && hasScalarAsBase(type, "bytes")) {
|
|
1023
1020
|
return this.processByteArraySchema(type, nameHint, true);
|
|
@@ -1162,6 +1159,11 @@ export class CodeModelBuilder {
|
|
|
1162
1159
|
},
|
|
1163
1160
|
}));
|
|
1164
1161
|
}
|
|
1162
|
+
processUnixTimeSchema(type, name) {
|
|
1163
|
+
return this.codeModel.schemas.add(new UnixTimeSchema(name, this.getDoc(type), {
|
|
1164
|
+
summary: this.getSummary(type),
|
|
1165
|
+
}));
|
|
1166
|
+
}
|
|
1165
1167
|
processDateTimeSchema(type, name, rfc1123) {
|
|
1166
1168
|
return this.codeModel.schemas.add(new DateTimeSchema(name, this.getDoc(type), {
|
|
1167
1169
|
summary: this.getSummary(type),
|
|
@@ -1336,10 +1338,14 @@ export class CodeModelBuilder {
|
|
|
1336
1338
|
if (encode.encoding === "seconds" && hasScalarAsBase(prop.type, "duration")) {
|
|
1337
1339
|
schema = this.processDurationSchema(prop.type, nameHint, getDurationFormat(encode));
|
|
1338
1340
|
}
|
|
1339
|
-
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231") &&
|
|
1341
|
+
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231" || encode.encoding === "unixTimestamp") &&
|
|
1340
1342
|
(hasScalarAsBase(prop.type, "utcDateTime") || hasScalarAsBase(prop.type, "offsetDateTime"))) {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
+
if (encode.encoding === "unixTimestamp") {
|
|
1344
|
+
return this.processUnixTimeSchema(prop.type, nameHint);
|
|
1345
|
+
}
|
|
1346
|
+
else {
|
|
1347
|
+
return this.processDateTimeSchema(prop.type, nameHint, encode.encoding === "rfc7231");
|
|
1348
|
+
}
|
|
1343
1349
|
}
|
|
1344
1350
|
else if (encode.encoding === "base64url" && hasScalarAsBase(prop.type, "bytes")) {
|
|
1345
1351
|
return this.processByteArraySchema(prop.type, nameHint, true);
|
|
@@ -1350,7 +1356,7 @@ export class CodeModelBuilder {
|
|
|
1350
1356
|
}
|
|
1351
1357
|
processModelProperty(prop) {
|
|
1352
1358
|
const schema = this.processSchema(prop, prop.name);
|
|
1353
|
-
let nullable =
|
|
1359
|
+
let nullable = isNullableType(prop.type);
|
|
1354
1360
|
let extensions = undefined;
|
|
1355
1361
|
if (this.isSecret(prop)) {
|
|
1356
1362
|
extensions = {
|
|
@@ -1382,9 +1388,12 @@ export class CodeModelBuilder {
|
|
|
1382
1388
|
case "password":
|
|
1383
1389
|
case "url":
|
|
1384
1390
|
case "uuid":
|
|
1391
|
+
case "eTag":
|
|
1392
|
+
return this.processStringSchema(type, nameHint);
|
|
1393
|
+
default:
|
|
1394
|
+
this.logWarning(`Unrecognized string format: '${format}'.`);
|
|
1385
1395
|
return this.processStringSchema(type, nameHint);
|
|
1386
1396
|
}
|
|
1387
|
-
throw new Error(`Unrecognized string format: '${format}'.`);
|
|
1388
1397
|
}
|
|
1389
1398
|
processUnionSchema(type, name) {
|
|
1390
1399
|
const nonNullVariants = Array.from(type.variants.values()).filter((it) => !isNullType(it.type));
|
|
@@ -1392,7 +1401,7 @@ export class CodeModelBuilder {
|
|
|
1392
1401
|
// nullable
|
|
1393
1402
|
return this.processSchema(nonNullVariants[0].type, name);
|
|
1394
1403
|
}
|
|
1395
|
-
if (
|
|
1404
|
+
if (isSameLiteralTypes(nonNullVariants)) {
|
|
1396
1405
|
// enum
|
|
1397
1406
|
return this.processChoiceSchemaForUnion(type, nonNullVariants, name);
|
|
1398
1407
|
}
|
|
@@ -1481,25 +1490,6 @@ export class CodeModelBuilder {
|
|
|
1481
1490
|
throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
1482
1491
|
}
|
|
1483
1492
|
}
|
|
1484
|
-
isNullableType(type) {
|
|
1485
|
-
if (type.kind === "Union") {
|
|
1486
|
-
const nullVariants = Array.from(type.variants.values()).filter((it) => isNullType(it.type));
|
|
1487
|
-
return nullVariants.length >= 1;
|
|
1488
|
-
}
|
|
1489
|
-
else {
|
|
1490
|
-
return false;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
isSameLiteralTypes(variants) {
|
|
1494
|
-
const kindSet = new Set(variants.map((it) => it.type.kind));
|
|
1495
|
-
if (kindSet.size === 1) {
|
|
1496
|
-
const kind = kindSet.values().next().value;
|
|
1497
|
-
return kind === "String" || kind === "Number" || kind === "Boolean";
|
|
1498
|
-
}
|
|
1499
|
-
else {
|
|
1500
|
-
return false;
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
1493
|
getDefaultValue(type) {
|
|
1504
1494
|
if (type) {
|
|
1505
1495
|
switch (type.kind) {
|
|
@@ -1594,13 +1584,10 @@ export class CodeModelBuilder {
|
|
|
1594
1584
|
}
|
|
1595
1585
|
}
|
|
1596
1586
|
logWarning(msg) {
|
|
1597
|
-
this.program
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
message: msg,
|
|
1602
|
-
target: NoTarget,
|
|
1603
|
-
});
|
|
1587
|
+
logWarning(this.program, msg);
|
|
1588
|
+
}
|
|
1589
|
+
trace(msg) {
|
|
1590
|
+
trace(this.program, msg);
|
|
1604
1591
|
}
|
|
1605
1592
|
get stringSchema() {
|
|
1606
1593
|
return (this._stringSchema ||
|