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

Fix bugs found in Network.Analytics RP #2333

Merged
merged 7 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface DeleteMultivariateModelDefaultHeaders {
// @public (undocumented)
export interface DeleteMultivariateModelDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
// (undocumented)
headers: RawHttpHeaders & DeleteMultivariateModelDefaultHeaders;
// (undocumented)
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface DetectMultivariateBatchAnomalyDefaultHeaders {
// @public (undocumented)
export interface DetectMultivariateBatchAnomalyDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
// (undocumented)
headers: RawHttpHeaders & DetectMultivariateBatchAnomalyDefaultHeaders;
// (undocumented)
Expand Down Expand Up @@ -129,7 +129,7 @@ export interface DetectMultivariateLastAnomalyDefaultHeaders {
// @public (undocumented)
export interface DetectMultivariateLastAnomalyDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
// (undocumented)
headers: RawHttpHeaders & DetectMultivariateLastAnomalyDefaultHeaders;
// (undocumented)
Expand Down Expand Up @@ -271,7 +271,7 @@ export interface GetMultivariateBatchDetectionResultDefaultHeaders {
// @public (undocumented)
export interface GetMultivariateBatchDetectionResultDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
// (undocumented)
headers: RawHttpHeaders & GetMultivariateBatchDetectionResultDefaultHeaders;
// (undocumented)
Expand All @@ -297,7 +297,7 @@ export interface GetMultivariateModelDefaultHeaders {
// @public (undocumented)
export interface GetMultivariateModelDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
// (undocumented)
headers: RawHttpHeaders & GetMultivariateModelDefaultHeaders;
// (undocumented)
Expand Down Expand Up @@ -359,7 +359,7 @@ export interface ListMultivariateModelsDefaultHeaders {
// @public (undocumented)
export interface ListMultivariateModelsDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
MaryGao marked this conversation as resolved.
Show resolved Hide resolved
// (undocumented)
headers: RawHttpHeaders & ListMultivariateModelsDefaultHeaders;
// (undocumented)
Expand Down Expand Up @@ -548,6 +548,12 @@ export interface MultivariateMultivariateLastDetectionResultOutput {
variableStates?: Array<MultivariateVariableStateOutput>;
}

// @public
export interface MultivariateResponseErrorOutput {
code: string;
message: string;
}

// @public
export interface MultivariateVariableState {
effectiveCount?: number;
Expand Down Expand Up @@ -638,7 +644,7 @@ export interface TrainMultivariateModelDefaultHeaders {
// @public (undocumented)
export interface TrainMultivariateModelDefaultResponse extends HttpResponse {
// (undocumented)
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
// (undocumented)
headers: RawHttpHeaders & TrainMultivariateModelDefaultHeaders;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ export interface MultivariateCorrelationChangesOutput {
changedVariables?: string[];
}

/** Error response */
export interface MultivariateResponseErrorOutput {
/** The error code. */
code: string;
/** The message explaining the error reported by the service. */
message: string;
}

/**
* Training result of a model including its status, errors and diagnostics
* information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
UnivariateUnivariateLastDetectionResultOutput,
UnivariateUnivariateChangePointDetectionResultOutput,
MultivariateMultivariateDetectionResultOutput,
MultivariateErrorResponseOutput,
MultivariateResponseErrorOutput,
MultivariateAnomalyDetectionModelOutput,
MultivariateModelListOutput,
MultivariateMultivariateLastDetectionResultOutput,
Expand Down Expand Up @@ -83,7 +83,7 @@ export interface GetMultivariateBatchDetectionResultDefaultHeaders {
export interface GetMultivariateBatchDetectionResultDefaultResponse
extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & GetMultivariateBatchDetectionResultDefaultHeaders;
}

Expand All @@ -106,7 +106,7 @@ export interface TrainMultivariateModelDefaultHeaders {

export interface TrainMultivariateModelDefaultResponse extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & TrainMultivariateModelDefaultHeaders;
}

Expand All @@ -123,7 +123,7 @@ export interface ListMultivariateModelsDefaultHeaders {

export interface ListMultivariateModelsDefaultResponse extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & ListMultivariateModelsDefaultHeaders;
}

Expand All @@ -139,7 +139,7 @@ export interface DeleteMultivariateModelDefaultHeaders {

export interface DeleteMultivariateModelDefaultResponse extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & DeleteMultivariateModelDefaultHeaders;
}

Expand All @@ -156,7 +156,7 @@ export interface GetMultivariateModelDefaultHeaders {

export interface GetMultivariateModelDefaultResponse extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & GetMultivariateModelDefaultHeaders;
}

Expand All @@ -183,7 +183,7 @@ export interface DetectMultivariateBatchAnomalyDefaultHeaders {
export interface DetectMultivariateBatchAnomalyDefaultResponse
extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & DetectMultivariateBatchAnomalyDefaultHeaders;
}

Expand All @@ -201,6 +201,6 @@ export interface DetectMultivariateLastAnomalyDefaultHeaders {
export interface DetectMultivariateLastAnomalyDefaultResponse
extends HttpResponse {
status: string;
body: MultivariateErrorResponseOutput;
body: MultivariateResponseErrorOutput;
headers: RawHttpHeaders & DetectMultivariateLastAnomalyDefaultHeaders;
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface TextAnalyzeSeverityResult {

// @public
export interface TextBlockItem {
readonly blockItemId: string;
blockItemId: string;
description?: string;
text: string;
}
Expand All @@ -188,7 +188,7 @@ export interface TextBlockItemInfo {

// @public
export interface TextBlocklist {
readonly blocklistName: string;
blocklistName: string;
description?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export function _createOrUpdateTextBlocklistSend(
...operationOptionsToRequestParameters(options),
contentType:
(options.contentType as any) ?? "application/merge-patch+json",
body: { description: resource["description"] },
body: {
blocklistName: resource["blocklistName"],
description: resource["description"],
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/** Text Blocklist. */
export interface TextBlocklist {
/** Text blocklist name. */
readonly blocklistName: string;
blocklistName: string;
/** Text blocklist description. */
description?: string;
}
Expand Down Expand Up @@ -32,7 +32,7 @@ export interface AddOrUpdateBlockItemsResult {
/** Item in TextBlocklist. */
export interface TextBlockItem {
/** Block Item Id. It will be uuid. */
readonly blockItemId: string;
blockItemId: string;
/** Block item description. */
description?: string;
/** Block item content. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export interface ErrorModelOutput {
message: string;
}

// @public (undocumented)
export interface InvalidTodoItemOutput extends ErrorModelOutput {
}

// @public
export interface InvalidUserResponseOutput extends ErrorModelOutput {
}

// @public (undocumented)
export interface Routes {
(path: "/users"): UsersCreate;
Expand Down Expand Up @@ -194,7 +202,7 @@ export interface TodoItemsCreateForm200Response extends HttpResponse {
// @public
export interface TodoItemsCreateForm422Response extends HttpResponse {
// (undocumented)
body: ErrorModelOutput;
body: InvalidTodoItemOutput;
// (undocumented)
status: "422";
}
Expand Down Expand Up @@ -228,7 +236,7 @@ export interface TodoItemsCreateJson200Response extends HttpResponse {
// @public
export interface TodoItemsCreateJson422Response extends HttpResponse {
// (undocumented)
body: ErrorModelOutput;
body: InvalidTodoItemOutput;
// (undocumented)
status: "422";
}
Expand Down Expand Up @@ -413,6 +421,10 @@ export interface UserCreatedResponseOutput {
username: string;
}

// @public
export interface UserExistsResponseOutput extends ErrorModelOutput {
}

// @public (undocumented)
export interface UsersCreate {
// (undocumented)
Expand All @@ -430,15 +442,15 @@ export interface UsersCreate200Response extends HttpResponse {
// @public
export interface UsersCreate409Response extends HttpResponse {
// (undocumented)
body: ErrorModelOutput;
body: UserExistsResponseOutput;
// (undocumented)
status: "409";
}

// @public
export interface UsersCreate422Response extends HttpResponse {
// (undocumented)
body: ErrorModelOutput;
body: InvalidUserResponseOutput;
// (undocumented)
status: "422";
}
Expand Down Expand Up @@ -575,7 +587,7 @@ export interface UsersValidate200Response extends HttpResponse {
// @public
export interface UsersValidate422Response extends HttpResponse {
// (undocumented)
body: ErrorModelOutput;
body: InvalidUserResponseOutput;
// (undocumented)
status: "422";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ export interface UserCreatedResponseOutput {
token: string;
}

/** The user already exists */
export interface UserExistsResponseOutput extends ErrorModelOutput {}

export interface ErrorModelOutput {
/** A machine readable error code */
code: string;
/** A human readable message */
message: string;
}

/** The user is invalid (e.g. forgot to enter email address) */
export interface InvalidUserResponseOutput extends ErrorModelOutput {}

export interface InvalidTodoItemOutput extends ErrorModelOutput {}

export interface TodoPageOutput {
/** The items in the page */
items: Array<TodoItemOutput>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import { HttpResponse } from "@typespec/ts-http-runtime";
import {
UserCreatedResponseOutput,
ErrorModelOutput,
UserExistsResponseOutput,
InvalidUserResponseOutput,
TodoPageOutput,
TodoItemOutput,
InvalidTodoItemOutput,
TodoAttachmentOutput,
} from "./outputModels";

Expand All @@ -18,13 +20,13 @@ export interface UsersCreate200Response extends HttpResponse {
/** The request conflicts with the current state of the server. */
export interface UsersCreate409Response extends HttpResponse {
status: "409";
body: ErrorModelOutput;
body: UserExistsResponseOutput;
}

/** Client error */
export interface UsersCreate422Response extends HttpResponse {
status: "422";
body: ErrorModelOutput;
body: InvalidUserResponseOutput;
}

/** The request has succeeded. */
Expand All @@ -35,7 +37,7 @@ export interface UsersValidate200Response extends HttpResponse {
/** Client error */
export interface UsersValidate422Response extends HttpResponse {
status: "422";
body: ErrorModelOutput;
body: InvalidUserResponseOutput;
}

/** The request has succeeded. */
Expand Down Expand Up @@ -88,7 +90,7 @@ export interface TodoItemsCreateJson200Response extends HttpResponse {
/** Client error */
export interface TodoItemsCreateJson422Response extends HttpResponse {
status: "422";
body: ErrorModelOutput;
body: InvalidTodoItemOutput;
}

/** The request has succeeded. */
Expand All @@ -100,7 +102,7 @@ export interface TodoItemsCreateForm200Response extends HttpResponse {
/** Client error */
export interface TodoItemsCreateForm422Response extends HttpResponse {
status: "422";
body: ErrorModelOutput;
body: InvalidTodoItemOutput;
}

/** The request has succeeded. */
Expand Down
15 changes: 10 additions & 5 deletions packages/typespec-ts/src/modular/buildCodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,25 @@ function getEffectiveSchemaType(program: Program, type: Model | Union): Model {
return !(headerInfo || queryInfo || pathInfo || statusCodeinfo);
}

let effective: Model;
// If type is an anonymous model, tries to find a named model that has the same properties
let effective: Model | undefined = undefined;
if (type.kind === "Union") {
const nonNullOptions = [...type.variants.values()]
.map((x) => x.type)
.filter((t) => !isNullType(t));
if (nonNullOptions.length === 1 && nonNullOptions[0]?.kind === "Model") {
if (
nonNullOptions.length === 1 &&
nonNullOptions[0]?.kind === "Model" &&
nonNullOptions[0]?.name === ""
) {
effective = getEffectiveModelType(program, nonNullOptions[0]);
}
return type as any;
} else {
} else if (type.name === "") {
effective = getEffectiveModelType(program, type, isSchemaProperty);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only apply getEffectiveModelType for anonymous model due to microsoft/typespec#2991 (comment)

}

if (effective.name) {
if (effective?.name) {
return effective;
}
return type as Model;
Expand Down Expand Up @@ -951,7 +956,7 @@ function isReadOnly(program: Program, type: ModelProperty): boolean {
// Only "read" should be readOnly
const visibility = getVisibility(program, type);
if (visibility) {
return visibility.includes("read");
return visibility.includes("read") && visibility.length === 1;
} else {
return false;
}
Expand Down
Loading
Loading