@azure-tools/typespec-ts 0.15.0 → 0.16.0-alpha.20230918.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/CHANGELOG.md +10 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -17
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +3 -3
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +2 -3
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +26 -12
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +3 -3
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +5 -4
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +3 -2
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +163 -69
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +2 -2
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +15 -8
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +2 -2
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +4 -4
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +12 -5
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +2 -2
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +7 -4
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +3 -3
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +28 -18
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +1 -1
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +167 -88
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +2 -2
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +13 -7
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +11 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +3 -4
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +0 -10
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +7 -51
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformResponses.js +3 -4
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +4 -8
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.js +3 -10
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +48 -9
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +2 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +83 -73
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +15 -1
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +82 -3
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -11
- package/src/index.ts +24 -51
- package/src/lib.ts +3 -3
- package/src/modular/buildClassicalClient.ts +29 -16
- package/src/modular/buildClientContext.ts +8 -9
- package/src/modular/buildCodeModel.ts +212 -75
- package/src/modular/buildOperations.ts +16 -11
- package/src/modular/buildProjectFiles.ts +2 -2
- package/src/modular/buildRootIndex.ts +19 -12
- package/src/modular/buildSubpathIndex.ts +10 -8
- package/src/modular/emitModels.ts +35 -24
- package/src/modular/helpers/clientHelpers.ts +1 -1
- package/src/modular/helpers/operationHelpers.ts +256 -127
- package/src/modular/helpers/typeHelpers.ts +19 -7
- package/src/modular/modularCodeModel.ts +11 -0
- package/src/transform/transformHelperFunctionDetails.ts +10 -4
- package/src/transform/transformParameters.ts +15 -57
- package/src/transform/transformResponses.ts +2 -4
- package/src/transform/transformSchemas.ts +5 -9
- package/src/transform/transformTelemetryInfo.ts +4 -18
- package/src/transform/transfromRLCOptions.ts +67 -9
- package/src/utils/modelUtils.ts +81 -72
- package/src/utils/operationUtil.ts +121 -4
package/src/utils/modelUtils.ts
CHANGED
|
@@ -134,7 +134,7 @@ export function getSchemaForType(
|
|
|
134
134
|
const program = dpgContext.program;
|
|
135
135
|
const type = getEffectiveModelFromType(program, typeInput);
|
|
136
136
|
|
|
137
|
-
const builtinType =
|
|
137
|
+
const builtinType = mapTypeSpecTypeToTypeScript(dpgContext, type, usage);
|
|
138
138
|
if (builtinType !== undefined) {
|
|
139
139
|
// add in description elements for types derived from primitive types (SecureString, etc.)
|
|
140
140
|
const doc = getDoc(program, type);
|
|
@@ -284,7 +284,7 @@ function getSchemaForUnionVariant(
|
|
|
284
284
|
return getSchemaForType(dpgContext, variant, usage);
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
// An openapi "string" can be defined in several different ways in
|
|
287
|
+
// An openapi "string" can be defined in several different ways in typespec
|
|
288
288
|
function isOasString(type: Type): boolean {
|
|
289
289
|
if (type.kind === "String") {
|
|
290
290
|
// A string literal
|
|
@@ -402,7 +402,7 @@ function validateDiscriminator(
|
|
|
402
402
|
* A "schema property" here is a property that is emitted to OpenAPI schema.
|
|
403
403
|
*
|
|
404
404
|
* Headers, parameters, status codes are not schema properties even they are
|
|
405
|
-
* represented as properties in
|
|
405
|
+
* represented as properties in typespec.
|
|
406
406
|
*/
|
|
407
407
|
function isSchemaProperty(program: Program, property: ModelProperty) {
|
|
408
408
|
const headerInfo = getHeaderFieldName(program, property);
|
|
@@ -420,9 +420,7 @@ function getSchemaForModel(
|
|
|
420
420
|
) {
|
|
421
421
|
const program = dpgContext.program;
|
|
422
422
|
const overridedModelName =
|
|
423
|
-
getProjectedName(program, model, "
|
|
424
|
-
getProjectedName(program, model, "client") ??
|
|
425
|
-
getFriendlyName(program, model);
|
|
423
|
+
getFriendlyName(program, model) ?? getProjectedName(program, model, "json");
|
|
426
424
|
let name = model.name;
|
|
427
425
|
if (
|
|
428
426
|
!overridedModelName &&
|
|
@@ -459,14 +457,7 @@ function getSchemaForModel(
|
|
|
459
457
|
|
|
460
458
|
modelSchema.typeName = modelSchema.name;
|
|
461
459
|
|
|
462
|
-
if (
|
|
463
|
-
(model.name === "ErrorResponse" ||
|
|
464
|
-
model.name === "ErrorModel" ||
|
|
465
|
-
model.name === "Error") &&
|
|
466
|
-
model.kind === "Model" &&
|
|
467
|
-
model.namespace?.name === "Foundations" &&
|
|
468
|
-
model.namespace.namespace?.name === "Core"
|
|
469
|
-
) {
|
|
460
|
+
if (isAzureCoreErrorType(model)) {
|
|
470
461
|
modelSchema.fromCore = true;
|
|
471
462
|
}
|
|
472
463
|
|
|
@@ -654,86 +645,86 @@ function getSchemaForModel(
|
|
|
654
645
|
}
|
|
655
646
|
return modelSchema;
|
|
656
647
|
}
|
|
657
|
-
// Map an
|
|
648
|
+
// Map an typespec type to an OA schema. Returns undefined when the resulting
|
|
658
649
|
// OA schema is just a regular object schema.
|
|
659
|
-
function
|
|
650
|
+
function mapTypeSpecTypeToTypeScript(
|
|
660
651
|
dpgContext: SdkContext,
|
|
661
|
-
|
|
652
|
+
type: Type,
|
|
662
653
|
usage?: SchemaContext[]
|
|
663
654
|
): any {
|
|
664
|
-
switch (
|
|
655
|
+
switch (type.kind) {
|
|
665
656
|
case "Number":
|
|
666
|
-
return { type: `${
|
|
657
|
+
return { type: `${type.value}` };
|
|
667
658
|
case "String":
|
|
668
|
-
return { type: `"${
|
|
659
|
+
return { type: `"${type.value}"` };
|
|
669
660
|
case "Boolean":
|
|
670
|
-
return { type: `${
|
|
661
|
+
return { type: `${type.value}` };
|
|
671
662
|
case "Model":
|
|
672
|
-
return
|
|
663
|
+
return mapTypeSpecStdTypeToTypeScript(dpgContext, type, usage);
|
|
673
664
|
}
|
|
674
|
-
if (
|
|
675
|
-
if (typeof
|
|
676
|
-
return { type: `"${
|
|
677
|
-
} else if (typeof
|
|
678
|
-
return { type: `${
|
|
665
|
+
if (type.kind === undefined) {
|
|
666
|
+
if (typeof type === "string") {
|
|
667
|
+
return { type: `"${type}"` };
|
|
668
|
+
} else if (typeof type === "number" || typeof type === "boolean") {
|
|
669
|
+
return { type: `${type}` };
|
|
679
670
|
}
|
|
680
671
|
}
|
|
681
672
|
}
|
|
682
673
|
function applyIntrinsicDecorators(
|
|
683
674
|
program: Program,
|
|
684
|
-
|
|
675
|
+
type: Scalar | ModelProperty,
|
|
685
676
|
target: any
|
|
686
677
|
): any {
|
|
687
678
|
const newTarget = { ...target };
|
|
688
|
-
const docStr = getDoc(program,
|
|
689
|
-
const isString = isStringType(program, getPropertyType(
|
|
690
|
-
const isNumeric = isNumericType(program, getPropertyType(
|
|
679
|
+
const docStr = getDoc(program, type);
|
|
680
|
+
const isString = isStringType(program, getPropertyType(type));
|
|
681
|
+
const isNumeric = isNumericType(program, getPropertyType(type));
|
|
691
682
|
|
|
692
683
|
if (isString && !target.documentation && docStr) {
|
|
693
684
|
newTarget.description = docStr;
|
|
694
685
|
}
|
|
695
686
|
|
|
696
|
-
const restApiName = getProjectedName(program,
|
|
687
|
+
const restApiName = getProjectedName(program, type, "json");
|
|
697
688
|
if (restApiName) {
|
|
698
689
|
newTarget.name = restApiName;
|
|
699
690
|
}
|
|
700
691
|
|
|
701
|
-
const summaryStr = getSummary(program,
|
|
692
|
+
const summaryStr = getSummary(program, type);
|
|
702
693
|
if (isString && !target.summary && summaryStr) {
|
|
703
694
|
newTarget.summary = summaryStr;
|
|
704
695
|
}
|
|
705
696
|
|
|
706
|
-
const formatStr = getFormat(program,
|
|
697
|
+
const formatStr = getFormat(program, type);
|
|
707
698
|
if (isString && !target.format && formatStr) {
|
|
708
699
|
newTarget.format = formatStr;
|
|
709
700
|
}
|
|
710
701
|
|
|
711
|
-
const pattern = getPattern(program,
|
|
702
|
+
const pattern = getPattern(program, type);
|
|
712
703
|
if (isString && !target.pattern && pattern) {
|
|
713
704
|
newTarget.pattern = pattern;
|
|
714
705
|
}
|
|
715
706
|
|
|
716
|
-
const minLength = getMinLength(program,
|
|
707
|
+
const minLength = getMinLength(program, type);
|
|
717
708
|
if (isString && !target.minLength && minLength !== undefined) {
|
|
718
709
|
newTarget.minLength = minLength;
|
|
719
710
|
}
|
|
720
711
|
|
|
721
|
-
const maxLength = getMaxLength(program,
|
|
712
|
+
const maxLength = getMaxLength(program, type);
|
|
722
713
|
if (isString && !target.maxLength && maxLength !== undefined) {
|
|
723
714
|
newTarget.maxLength = maxLength;
|
|
724
715
|
}
|
|
725
716
|
|
|
726
|
-
const minValue = getMinValue(program,
|
|
717
|
+
const minValue = getMinValue(program, type);
|
|
727
718
|
if (isNumeric && !target.minimum && minValue !== undefined) {
|
|
728
719
|
newTarget.minimum = minValue;
|
|
729
720
|
}
|
|
730
721
|
|
|
731
|
-
const maxValue = getMaxValue(program,
|
|
722
|
+
const maxValue = getMaxValue(program, type);
|
|
732
723
|
if (isNumeric && !target.maximum && maxValue !== undefined) {
|
|
733
724
|
newTarget.maximum = maxValue;
|
|
734
725
|
}
|
|
735
726
|
|
|
736
|
-
if (isSecret(program,
|
|
727
|
+
if (isSecret(program, type)) {
|
|
737
728
|
newTarget.format = "password";
|
|
738
729
|
newTarget["x-ms-secret"] = true;
|
|
739
730
|
}
|
|
@@ -781,15 +772,15 @@ function enumMemberType(member: EnumMember) {
|
|
|
781
772
|
return "string";
|
|
782
773
|
}
|
|
783
774
|
/**
|
|
784
|
-
* Map
|
|
775
|
+
* Map TypeSpec intrinsic models to open api definitions
|
|
785
776
|
*/
|
|
786
|
-
function
|
|
777
|
+
function mapTypeSpecStdTypeToTypeScript(
|
|
787
778
|
dpgContext: SdkContext,
|
|
788
|
-
|
|
779
|
+
type: Model,
|
|
789
780
|
usage?: SchemaContext[]
|
|
790
781
|
): any | undefined {
|
|
791
782
|
const program = dpgContext.program;
|
|
792
|
-
const indexer = (
|
|
783
|
+
const indexer = (type as Model).indexer;
|
|
793
784
|
if (indexer !== undefined) {
|
|
794
785
|
if (!isNeverType(indexer.key)) {
|
|
795
786
|
const name = indexer.key.name;
|
|
@@ -804,7 +795,7 @@ function mapCadlStdTypeToTypeScript(
|
|
|
804
795
|
schema = {
|
|
805
796
|
type: "dictionary",
|
|
806
797
|
additionalProperties: valueType,
|
|
807
|
-
description: getDoc(program,
|
|
798
|
+
description: getDoc(program, type)
|
|
808
799
|
};
|
|
809
800
|
if (
|
|
810
801
|
!program.checker.isStdType(indexer.value) &&
|
|
@@ -838,7 +829,7 @@ function mapCadlStdTypeToTypeScript(
|
|
|
838
829
|
schema = {
|
|
839
830
|
type: "array",
|
|
840
831
|
items: getSchemaForType(dpgContext, indexer.value!, usage, true),
|
|
841
|
-
description: getDoc(program,
|
|
832
|
+
description: getDoc(program, type)
|
|
842
833
|
};
|
|
843
834
|
if (
|
|
844
835
|
!program.checker.isStdType(indexer.value) &&
|
|
@@ -897,10 +888,10 @@ function isUnionType(type: Type) {
|
|
|
897
888
|
|
|
898
889
|
function getSchemaForStdScalar(
|
|
899
890
|
program: Program,
|
|
900
|
-
|
|
891
|
+
type: Scalar,
|
|
901
892
|
relevantProperty?: ModelProperty
|
|
902
893
|
) {
|
|
903
|
-
if (!program.checker.isStdType(
|
|
894
|
+
if (!program.checker.isStdType(type)) {
|
|
904
895
|
return undefined;
|
|
905
896
|
}
|
|
906
897
|
|
|
@@ -909,83 +900,85 @@ function getSchemaForStdScalar(
|
|
|
909
900
|
* if absent use typespec type (or default way of serializing that type)
|
|
910
901
|
* if present respect type provided in @encode
|
|
911
902
|
*/
|
|
903
|
+
let format = undefined;
|
|
912
904
|
if (relevantProperty) {
|
|
913
905
|
const encodeData = getEncode(program, relevantProperty);
|
|
914
|
-
if (encodeData && isEncodeTypeEffective(
|
|
915
|
-
|
|
906
|
+
if (encodeData && isEncodeTypeEffective(type, encodeData)) {
|
|
907
|
+
type = encodeData.type;
|
|
908
|
+
format = encodeData.encoding;
|
|
916
909
|
}
|
|
917
910
|
}
|
|
918
|
-
const name =
|
|
919
|
-
const description = getSummary(program,
|
|
911
|
+
const name = type.name;
|
|
912
|
+
const description = getSummary(program, type);
|
|
920
913
|
switch (name) {
|
|
921
914
|
case "bytes":
|
|
922
915
|
return { type: "string", format: "byte", description };
|
|
923
916
|
case "integer":
|
|
924
|
-
return applyIntrinsicDecorators(program,
|
|
917
|
+
return applyIntrinsicDecorators(program, type, {
|
|
925
918
|
type: "number"
|
|
926
919
|
});
|
|
927
920
|
case "int8":
|
|
928
|
-
return applyIntrinsicDecorators(program,
|
|
921
|
+
return applyIntrinsicDecorators(program, type, {
|
|
929
922
|
type: "number",
|
|
930
923
|
format: "int8"
|
|
931
924
|
});
|
|
932
925
|
case "int16":
|
|
933
|
-
return applyIntrinsicDecorators(program,
|
|
926
|
+
return applyIntrinsicDecorators(program, type, {
|
|
934
927
|
type: "number",
|
|
935
928
|
format: "int16"
|
|
936
929
|
});
|
|
937
930
|
case "int32":
|
|
938
|
-
return applyIntrinsicDecorators(program,
|
|
931
|
+
return applyIntrinsicDecorators(program, type, {
|
|
939
932
|
type: "number",
|
|
940
933
|
format: "int32"
|
|
941
934
|
});
|
|
942
935
|
case "int64":
|
|
943
|
-
return applyIntrinsicDecorators(program,
|
|
936
|
+
return applyIntrinsicDecorators(program, type, {
|
|
944
937
|
type: "number",
|
|
945
938
|
format: "int64"
|
|
946
939
|
});
|
|
947
940
|
case "safeint":
|
|
948
|
-
return applyIntrinsicDecorators(program,
|
|
941
|
+
return applyIntrinsicDecorators(program, type, {
|
|
949
942
|
type: "number",
|
|
950
943
|
format: "int64"
|
|
951
944
|
});
|
|
952
945
|
case "uint8":
|
|
953
|
-
return applyIntrinsicDecorators(program,
|
|
946
|
+
return applyIntrinsicDecorators(program, type, {
|
|
954
947
|
type: "number",
|
|
955
948
|
format: "uint8"
|
|
956
949
|
});
|
|
957
950
|
case "uint16":
|
|
958
|
-
return applyIntrinsicDecorators(program,
|
|
951
|
+
return applyIntrinsicDecorators(program, type, {
|
|
959
952
|
type: "number",
|
|
960
953
|
format: "uint16"
|
|
961
954
|
});
|
|
962
955
|
case "uint32":
|
|
963
|
-
return applyIntrinsicDecorators(program,
|
|
956
|
+
return applyIntrinsicDecorators(program, type, {
|
|
964
957
|
type: "number",
|
|
965
958
|
format: "uint32"
|
|
966
959
|
});
|
|
967
960
|
case "uint64":
|
|
968
|
-
return applyIntrinsicDecorators(program,
|
|
961
|
+
return applyIntrinsicDecorators(program, type, {
|
|
969
962
|
type: "number",
|
|
970
963
|
format: "uint64"
|
|
971
964
|
});
|
|
972
965
|
case "float64":
|
|
973
|
-
return applyIntrinsicDecorators(program,
|
|
966
|
+
return applyIntrinsicDecorators(program, type, {
|
|
974
967
|
type: "number",
|
|
975
968
|
format: "double"
|
|
976
969
|
});
|
|
977
970
|
case "float32":
|
|
978
|
-
return applyIntrinsicDecorators(program,
|
|
971
|
+
return applyIntrinsicDecorators(program, type, {
|
|
979
972
|
type: "number",
|
|
980
973
|
format: "float"
|
|
981
974
|
});
|
|
982
975
|
case "float":
|
|
983
|
-
return applyIntrinsicDecorators(program,
|
|
976
|
+
return applyIntrinsicDecorators(program, type, {
|
|
984
977
|
type: "number",
|
|
985
978
|
format: "float"
|
|
986
979
|
});
|
|
987
980
|
case "string":
|
|
988
|
-
return applyIntrinsicDecorators(program,
|
|
981
|
+
return applyIntrinsicDecorators(program, type, {
|
|
989
982
|
type: "string"
|
|
990
983
|
});
|
|
991
984
|
case "boolean":
|
|
@@ -993,7 +986,7 @@ function getSchemaForStdScalar(
|
|
|
993
986
|
case "plainDate":
|
|
994
987
|
return {
|
|
995
988
|
type: "string",
|
|
996
|
-
format
|
|
989
|
+
format,
|
|
997
990
|
description,
|
|
998
991
|
typeName: "Date | string",
|
|
999
992
|
outputTypeName: "string"
|
|
@@ -1001,7 +994,7 @@ function getSchemaForStdScalar(
|
|
|
1001
994
|
case "utcDateTime":
|
|
1002
995
|
return {
|
|
1003
996
|
type: "string",
|
|
1004
|
-
format
|
|
997
|
+
format,
|
|
1005
998
|
description,
|
|
1006
999
|
typeName: "Date | string",
|
|
1007
1000
|
outputTypeName: "string"
|
|
@@ -1023,7 +1016,7 @@ function getSchemaForStdScalar(
|
|
|
1023
1016
|
outputTypeName: "string"
|
|
1024
1017
|
};
|
|
1025
1018
|
case "duration":
|
|
1026
|
-
return { type: "string", format
|
|
1019
|
+
return { type: "string", format, description };
|
|
1027
1020
|
}
|
|
1028
1021
|
}
|
|
1029
1022
|
|
|
@@ -1094,11 +1087,11 @@ function getEnumStringDescription(type: any) {
|
|
|
1094
1087
|
|
|
1095
1088
|
export function getFormattedPropertyDoc(
|
|
1096
1089
|
program: Program,
|
|
1097
|
-
|
|
1090
|
+
type: ModelProperty | Type,
|
|
1098
1091
|
schemaType: any,
|
|
1099
1092
|
sperator: string = "\n\n"
|
|
1100
1093
|
) {
|
|
1101
|
-
const propertyDoc = getDoc(program,
|
|
1094
|
+
const propertyDoc = getDoc(program, type);
|
|
1102
1095
|
const enhancedDocFromType = getEnumStringDescription(schemaType);
|
|
1103
1096
|
if (propertyDoc && enhancedDocFromType) {
|
|
1104
1097
|
return `${propertyDoc}${sperator}${enhancedDocFromType}`;
|
|
@@ -1108,7 +1101,6 @@ export function getFormattedPropertyDoc(
|
|
|
1108
1101
|
|
|
1109
1102
|
export function getBodyType(
|
|
1110
1103
|
program: Program,
|
|
1111
|
-
|
|
1112
1104
|
route: HttpOperation
|
|
1113
1105
|
): Type | undefined {
|
|
1114
1106
|
let bodyModel = route.parameters.bodyType;
|
|
@@ -1257,3 +1249,20 @@ export function trimUsage(model: any) {
|
|
|
1257
1249
|
}, {});
|
|
1258
1250
|
return ordered;
|
|
1259
1251
|
}
|
|
1252
|
+
|
|
1253
|
+
export function isAzureCoreErrorType(t?: Type): boolean {
|
|
1254
|
+
if (
|
|
1255
|
+
t?.kind !== "Model" ||
|
|
1256
|
+
!["error", "errorresponse", "innererror"].includes(t.name.toLowerCase())
|
|
1257
|
+
)
|
|
1258
|
+
return false;
|
|
1259
|
+
const namespaces = ".Azure.Core.Foundations".split(".");
|
|
1260
|
+
while (
|
|
1261
|
+
namespaces.length > 0 &&
|
|
1262
|
+
(t?.kind === "Model" || t?.kind === "Namespace") &&
|
|
1263
|
+
t.namespace?.name === namespaces.pop()
|
|
1264
|
+
) {
|
|
1265
|
+
t = t.namespace;
|
|
1266
|
+
}
|
|
1267
|
+
return namespaces.length == 0;
|
|
1268
|
+
}
|
|
@@ -20,10 +20,11 @@ import {
|
|
|
20
20
|
Type
|
|
21
21
|
} from "@typespec/compiler";
|
|
22
22
|
import {
|
|
23
|
-
getHttpOperation,
|
|
24
23
|
HttpOperation,
|
|
24
|
+
HttpOperationParameter,
|
|
25
25
|
HttpOperationResponse,
|
|
26
|
-
StatusCode
|
|
26
|
+
StatusCode,
|
|
27
|
+
getHttpOperation
|
|
27
28
|
} from "@typespec/http";
|
|
28
29
|
import {
|
|
29
30
|
getLroMetadata,
|
|
@@ -119,11 +120,11 @@ export function isBinaryPayload(
|
|
|
119
120
|
) {
|
|
120
121
|
contentType = `"${contentType}"`;
|
|
121
122
|
if (
|
|
122
|
-
isByteOrByteUnion(dpgContext, body) &&
|
|
123
123
|
contentType !== `"application/json"` &&
|
|
124
124
|
contentType !== `"text/plain"` &&
|
|
125
125
|
contentType !== `"application/json" | "text/plain"` &&
|
|
126
|
-
contentType !== `"text/plain" | "application/json"`
|
|
126
|
+
contentType !== `"text/plain" | "application/json"` &&
|
|
127
|
+
isByteOrByteUnion(dpgContext, body)
|
|
127
128
|
) {
|
|
128
129
|
return true;
|
|
129
130
|
}
|
|
@@ -350,3 +351,119 @@ export function extractPagedMetadataNested(
|
|
|
350
351
|
}
|
|
351
352
|
return paged;
|
|
352
353
|
}
|
|
354
|
+
|
|
355
|
+
export function getSpecialSerializeInfo(
|
|
356
|
+
paramType: string,
|
|
357
|
+
paramFormat: string
|
|
358
|
+
) {
|
|
359
|
+
const hasMultiCollection = getHasMultiCollection(paramType, paramFormat);
|
|
360
|
+
const hasPipeCollection = getHasPipeCollection(paramType, paramFormat);
|
|
361
|
+
const hasSsvCollection = getHasSsvCollection(paramType, paramFormat);
|
|
362
|
+
const hasTsvCollection = getHasTsvCollection(paramType, paramFormat);
|
|
363
|
+
const hasCsvCollection = getHasCsvCollection(paramType, paramFormat);
|
|
364
|
+
const descriptions = [];
|
|
365
|
+
const collectionInfo = [];
|
|
366
|
+
if (hasMultiCollection) {
|
|
367
|
+
descriptions.push("buildMultiCollection");
|
|
368
|
+
collectionInfo.push("multi");
|
|
369
|
+
}
|
|
370
|
+
if (hasSsvCollection) {
|
|
371
|
+
descriptions.push("buildSsvCollection");
|
|
372
|
+
collectionInfo.push("ssv");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (hasTsvCollection) {
|
|
376
|
+
descriptions.push("buildTsvCollection");
|
|
377
|
+
collectionInfo.push("tsv");
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (hasPipeCollection) {
|
|
381
|
+
descriptions.push("buildPipeCollection");
|
|
382
|
+
collectionInfo.push("pipe");
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (hasCsvCollection) {
|
|
386
|
+
descriptions.push("buildCsvCollection");
|
|
387
|
+
collectionInfo.push("csv");
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
hasMultiCollection,
|
|
391
|
+
hasPipeCollection,
|
|
392
|
+
hasSsvCollection,
|
|
393
|
+
hasTsvCollection,
|
|
394
|
+
hasCsvCollection,
|
|
395
|
+
descriptions,
|
|
396
|
+
collectionInfo
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function getHasMultiCollection(paramType: string, paramFormat: string) {
|
|
401
|
+
return (
|
|
402
|
+
(paramType === "query" || paramType === "header") && paramFormat === "multi"
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
function getHasSsvCollection(paramType: string, paramFormat: string) {
|
|
406
|
+
return paramType === "query" && paramFormat === "ssv";
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function getHasTsvCollection(paramType: string, paramFormat: string) {
|
|
410
|
+
return paramType === "query" && paramFormat === "tsv";
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function getHasCsvCollection(paramType: string, paramFormat: string) {
|
|
414
|
+
return paramType === "header" && paramFormat === "csv";
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function getHasPipeCollection(paramType: string, paramFormat: string) {
|
|
418
|
+
return paramType === "query" && paramFormat === "pipes";
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function hasCollectionFormatInfo(
|
|
422
|
+
paramType: string,
|
|
423
|
+
paramFormat: string
|
|
424
|
+
) {
|
|
425
|
+
return (
|
|
426
|
+
getHasMultiCollection(paramType, paramFormat) ||
|
|
427
|
+
getHasSsvCollection(paramType, paramFormat) ||
|
|
428
|
+
getHasTsvCollection(paramType, paramFormat) ||
|
|
429
|
+
getHasCsvCollection(paramType, paramFormat) ||
|
|
430
|
+
getHasPipeCollection(paramType, paramFormat)
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export function getCollectionFormatHelper(
|
|
435
|
+
paramType: string,
|
|
436
|
+
paramFormat: string
|
|
437
|
+
) {
|
|
438
|
+
const detail = getSpecialSerializeInfo(paramType, paramFormat);
|
|
439
|
+
return detail.descriptions.length > 0 ? detail.descriptions[0] : undefined;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function getCustomRequestHeaderNameForOperation(
|
|
443
|
+
route: HttpOperation
|
|
444
|
+
): string | undefined {
|
|
445
|
+
const params = route.parameters.parameters.filter(
|
|
446
|
+
isCustomClientRequestIdParam
|
|
447
|
+
);
|
|
448
|
+
if (params.length > 0) {
|
|
449
|
+
return "client-request-id";
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export function isCustomClientRequestIdParam(param: HttpOperationParameter) {
|
|
456
|
+
return (
|
|
457
|
+
param.type === "header" && param.name.toLowerCase() === "client-request-id"
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export function isIgnoredHeaderParam(param: HttpOperationParameter) {
|
|
462
|
+
return (
|
|
463
|
+
isCustomClientRequestIdParam(param) ||
|
|
464
|
+
(param.type === "header" &&
|
|
465
|
+
["return-client-request-id", "ocp-date"].includes(
|
|
466
|
+
param.name.toLowerCase()
|
|
467
|
+
))
|
|
468
|
+
);
|
|
469
|
+
}
|