Skip to content

Commit a867e60

Browse files
tg123brendandburns
authored andcommitted
csharp generator update for v1.8 (#39)
* handle intorstr and quantity in csharp * remove generated public property from quantity * add comment why mkdir before docker build
1 parent 86d53c7 commit a867e60

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

openapi/csharp.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ popd > /dev/null
4747
source "${SCRIPT_ROOT}/client-generator.sh"
4848
source "${SETTING_FILE}"
4949

50+
# this is to ensure sed after docker build has perm to modify files generated
51+
mkdir -p ${OUTPUT_DIR}/Models/
52+
5053
# TODO(brendandburns): Update CLEANUP_DIRS
5154
CLIENT_LANGUAGE=csharp; CLEANUP_DIRS=(docs src target gradle); kubeclient::generator::generate_client "${OUTPUT_DIR}"
5255

53-
5456
# hack for generating empty host url
5557
sed -i '/BaseUri = new System.Uri(\"\");/ d' ${OUTPUT_DIR}/Kubernetes.cs
58+
59+
# remove public prop from Quantity, (autorest cannot generate empty class)
60+
sed -i '/JsonProperty/ d' ${OUTPUT_DIR}/Models/ResourceQuantity.cs
61+
sed -i 's/public string Value/private string Value/' ${OUTPUT_DIR}/Models/ResourceQuantity.cs

openapi/csharp.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
<argument>--debug</argument>
4444
<argument>--verbose</argument>
4545
<argument>--directive={from: "swagger-document", where: "$..*[?(@.consumes[0] === \"*/*\")]", transform: "$.consumes[0] = \"application/json\""}</argument>
46-
<argument>--directive={from: "swagger-document", where: "$.definitions", transform: "$[\"IntOrString\"] = {\"properties\": { \"value\": { \"type\": \"string\" }}}"}</argument>
47-
<argument>--directive={from: "swagger-document", where: "$..*[?(@.format === \"int-or-string\")]", transform: "delete $.type; delete $.format; $[\"$ref\"] = \"#/definitions/IntOrString\""}</argument>
46+
<argument>--directive={from: "swagger-document", where: "$.definitions", transform: "$[\"intstr.IntOrString\"] = {\"properties\": { \"value\": { \"type\": \"string\" }}}"}</argument>
47+
<argument>--directive={from: "swagger-document", where: "$.definitions", transform: "$[\"resource.Quantity\"] = {\"properties\": { \"value\": { \"type\": \"string\" }}}"}</argument>
4848
<argument>--use=@microsoft.azure/autorest.csharp@preview</argument>
4949
</arguments>
5050
</configuration>

openapi/preprocess_spec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def process_swagger(spec, client_language):
134134
def preserved_primitives_for_language(client_language):
135135
if client_language == "java":
136136
return ["intstr.IntOrString", "resource.Quantity"]
137+
elif client_language == "csharp":
138+
return ["intstr.IntOrString", "resource.Quantity"]
137139
else:
138140
return []
139141

0 commit comments

Comments
 (0)