From d983279caed77a63e85216e8c960012be73131c6 Mon Sep 17 00:00:00 2001 From: mcgallan <88413158+mcgallan@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:02:02 +0800 Subject: [PATCH] Type/array/nullableelement test (#593) * Type/array nullable-element * Update mockapi.ts * update * Update pnpm-lock.yaml * Create shaggy-turkeys-applaud.md * Update wet-tomatoes-yawn.md * Update pnpm-lock.yaml * Update cadl-ranch-summary.md --------- Co-authored-by: Weidong Xu --- .changeset/shaggy-turkeys-applaud.md | 5 ++ .../cadl-ranch-specs/cadl-ranch-summary.md | 80 +++++++++++++++++++ .../cadl-ranch-specs/http/type/array/main.tsp | 25 ++++++ .../http/type/array/mockapi.ts | 16 ++++ 4 files changed, 126 insertions(+) create mode 100644 .changeset/shaggy-turkeys-applaud.md diff --git a/.changeset/shaggy-turkeys-applaud.md b/.changeset/shaggy-turkeys-applaud.md new file mode 100644 index 000000000..664da6f6d --- /dev/null +++ b/.changeset/shaggy-turkeys-applaud.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": patch +--- + +Add nullable int/string/boolean/model test cases for Type/Array diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index 76c9bf459..5577fa644 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -3433,6 +3433,26 @@ Expected Array input body: [{ "property": "hello" }, { "property": "world" }] ``` +### Type_Array_NullableBooleanValue_get + +- Endpoint: `get /type/array/nullable-boolean` + +Expected Array response body: + +```json +[true, null, false] +``` + +### Type_Array_NullableBooleanValue_put + +- Endpoint: `put /type/array/nullable-boolean` + +Expected Array input body: + +```json +[true, null, false] +``` + ### Type_Array_NullableFloatValue_get - Endpoint: `get /type/array/nullable-float` @@ -3453,6 +3473,66 @@ Expected Array input body: [1.25, null, 3.0] ``` +### Type_Array_NullableInt32Value_get + +- Endpoint: `get /type/array/nullable-int32` + +Expected Array response body: + +```json +[1, null, 3] +``` + +### Type_Array_NullableInt32Value_put + +- Endpoint: `put /type/array/nullable-int32` + +Expected Array input body: + +```json +[1, null, 3] +``` + +### Type_Array_NullableModelValue_get + +- Endpoint: `get /type/array/nullable-model` + +Expected Array response body: + +```json +[{ "property": "hello" }, null, { "property": "world" }] +``` + +### Type_Array_NullableModelValue_put + +- Endpoint: `put /type/array/nullable-model` + +Expected Array input body: + +```json +[{ "property": "hello" }, null, { "property": "world" }] +``` + +### Type_Array_NullableStringValue_get + +- Endpoint: `get /type/array/nullable-string` + +Expected Array response body: + +```json +["hello", null, "world"] +``` + +### Type_Array_NullableStringValue_put + +- Endpoint: `put /type/array/nullable-string` + +Expected Array input body: + +```json +["hello", null, "world"] +``` + ### Type_Array_StringValue_get - Endpoint: `get /type/array/string` diff --git a/packages/cadl-ranch-specs/http/type/array/main.tsp b/packages/cadl-ranch-specs/http/type/array/main.tsp index b846faab3..208824e2b 100644 --- a/packages/cadl-ranch-specs/http/type/array/main.tsp +++ b/packages/cadl-ranch-specs/http/type/array/main.tsp @@ -100,3 +100,28 @@ alias NullableFloat = float32 | null; @route("/nullable-float") @operationGroup interface NullableFloatValue extends ArrayOperations {} + +alias NullableInt32 = int32 | null; +@doc("Array of nullable int32 values") +@route("/nullable-int32") +@operationGroup +interface NullableInt32Value extends ArrayOperations {} + +alias NullableBoolean = boolean | null; +@doc("Array of nullable boolean values") +@route("/nullable-boolean") +@operationGroup +interface NullableBooleanValue extends ArrayOperations {} + +alias NullableString = string | null; +@doc("Array of nullable string values") +@route("/nullable-string") +@operationGroup +interface NullableStringValue extends ArrayOperations {} + +alias NullableModel = InnerModel | null; +@doc("Array of nullable model values") +@route("/nullable-model") +@operationGroup +interface NullableModelValue + extends ArrayOperations {} diff --git a/packages/cadl-ranch-specs/http/type/array/mockapi.ts b/packages/cadl-ranch-specs/http/type/array/mockapi.ts index 20c170305..775f0180e 100644 --- a/packages/cadl-ranch-specs/http/type/array/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/array/mockapi.ts @@ -69,3 +69,19 @@ Scenarios.Type_Array_ModelValue_put = passOnSuccess(ModelValueMock.put); const NullableFloatMock = createModelMockApis("nullable-float", [1.25, null, 3.0]); Scenarios.Type_Array_NullableFloatValue_get = passOnSuccess(NullableFloatMock.get); Scenarios.Type_Array_NullableFloatValue_put = passOnSuccess(NullableFloatMock.put); + +const NullableInt32Mock = createModelMockApis("nullable-int32", [1, null, 3]); +Scenarios.Type_Array_NullableInt32Value_get = passOnSuccess(NullableInt32Mock.get); +Scenarios.Type_Array_NullableInt32Value_put = passOnSuccess(NullableInt32Mock.put); + +const NullableStringMock = createModelMockApis("nullable-string", ["hello", null, "world"]); +Scenarios.Type_Array_NullableStringValue_get = passOnSuccess(NullableStringMock.get); +Scenarios.Type_Array_NullableStringValue_put = passOnSuccess(NullableStringMock.put); + +const NullableBooleanMock = createModelMockApis("nullable-boolean", [true, null, false]); +Scenarios.Type_Array_NullableBooleanValue_get = passOnSuccess(NullableBooleanMock.get); +Scenarios.Type_Array_NullableBooleanValue_put = passOnSuccess(NullableBooleanMock.put); + +const NullableModelMock = createModelMockApis("nullable-model", [{ property: "hello" }, null, { property: "world" }]); +Scenarios.Type_Array_NullableModelValue_get = passOnSuccess(NullableModelMock.get); +Scenarios.Type_Array_NullableModelValue_put = passOnSuccess(NullableModelMock.put);