diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index 15d131321a..94f407c98b 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -146,7 +146,7 @@ import { import { ProcessingCache, getAccess, - getDurationFormatFromSdkType, + getDurationFormat, getNonNullSdkType, getUnionDescription, getUsage, @@ -177,7 +177,7 @@ export class CodeModelBuilder { private loggingEnabled: boolean = false; readonly schemaCache = new ProcessingCache((type: SdkType, name: string) => - this.processSchemaFromSdkTypeImpl(type, name), + this.processSchemaImpl(type, name), ); readonly typeUnionRefCache = new Map(); // Union means it ref a Union type, null means it does not ref any Union, undefined means type visited but not completed @@ -275,7 +275,7 @@ export class CodeModelBuilder { if (arg.isApiVersionParam) { parameter = this.createApiVersionParameter(arg.name, ParameterLocation.Uri); } else { - const schema = this.processSchemaFromSdkType(arg.type, arg.name); + const schema = this.processSchema(arg.type, arg.name); this.trackSchemaUsage(schema, { usage: [SchemaContext.Input, SchemaContext.Output /*SchemaContext.Public*/], }); @@ -339,7 +339,7 @@ export class CodeModelBuilder { if (this.isBranded()) { // Azure would not allow BasicAuth or BearerAuth - this.logWarning(`{scheme.scheme} auth method is currently not supported.`); + this.logWarning(`${scheme.scheme} auth method is currently not supported.`); continue; } } @@ -381,13 +381,13 @@ export class CodeModelBuilder { if (!processedSdkModels.has(model)) { const access = getAccess(model.__raw, accessCache); if (access === "public") { - const schema = this.processSchemaFromSdkType(model, ""); + const schema = this.processSchema(model, ""); this.trackSchemaUsage(schema, { usage: [SchemaContext.Public], }); } else if (access === "internal") { - const schema = this.processSchemaFromSdkType(model, model.name); + const schema = this.processSchema(model, model.name); this.trackSchemaUsage(schema, { usage: [SchemaContext.Internal], @@ -396,7 +396,7 @@ export class CodeModelBuilder { const usage = getUsage(model.__raw, usageCache); if (usage) { - const schema = this.processSchemaFromSdkType(model, ""); + const schema = this.processSchema(model, ""); this.trackSchemaUsage(schema, { usage: usage, @@ -954,7 +954,7 @@ export class CodeModelBuilder { } else { const pollType = this.findResponseBody(lroMetadata.pollingInfo.responseModel); const sdkType = getClientType(this.sdkContext, pollType); - pollingSchema = this.processSchemaFromSdkType(sdkType, "pollResult"); + pollingSchema = this.processSchema(sdkType, "pollResult"); } // finalSchema @@ -970,7 +970,7 @@ export class CodeModelBuilder { : lroMetadata.finalEnvelopeResult; const finalType = this.findResponseBody(finalResult); const sdkType = getClientType(this.sdkContext, finalType); - finalSchema = this.processSchemaFromSdkType(sdkType, "finalResult"); + finalSchema = this.processSchema(sdkType, "finalResult"); if ( useNewPollStrategy && @@ -1070,7 +1070,7 @@ export class CodeModelBuilder { } else { // schema const sdkType = getNonNullSdkType(param.type); - const schema = this.processSchemaFromSdkType(sdkType, param.name); + const schema = this.processSchema(sdkType, param.name); let extensions: { [id: string]: any } | undefined = undefined; if (param.kind === "path") { @@ -1350,9 +1350,9 @@ export class CodeModelBuilder { let schema: Schema; if (unknownRequestBody && sdkType.kind === "bytes") { // if it's unknown request body, handle binary request body - schema = this.processBinarySchemaFromSdkType(sdkType); + schema = this.processBinarySchema(sdkType); } else { - schema = this.processSchemaFromSdkType(getNonNullSdkType(sdkType), sdkBody.name); + schema = this.processSchema(getNonNullSdkType(sdkType), sdkBody.name); } const parameterName = sdkBody.name; @@ -1610,7 +1610,7 @@ export class CodeModelBuilder { headers = []; if (sdkResponse.headers) { for (const header of sdkResponse.headers) { - const schema = this.processSchemaFromSdkType(header.type, header.serializedName); + const schema = this.processSchema(header.type, header.serializedName); headers.push( new HttpHeader(header.serializedName, schema, { language: { @@ -1659,7 +1659,7 @@ export class CodeModelBuilder { trackConvenienceApi = false; } if (!schema) { - schema = this.processSchemaFromSdkType(bodyType, op.language.default.name + "Response"); + schema = this.processSchema(bodyType, op.language.default.name + "Response"); } response = new SchemaResponse(schema, { protocol: { @@ -1730,101 +1730,97 @@ export class CodeModelBuilder { } } - private processSchemaFromSdkType(type: SdkType, nameHint: string): Schema { + private processSchema(type: SdkType, nameHint: string): Schema { return this.schemaCache.process(type, nameHint) || fail("Unable to process schema."); } - private processSchemaFromSdkTypeImpl(type: SdkType, nameHint: string): Schema { + private processSchemaImpl(type: SdkType, nameHint: string): Schema { if (isSdkBuiltInKind(type.kind)) { - return this.processBuiltInFromSdkType(type as SdkBuiltInType, nameHint); + return this.processBuiltInType(type as SdkBuiltInType, nameHint); } else { switch (type.kind) { case "enum": - return this.processChoiceSchemaFromSdkType(type, type.name); + return this.processChoiceSchema(type, type.name); case "enumvalue": - return this.processConstantSchemaFromEnumValueFromSdkType(type, nameHint); + return this.processConstantSchemaFromEnumValue(type, nameHint); case "union": - return this.processUnionSchemaFromSdkType(type, type.name); + return this.processUnionSchema(type, type.name); case "model": - return this.processObjectSchemaFromSdkType(type, type.name); + return this.processObjectSchema(type, type.name); case "dict": - return this.processDictionarySchemaFromSdkType(type, nameHint); + return this.processDictionarySchema(type, nameHint); case "array": - return this.processArraySchemaFromSdkType(type, nameHint); + return this.processArraySchema(type, nameHint); case "duration": - return this.processDurationSchemaFromSdkType( - type, - nameHint, - getDurationFormatFromSdkType(type), - ); + return this.processDurationSchema(type, nameHint, getDurationFormat(type)); case "constant": - return this.processConstantSchemaFromSdkType(type, nameHint); + return this.processConstantSchema(type, nameHint); case "utcDateTime": case "offsetDateTime": if (type.encode === "unixTimestamp") { - return this.processUnixTimeSchemaFromSdkType(type, nameHint); + return this.processUnixTimeSchema(type, nameHint); } else { - return this.processDateTimeSchemaFromSdkType(type, nameHint, type.encode === "rfc7231"); + return this.processDateTimeSchema(type, nameHint, type.encode === "rfc7231"); } } } throw new Error(`Unrecognized type: '${type.kind}'.`); } - private processBuiltInFromSdkType(type: SdkBuiltInType, nameHint: string): Schema { + private processBuiltInType(type: SdkBuiltInType, nameHint: string): Schema { nameHint = nameHint || type.kind; if (isSdkIntKind(type.kind)) { const integerSize = type.kind === "safeint" || type.kind.includes("int64") ? 64 : 32; - return this.processIntegerSchemaFromSdkType(type, nameHint, integerSize); + return this.processIntegerSchema(type, nameHint, integerSize); } else { switch (type.kind) { case "any": - return this.processAnySchemaFromSdkType(); + return this.processAnySchema(); case "string": - return this.processStringSchemaFromSdkType(type, nameHint); + return this.processStringSchema(type, nameHint); case "float": case "float32": case "float64": - return this.processNumberSchemaFromSdkType(type, nameHint); + return this.processNumberSchema(type, nameHint); case "decimal": case "decimal128": - return this.processDecimalSchemaFromSdkType(type, nameHint); + return this.processDecimalSchema(type, nameHint); case "bytes": - return this.processByteArraySchemaFromSdkType(type, nameHint); + return this.processByteArraySchema(type, nameHint); case "boolean": - return this.processBooleanSchemaFromSdkType(type, nameHint); + return this.processBooleanSchema(type, nameHint); case "plainTime": - return this.processTimeSchemaFromSdkType(type, nameHint); + return this.processTimeSchema(type, nameHint); case "plainDate": - return this.processDateSchemaFromSdkType(type, nameHint); + return this.processDateSchema(type, nameHint); case "url": - return this.processUrlSchemaFromSdkType(type, nameHint); + return this.processUrlSchema(type, nameHint); } } } - private processAnySchemaFromSdkType(): AnySchema { + private processAnySchema(): AnySchema { return this.anySchema; } - private processStringSchemaFromSdkType(type: SdkBuiltInType, name: string): StringSchema { + private processStringSchema(type: SdkBuiltInType, name: string): StringSchema { return this.codeModel.schemas.add( new StringSchema(name, type.details ?? "", { summary: type.description, @@ -1832,7 +1828,7 @@ export class CodeModelBuilder { ); } - private processByteArraySchemaFromSdkType(type: SdkBuiltInType, name: string): ByteArraySchema { + private processByteArraySchema(type: SdkBuiltInType, name: string): ByteArraySchema { const base64Encoded: boolean = type.encode === "base64url"; return this.codeModel.schemas.add( new ByteArraySchema(name, type.details ?? "", { @@ -1842,7 +1838,7 @@ export class CodeModelBuilder { ); } - private processIntegerSchemaFromSdkType( + private processIntegerSchema( type: SdkBuiltInType, name: string, precision: number, @@ -1856,7 +1852,7 @@ export class CodeModelBuilder { return this.codeModel.schemas.add(schema); } - private processNumberSchemaFromSdkType(type: SdkBuiltInType, name: string): NumberSchema { + private processNumberSchema(type: SdkBuiltInType, name: string): NumberSchema { return this.codeModel.schemas.add( new NumberSchema(name, type.details ?? "", SchemaType.Number, 64, { summary: type.description, @@ -1864,7 +1860,7 @@ export class CodeModelBuilder { ); } - private processDecimalSchemaFromSdkType(type: SdkBuiltInType, name: string): NumberSchema { + private processDecimalSchema(type: SdkBuiltInType, name: string): NumberSchema { // "Infinity" maps to "BigDecimal" in Java return this.codeModel.schemas.add( new NumberSchema(name, type.details ?? "", SchemaType.Number, Infinity, { @@ -1873,7 +1869,7 @@ export class CodeModelBuilder { ); } - private processBooleanSchemaFromSdkType(type: SdkBuiltInType, name: string): BooleanSchema { + private processBooleanSchema(type: SdkBuiltInType, name: string): BooleanSchema { return this.codeModel.schemas.add( new BooleanSchema(name, type.details ?? "", { summary: type.description, @@ -1881,7 +1877,7 @@ export class CodeModelBuilder { ); } - private processArraySchemaFromSdkType(type: SdkArrayType, name: string): ArraySchema { + private processArraySchema(type: SdkArrayType, name: string): ArraySchema { let nullableItems = false; let elementType = type.valueType; if (elementType.kind === "nullable") { @@ -1889,7 +1885,7 @@ export class CodeModelBuilder { elementType = elementType.type; } - const elementSchema = this.processSchemaFromSdkType(elementType, name); + const elementSchema = this.processSchema(elementType, name); return this.codeModel.schemas.add( new ArraySchema(name, type.details ?? "", elementSchema, { summary: type.description, @@ -1898,10 +1894,7 @@ export class CodeModelBuilder { ); } - private processDictionarySchemaFromSdkType( - type: SdkDictionaryType, - name: string, - ): DictionarySchema { + private processDictionarySchema(type: SdkDictionaryType, name: string): DictionarySchema { const dictSchema = new DictionarySchema(name, type.details ?? "", null, { summary: type.description, }); @@ -1917,7 +1910,7 @@ export class CodeModelBuilder { nullableItems = true; elementType = elementType.type; } - const elementSchema = this.processSchemaFromSdkType(elementType, name); + const elementSchema = this.processSchema(elementType, name); dictSchema.elementType = elementSchema; dictSchema.nullableItems = nullableItems; @@ -1925,13 +1918,13 @@ export class CodeModelBuilder { return this.codeModel.schemas.add(dictSchema); } - private processChoiceSchemaFromSdkType( + private processChoiceSchema( type: SdkEnumType, name: string, ): ChoiceSchema | SealedChoiceSchema | ConstantSchema { const rawEnumType = type.__raw; const namespace = getNamespace(rawEnumType); - const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind); + const valueType = this.processSchema(type.valueType, type.valueType.kind); const choices: ChoiceValue[] = []; type.values.forEach((it: SdkEnumValueType) => @@ -1957,8 +1950,8 @@ export class CodeModelBuilder { return this.codeModel.schemas.add(schema); } - private processConstantSchemaFromSdkType(type: SdkConstantType, name: string): ConstantSchema { - const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind); + private processConstantSchema(type: SdkConstantType, name: string): ConstantSchema { + const valueType = this.processSchema(type.valueType, type.valueType.kind); return this.codeModel.schemas.add( new ConstantSchema(type.name ?? name, type.details ?? "", { @@ -1969,11 +1962,8 @@ export class CodeModelBuilder { ); } - private processConstantSchemaFromEnumValueFromSdkType( - type: SdkEnumValueType, - name: string, - ): ConstantSchema { - const valueType = this.processSchemaFromSdkType(type.enumType, type.enumType.name); + private processConstantSchemaFromEnumValue(type: SdkEnumValueType, name: string): ConstantSchema { + const valueType = this.processSchema(type.enumType, type.enumType.name); return this.codeModel.schemas.add( new ConstantSchema(type.name ?? name, type.details ?? "", { @@ -1984,7 +1974,7 @@ export class CodeModelBuilder { ); } - private processUnixTimeSchemaFromSdkType(type: SdkDateTimeType, name: string): UnixTimeSchema { + private processUnixTimeSchema(type: SdkDateTimeType, name: string): UnixTimeSchema { return this.codeModel.schemas.add( new UnixTimeSchema(name, type.details ?? "", { summary: type.description, @@ -1992,7 +1982,7 @@ export class CodeModelBuilder { ); } - private processDateTimeSchemaFromSdkType( + private processDateTimeSchema( type: SdkDateTimeType, name: string, rfc1123: boolean, @@ -2005,7 +1995,7 @@ export class CodeModelBuilder { ); } - private processDateSchemaFromSdkType(type: SdkBuiltInType, name: string): DateSchema { + private processDateSchema(type: SdkBuiltInType, name: string): DateSchema { return this.codeModel.schemas.add( new DateSchema(name, type.details ?? "", { summary: type.description, @@ -2013,7 +2003,7 @@ export class CodeModelBuilder { ); } - private processTimeSchemaFromSdkType(type: SdkBuiltInType, name: string): TimeSchema { + private processTimeSchema(type: SdkBuiltInType, name: string): TimeSchema { return this.codeModel.schemas.add( new TimeSchema(name, type.details ?? "", { summary: type.description, @@ -2021,7 +2011,7 @@ export class CodeModelBuilder { ); } - private processDurationSchemaFromSdkType( + private processDurationSchema( type: SdkDurationType, name: string, format: DurationSchema["format"] = "duration-rfc3339", @@ -2034,7 +2024,7 @@ export class CodeModelBuilder { ); } - private processUrlSchemaFromSdkType(type: SdkBuiltInType, name: string): UriSchema { + private processUrlSchema(type: SdkBuiltInType, name: string): UriSchema { return this.codeModel.schemas.add( new UriSchema(name, type.details ?? "", { summary: type.description, @@ -2042,7 +2032,7 @@ export class CodeModelBuilder { ); } - private processObjectSchemaFromSdkType(type: SdkModelType, name: string): ObjectSchema { + private processObjectSchema(type: SdkModelType, name: string): ObjectSchema { const rawModelType = type.__raw; const namespace = getNamespace(rawModelType); const objectSchema = new ObjectSchema(name, type.details ?? "", { @@ -2068,17 +2058,17 @@ export class CodeModelBuilder { // discriminator if (type.discriminatedSubtypes && type.discriminatorProperty) { objectSchema.discriminator = new Discriminator( - this.processModelPropertyFromSdkType(type.discriminatorProperty), + this.processModelProperty(type.discriminatorProperty), ); for (const discriminatorValue in type.discriminatedSubtypes) { const subType = type.discriminatedSubtypes[discriminatorValue]; - this.processSchemaFromSdkType(subType, subType.name); + this.processSchema(subType, subType.name); } } // type is a subtype if (type.baseModel) { - const parentSchema = this.processSchemaFromSdkType(type.baseModel, type.baseModel.name); + const parentSchema = this.processSchema(type.baseModel, type.baseModel.name); objectSchema.parents = new Relations(); objectSchema.parents.immediate.push(parentSchema); @@ -2116,7 +2106,7 @@ export class CodeModelBuilder { valueType: type.additionalProperties, decorators: [], }; - const parentSchema = this.processSchemaFromSdkType(sdkDictType, "Record"); + const parentSchema = this.processSchema(sdkDictType, "Record"); objectSchema.parents = objectSchema.parents ?? new Relations(); objectSchema.parents.immediate.push(parentSchema); pushDistinct(objectSchema.parents.all, parentSchema); @@ -2126,7 +2116,7 @@ export class CodeModelBuilder { // properties for (const prop of type.properties) { if (prop.kind === "property" && !prop.discriminator) { - objectSchema.addProperty(this.processModelPropertyFromSdkType(prop)); + objectSchema.addProperty(this.processModelProperty(prop)); } } @@ -2151,7 +2141,7 @@ export class CodeModelBuilder { return type; } - private processModelPropertyFromSdkType(prop: SdkModelPropertyType): Property { + private processModelProperty(prop: SdkModelPropertyType): Property { let nullable = false; let nonNullType = prop.type; if (nonNullType.kind === "nullable") { @@ -2180,21 +2170,21 @@ export class CodeModelBuilder { if (prop.kind === "property" && prop.multipartOptions) { // TODO: handle MultipartOptions.isMulti if (prop.multipartOptions.isFilePart) { - schema = this.processMultipartFormDataFilePropertySchemaFromSdkType(prop); + schema = this.processMultipartFormDataFilePropertySchema(prop); } else if ( prop.type.kind === "model" && prop.type.properties.some((it) => it.kind === "body") ) { // TODO: this is HttpPart of non-File. TCGC should help handle this. - schema = this.processSchemaFromSdkType( + schema = this.processSchema( prop.type.properties.find((it) => it.kind === "body")!.type, "", ); } else { - schema = this.processSchemaFromSdkType(nonNullType, ""); + schema = this.processSchema(nonNullType, ""); } } else { - schema = this.processSchemaFromSdkType(nonNullType, ""); + schema = this.processSchema(nonNullType, ""); } return new Property(prop.name, prop.details ?? "", schema, { @@ -2207,7 +2197,7 @@ export class CodeModelBuilder { }); } - private processUnionSchemaFromSdkType(type: SdkUnionType, name: string): Schema { + private processUnionSchema(type: SdkUnionType, name: string): Schema { if (!(type.__raw && type.__raw.kind === "Union")) { throw new Error(`Invalid type for union: '${type.kind}'.`); } @@ -2239,7 +2229,7 @@ export class CodeModelBuilder { }, }); - const variantSchema = this.processSchemaFromSdkType(it, variantName); + const variantSchema = this.processSchema(it, variantName); objectSchema.addProperty( new Property(propertyName, type.details ?? "", variantSchema, { summary: type.description, @@ -2252,7 +2242,7 @@ export class CodeModelBuilder { return this.codeModel.schemas.add(unionSchema); } - private processBinarySchemaFromSdkType(type: SdkBuiltInType): BinarySchema { + private processBinarySchema(type: SdkBuiltInType): BinarySchema { return this.codeModel.schemas.add( new BinarySchema(type.description ?? "", { summary: type.details, @@ -2316,10 +2306,8 @@ export class CodeModelBuilder { } } - private processMultipartFormDataFilePropertySchemaFromSdkType( - property: SdkBodyModelPropertyType, - ): Schema { - const processSchemaFunc = (type: SdkType) => this.processSchemaFromSdkType(type, ""); + private processMultipartFormDataFilePropertySchema(property: SdkBodyModelPropertyType): Schema { + const processSchemaFunc = (type: SdkType) => this.processSchema(type, ""); if (property.type.kind === "bytes" || property.type.kind === "model") { const namespace = property.type.kind === "model" diff --git a/packages/http-client-java/emitter/src/type-utils.ts b/packages/http-client-java/emitter/src/type-utils.ts index af526d032e..d2271fdff7 100644 --- a/packages/http-client-java/emitter/src/type-utils.ts +++ b/packages/http-client-java/emitter/src/type-utils.ts @@ -119,7 +119,7 @@ export function getDefaultValue(value: Value | undefined): any { return undefined; } -export function getDurationFormatFromSdkType(type: SdkDurationType): DurationSchema["format"] { +export function getDurationFormat(type: SdkDurationType): DurationSchema["format"] { let format: DurationSchema["format"] = "duration-rfc3339"; // duration encoded as seconds if (type.encode === "seconds") {