@@ -4,14 +4,19 @@ These settings apply only when `--go` is specified on the command line.
4
4
5
5
``` yaml
6
6
input-file :
7
- - https://github.com/mikekistler/azure-rest-api-specs/blob/baed660fd853b4a387ca9f0b9491fd1414b66e9e/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-03-15-preview/inference.json
7
+ # - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/13a645b66b741e3cc2ef378cb81974b30e6a7a86/specification/cognitiveservices/AzureOpenAI/inference/2023-06-01-preview/generated.json
8
+ - ./testdata/generated/openapi3.json
9
+
8
10
output-folder : ../azopenai
9
11
clear-output-folder : false
10
12
module : github.com/Azure/azure-sdk-for-go/sdk/cognitiveservices/azopenai
11
13
license-header : MICROSOFT_MIT_NO_VERSION
12
14
openapi-type : data-plane
13
15
go : true
14
- use :
" @autorest/[email protected] "
16
+ use :
" @autorest/[email protected] "
17
+ title : " OpenAI"
18
+ slice-elements-byval : true
19
+ remove-non-reference-schema : true
15
20
` ` `
16
21
17
22
## Transformations
@@ -30,25 +35,18 @@ directive:
30
35
where : $.paths..parameters..[?(@.name=='deploymentId')]
31
36
transform : $["x-ms-parameter-location"] = "client";
32
37
33
- # Update operationIds to combine all operations into a single client
34
- - rename-operation :
35
- from : getCompletions
36
- to : OpenAI_GetCompletions
37
- - rename-operation :
38
- from : getEmbeddings
39
- to : OpenAI_GetEmbeddings
40
- - rename-operation :
41
- from : getChatCompletions
42
- to : OpenAI_GetChatCompletions
43
-
44
- # Mark request bodies as required (TypeSpec issue #1838)
45
38
- from : openapi-document
46
- where : $.paths["/deployments/{deploymentId}/completions"].post.requestBody
39
+ where : $.. paths["/deployments/{deploymentId}/completions"].post.requestBody
47
40
transform : $["required"] = true;
48
41
- from : openapi-document
49
42
where : $.paths["/deployments/{deploymentId}/embeddings"].post.requestBody
50
43
transform : $["required"] = true;
51
44
45
+ # get rid of these auto-generated LRO status methods that aren't exposed.
46
+ - from : openapi-document
47
+ where : $.paths
48
+ transform : delete $["/operations/images/{operationId}"]
49
+
52
50
# Remove stream property from CompletionsOptions and ChatCompletionsOptions
53
51
- from : openapi-document
54
52
where : $.components.schemas["CompletionsOptions"]
@@ -62,25 +60,44 @@ directive:
62
60
where : ' $.components.schemas["EmbeddingsOptions"].properties["input"]'
63
61
transform : delete $.anyOf;
64
62
63
+ - from : openapi-document
64
+ where : $.paths["/images/generations:submit"].post
65
+ transform : $["x-ms-long-running-operation"] = true;
66
+
65
67
# Fix autorest bug
68
+ - from : openapi-document
69
+ where : $.components.schemas["BatchImageGenerationOperationResponse"].properties
70
+ transform : |
71
+ $.result["$ref"] = "#/components/schemas/ImageGenerations"; delete $.allOf;
72
+ $.status["$ref"] = "#/components/schemas/AzureOpenAIOperationState"; delete $.allOf;
73
+ $.error["$ref"] = "#/components/schemas/Azure.Core.Foundations.Error"; delete $.allOf;
66
74
- from : openapi-document
67
75
where : $.components.schemas["ChatMessage"].properties.role
68
- transform : >
69
- delete $.allOf;
70
- $["$ref"] = "#/components/schemas/ChatRole";
71
-
72
- # Fix another autorest bug
76
+ transform : $["$ref"] = "#/components/schemas/ChatRole"; delete $.oneOf;
73
77
- from : openapi-document
74
78
where : $.components.schemas["Choice"].properties.finish_reason
75
- transform : >
76
- delete $.oneOf;
77
- $["$ref"] = "#/components/schemas/CompletionsFinishReason";
79
+ transform : $["$ref"] = "#/components/schemas/CompletionsFinishReason"; delete $.oneOf;
80
+ - from : openapi-document
81
+ where : $.components.schemas["ImageOperation"].properties.status
82
+ transform : $["$ref"] = $.anyOf[0]["$ref"];delete $.anyOf;
83
+ - from : openapi-document
84
+ where : $.components.schemas["ImageGenerationOptions"].properties
85
+ transform : |
86
+ $.size["$ref"] = "#/components/schemas/ImageSize"; delete $.allOf;
87
+ $.response_format["$ref"] = "#/components/schemas/ImageGenerationResponseFormat"; delete $.allOf;
88
+ - from : openapi-document
89
+ where : $.components.schemas["ImageOperationResponse"].properties
90
+ transform : |
91
+ $.status["$ref"] = "#/components/schemas/State"; delete $.status.allOf;
92
+ $.result["$ref"] = "#/components/schemas/ImageResponse"; delete $.status.allOf;
93
+ - from : openapi-document
94
+ where : $.components.schemas["ImageOperationStatus"].properties.status
95
+ transform : $["$ref"] = "#/components/schemas/State"; delete $.allOf;
78
96
- from : openapi-document
79
97
where : $.components.schemas["ChatChoice"].properties.finish_reason
80
98
transform : >
81
99
delete $.oneOf;
82
100
$["$ref"] = "#/components/schemas/CompletionsFinishReason";
83
-
84
101
# Fix "AutoGenerated" models
85
102
- from : openapi-document
86
103
where : $.components.schemas["ChatCompletions"].properties.usage
@@ -108,28 +125,29 @@ directive:
108
125
/(\s+)urlPath\s*:=\s*"\/deployments\/\{deploymentId\}\/([^"]+)".+?url\.PathEscape.+?\n/gs,
109
126
"$1urlPath := \"$2\"\n")
110
127
128
+ # Unexport the the poller state enum.
129
+ - from :
130
+ - constants.go
131
+ - models.go
132
+ where : $
133
+ transform : return $.replace(/AzureOpenAIOperationState/g, "azureOpenAIOperationState");
134
+
111
135
# splice out the auto-generated `deploymentID` field from the client
112
136
- from : client.go
113
137
where : $
114
138
transform : >-
115
139
return $.replace(
116
- /(type Client struct.+?)deploymentID string( [^}]+})/s,
117
- "$1$2 ")
140
+ /(type Client struct[^}]+})/s,
141
+ "type Client struct {\ninternal *azcore.Client; clientData;\n} ")
118
142
119
- # delete unused error models
120
- - from : models.go
121
- where : $
122
- transform : >-
123
- return $.replace(
124
- /\/\/ AzureCoreFoundations.*?type AzureCoreFoundations(Error|ErrorResponse|ErrorResponseError|InnerError|InnerErrorInnererror|ErrorInnererror) struct \{[^}]+\}/gs,
125
- "")
126
- - from : models_serde.go
143
+ - from :
144
+ - models_serde.go
145
+ - models.go
127
146
where : $
128
- transform : >-
129
- return $.replace(
130
- /\/\/ (UnmarshalJSON|MarshalJSON) implements.*?AzureCoreFoundations.*?func.+?\n}/gs,
131
- "")
132
- - from : models_serde.go
147
+ transform : return $.replace(/AzureCoreFoundations/g, "azureCoreFoundations");
148
+ - from :
149
+ - models_serde.go
150
+ - models.go
133
151
where : $
134
152
transform : return $.replace(/(?:\/\/.*\s)?func \(\w \*?(?:ErrorResponse|ErrorResponseError|InnerError|InnerErrorInnererror)\).*\{\s(?:.+\s)+\}\s/g, "");
135
153
@@ -144,7 +162,74 @@ directive:
144
162
- from :
145
163
- client.go
146
164
- models.go
147
- - response_types.go
165
+ - options.go
166
+ - response_types.go
148
167
where : $
149
168
transform : return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2");
169
+
170
+ # allow interception of formatting the URL path
171
+ - from : client.go
172
+ where : $
173
+ transform : return $.replace(/runtime\.JoinPaths\(client.endpoint, urlPath\)/g, "client.formatURL(urlPath)");
174
+
175
+ - from : models.go
176
+ where : $
177
+ transform : |
178
+ return $.replace(/type ImageGenerationsDataItem struct {[^}]+}/, "// ImageGenerationsDataItem represents an image URL or payload\ntype ImageGenerationsDataItem struct{\nImageLocation\nImagePayload\n}");
179
+
180
+ # delete the auto-generated ImageGenerationsDataItem, we handle that custom
181
+ - from : models.go
182
+ where : $
183
+ transform : return $.replace(/\/\/ ImageGenerationsDataItem represents[^}]+}/s, "");
184
+
185
+ # rename the image constants
186
+ - from : constants.go
187
+ where : $
188
+ transform : |
189
+ return $.replace(/ImageSizeFiveHundredTwelveX512/g, "ImageSize512x512")
190
+ .replace(/ImageSizeOneThousandTwentyFourX1024/g, "ImageSize1024x1024")
191
+ .replace(/ImageSizeTwoHundredFiftySixX256/g, "ImageSize256x256");
192
+
193
+ # scrub the Image(Payload|Location) deserializers.
194
+ - from : models_serde.go
195
+ where : $
196
+ transform : |
197
+ return $.replace(/\/\/ UnmarshalJSON implements the json.Unmarshaller interface for type ImagePayload.+?\n}/s, "")
198
+ .replace(/\/\/ MarshalJSON implements the json.Marshaller interface for type ImagePayload.+?\n}/s, "")
199
+ .replace(/\/\/ UnmarshalJSON implements the json.Unmarshaller interface for type ImageLocation.+?\n}/s, "")
200
+ .replace(/\/\/ MarshalJSON implements the json.Marshaller interface for type ImageLocation.+?\n}/s, "");
201
+
202
+ # hide the image generation pollers.
203
+ - rename-operation :
204
+ from : beginAzureBatchImageGeneration
205
+ to : azureBatchImageGenerationInternal
206
+ - from :
207
+ - client.go
208
+ - models.go
209
+ - models_serde.go
210
+ - options.go
211
+ - response_types.go
212
+ where : $
213
+ transform : |
214
+ return $.replace(/GetAzureBatchImageGenerationOperationStatusResponse/g, "getAzureBatchImageGenerationOperationStatusResponse")
215
+ .replace(/AzureBatchImageGenerationInternalResponse/g, "azureBatchImageGenerationInternalResponse")
216
+ .replace(/GetAzureBatchImageGenerationOperationStatusOptions/g, "getAzureBatchImageGenerationOperationStatusOptions")
217
+ .replace(/GetAzureBatchImageGenerationOperationStatus/g, "getAzureBatchImageGenerationOperationStatus")
218
+ .replace(/BeginAzureBatchImageGenerationInternal/g, "beginAzureBatchImageGeneration")
219
+ .replace(/BatchImageGenerationOperationResponse/g, "batchImageGenerationOperationResponse");
220
+
221
+ # fix some casing
222
+ - from :
223
+ - client.go
224
+ - models.go
225
+ - models_serde.go
226
+ - options.go
227
+ - response_types.go
228
+ where : $
229
+ transform : return $.replace(/Logprobs/g, "LogProbs")
230
+
231
+ # remove PossibleazureOpenAIOperationStateValues, since we don't expose the poller
232
+ - from : constants.go
233
+ where : $
234
+ transform : return $.replace(/\/\/ PossibleazureOpenAIOperationStateValues returns.+?\n}/s, "");
150
235
` ` `
0 commit comments