From 83c27fa06010a11698487ab851e578bc7d9f36e2 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 6 Mar 2025 14:47:05 +0800 Subject: [PATCH 1/3] add orphanModelSerializable op --- packages/azure-http-specs/spec-summary.md | 6 +++-- .../client-generator-core/usage/main.tsp | 25 +++++++++++++++++-- .../client-generator-core/usage/mockapi.ts | 14 +++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index ab44f97bac..c7853b725f 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -127,9 +127,11 @@ Expected response body: - `post /azure/client-generator-core/usage/inputToInputOutput` - `post /azure/client-generator-core/usage/outputToInputOutput` - `post /azure/client-generator-core/usage/modelInReadOnlyProperty` + - `post /azure/client-generator-core/usage/orphanModelSerializable` -This scenario contains two public operations. Both should be generated and exported. -The models are override to roundtrip, so they should be generated and exported as well. +This scenario contains 4 public operations. All should be generated and exported. +'OrphanModel' is not used but specified as 'public' and 'input', so it should be generated in SDK. The 'orphanModelSerializable' operation verifies that the model can be serialized to JSON. +The other models are override to roundtrip, so they should be generated and exported as well. ### Azure_Core_Basic_createOrReplace diff --git a/packages/azure-http-specs/specs/azure/client-generator-core/usage/main.tsp b/packages/azure-http-specs/specs/azure/client-generator-core/usage/main.tsp index f6fde1e697..6052539241 100644 --- a/packages/azure-http-specs/specs/azure/client-generator-core/usage/main.tsp +++ b/packages/azure-http-specs/specs/azure/client-generator-core/usage/main.tsp @@ -13,8 +13,9 @@ namespace _Specs_.Azure.ClientGenerator.Core.Usage; @scenario @scenarioDoc(""" - This scenario contains two public operations. Both should be generated and exported. - The models are override to roundtrip, so they should be generated and exported as well. + This scenario contains 4 public operations. All should be generated and exported. + 'OrphanModel' is not used but specified as 'public' and 'input', so it should be generated in SDK. The 'orphanModelSerializable' operation verifies that the model can be serialized to JSON. + The other models are override to roundtrip, so they should be generated and exported as well. """) @global.Azure.ClientGenerator.Core.clientNamespace("azure.clientgenerator.core.usage", "java") namespace ModelInOperation { @@ -90,11 +91,31 @@ namespace ModelInOperation { op modelInReadOnlyProperty(@body body: RoundTripModel): { @body body: RoundTripModel; }; + + @doc(""" + Serialize the 'OrphanModel' as request body. + + Expected body parameter: + ```json + { + "name": "name", + "desc": "desc" + } + ``` + """) + @global.Azure.ClientGenerator.Core.convenientAPI(false) + @route("/orphanModelSerializable") + @put + op orphanModelSerializable(@body body: unknown): NoContentResponse; } @doc("Not used anywhere, but access is override to public so still need to be generated and exported with serialization.") @global.Azure.ClientGenerator.Core.usage(global.Azure.ClientGenerator.Core.Usage.input) @global.Azure.ClientGenerator.Core.access(global.Azure.ClientGenerator.Core.Access.public) model OrphanModel { + @global.Azure.ClientGenerator.Core.clientName("modelName") name: string; + + @encodedName("application/json", "desc") + description: string; } diff --git a/packages/azure-http-specs/specs/azure/client-generator-core/usage/mockapi.ts b/packages/azure-http-specs/specs/azure/client-generator-core/usage/mockapi.ts index a72e2987a5..21c06c9426 100644 --- a/packages/azure-http-specs/specs/azure/client-generator-core/usage/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/client-generator-core/usage/mockapi.ts @@ -36,4 +36,18 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([ }, kind: "MockApiDefinition", }, + { + uri: "/azure/client-generator-core/usage/orphanModelSerializable", + method: "put", + request: { + body: { + name: "name", + desc: "desc", + }, + }, + response: { + status: 204, + }, + kind: "MockApiDefinition", + }, ]); From 2159dea58eb18fcb3c8ebd0df3f29ad5028b4234 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 6 Mar 2025 14:48:28 +0800 Subject: [PATCH 2/3] changelog --- ...validate-orphan-model-serializable-2025-2-6-14-48-18.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/azure-http-specs_validate-orphan-model-serializable-2025-2-6-14-48-18.md diff --git a/.chronus/changes/azure-http-specs_validate-orphan-model-serializable-2025-2-6-14-48-18.md b/.chronus/changes/azure-http-specs_validate-orphan-model-serializable-2025-2-6-14-48-18.md new file mode 100644 index 0000000000..8691cdca9e --- /dev/null +++ b/.chronus/changes/azure-http-specs_validate-orphan-model-serializable-2025-2-6-14-48-18.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/azure-http-specs" +--- + +Add orphanModelSerializable operation to verify the JSON serialization of an orphan model \ No newline at end of file From 0d165c58c3b4b0097349194cb32289bcff6b23e8 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 6 Mar 2025 14:55:50 +0800 Subject: [PATCH 3/3] a minor fix for java --- packages/azure-http-specs/specs/azure/core/traits/main.tsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/azure-http-specs/specs/azure/core/traits/main.tsp b/packages/azure-http-specs/specs/azure/core/traits/main.tsp index 87ef910d6a..6a7958eecb 100644 --- a/packages/azure-http-specs/specs/azure/core/traits/main.tsp +++ b/packages/azure-http-specs/specs/azure/core/traits/main.tsp @@ -21,7 +21,7 @@ using Spector; } ) @versioned(Versions) -@global.Azure.ClientGenerator.Core.clientNamespace("azure.core.trait", "java") +@global.Azure.ClientGenerator.Core.clientNamespace("azure.core.traits", "java") namespace _Specs_.Azure.Core.Traits; @doc("Service versions")