Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fix modle name in merge and patch #1647

Merged
merged 15 commits into from
Nov 8, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {
ParameterLocation,
Property,
SchemaContext,
ObjectSchema as M4ObjectSchema,
Request as M4OperationRequest
} from "@autorest/codemodel";
import {
ImportKind,
ObjectSchema,
OperationParameter,
ParameterBodyMetadata,
ParameterMetadata,
Schema
} from "@azure-tools/rlc-common";
import { transformObject } from "./transformSchemas";
import { getLanguageMetadata } from "../../utils/languageHelpers";
import { NameType, normalizeName } from "../../utils/nameUtils";
import { getDocs } from "../getPropertySignature";
Expand Down Expand Up @@ -61,7 +64,11 @@ export function transformParameterTypes(
// transform content type param
const contentTypeParam = transformContentTypeParameter(request);
// transform body
const bodyParameter = transformBodyParameters(parameters, importedModels);
const bodyParameter = transformBodyParameters(
parameters,
importedModels,
contentTypeParam
);
rlcParameter.parameters.push({
parameters: [
...queryParams,
Expand Down Expand Up @@ -147,7 +154,8 @@ function transformContentTypeParameter(

function transformBodyParameters(
parameters: Parameter[],
importedModels: Set<string>
importedModels: Set<string>,
contentTypeParam: ParameterMetadata[]
): ParameterBodyMetadata | undefined {
const bodyParameters = parameters.filter(p => p.protocol.http?.in === "body");
if (!bodyParameters.length) {
Expand All @@ -159,10 +167,12 @@ function transformBodyParameters(
};
if (isPartialBody) {
rlcBodyParam.body = bodyParameters.map(bp =>
getParamterSchema(bp, importedModels)
getParameterSchema(bp, importedModels, false, contentTypeParam)
);
} else {
rlcBodyParam.body = [getParamterSchema(bodyParameters[0], importedModels)];
rlcBodyParam.body = [
getParameterSchema(bodyParameters[0], importedModels, false, contentTypeParam)
];
}

return rlcBodyParam;
Expand All @@ -174,7 +184,7 @@ function getParameterMetadata(
importedModels = new Set<string>(),
isPrimitiveSchema = false
) {
const schema: Schema = getParamterSchema(
const schema: Schema = getParameterSchema(
parameter,
importedModels,
isPrimitiveSchema
Expand All @@ -186,11 +196,12 @@ function getParameterMetadata(
};
}

function getParamterSchema(
function getParameterSchema(
parameter: Property | Parameter,
importedModels = new Set<string>(),
isPrimitiveSchema = false
): Schema {
isPrimitiveSchema = false,
contentTypeParam: ParameterMetadata[] = []
): ObjectSchema {
const propertyLangMetadata = getLanguageMetadata(parameter.language);
const propertyName = `"${propertyLangMetadata.serializedName ??
(parameter as Property).serializedName}"`;
Expand All @@ -215,7 +226,22 @@ function getParamterSchema(
importedModels
);
}
if (
contentTypeParam.length === 1 &&
contentTypeParam[0].param.type.includes("application/merge-patch+json")
) {
const schema = transformObject(parameter.schema as M4ObjectSchema);
type = `${type}ResourceMergeAndPatch`;

return {
name: propertyName,
type,
description,
required: parameter.required,
properties: schema.properties,
typeName: schema.name
};
}
return {
name: propertyName,
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export interface SalmonParent extends FishParent {
}

export interface ReadonlyObj {
id?: string;
size?: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface SalmonOutputParent extends FishOutputParent {
}

export interface ReadonlyObjOutput {
id?: string;
readonly id?: string;
size?: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,13 @@ export interface Product extends Resource {

export interface ProductProperties {
provisioningState?: string;
provisioningStateValues?:
| "Succeeded"
| "Failed"
| "canceled"
| "Accepted"
| "Creating"
| "Created"
| "Updating"
| "Updated"
| "Deleting"
| "Deleted"
| "OK";
}

export interface Resource {
/** Resource Id */
id?: string;
/** Resource Type */
type?: string;
/** Dictionary of <string> */
tags?: Record<string, string>;
/** Resource Location */
location?: string;
/** Resource Name */
name?: string;
}

export interface Sku {
Expand All @@ -45,21 +27,6 @@ export interface SubProduct extends SubResource {

export interface SubProductProperties {
provisioningState?: string;
provisioningStateValues?:
| "Succeeded"
| "Failed"
| "canceled"
| "Accepted"
| "Creating"
| "Created"
| "Updating"
| "Updated"
| "Deleting"
| "Deleted"
| "OK";
}

export interface SubResource {
/** Sub Resource Id */
id?: string;
}
export interface SubResource {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ProductOutput extends ResourceOutput {

export interface ProductPropertiesOutput {
provisioningState?: string;
provisioningStateValues?:
readonly provisioningStateValues?:
| "Succeeded"
| "Failed"
| "canceled"
Expand All @@ -23,15 +23,15 @@ export interface ProductPropertiesOutput {

export interface ResourceOutput {
/** Resource Id */
id?: string;
readonly id?: string;
/** Resource Type */
type?: string;
readonly type?: string;
/** Dictionary of <string> */
tags?: Record<string, string>;
/** Resource Location */
location?: string;
/** Resource Name */
name?: string;
readonly name?: string;
}

export interface CloudErrorOutput {
Expand All @@ -50,7 +50,7 @@ export interface SubProductOutput extends SubResourceOutput {

export interface SubProductPropertiesOutput {
provisioningState?: string;
provisioningStateValues?:
readonly provisioningStateValues?:
| "Succeeded"
| "Failed"
| "canceled"
Expand All @@ -66,5 +66,5 @@ export interface SubProductPropertiesOutput {

export interface SubResourceOutput {
/** Sub Resource Id */
id?: string;
readonly id?: string;
}
Loading