Skip to content

Commit ef9e311

Browse files
Validate and update sample output for media type hint change (#2369)
This is the Azure companion of microsoft/typespec#6357 This PR updates the recorded sample output to account for changes to the default content types of scalars.
1 parent b4586c5 commit ef9e311

File tree

21 files changed

+140
-24
lines changed

21 files changed

+140
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@azure-tools/typespec-client-generator-core"
5+
---
6+
7+
Update some tests and logic around constant/string content-type parameters.

core

Submodule core updated 107 files

packages/samples/test/output/core/grpc-library-example/@azure-tools/typespec-autorest/openapi.json

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
"LibraryService"
140140
],
141141
"description": "Merges two shelves by adding all books from the shelf named\n`other_shelf_name` to shelf `name`, and deletes\n`other_shelf_name`. Returns the updated shelf.\nThe book ids of the moved books may not be the same as the original books.\nReturns NOT_FOUND if either shelf does not exist.\nThis call is a no-op if the specified shelves are the same.",
142+
"consumes": [
143+
"text/plain"
144+
],
142145
"parameters": [
143146
{
144147
"$ref": "#/parameters/MergeShelvesRequest.name"

packages/samples/test/output/core/init/@azure-tools/typespec-autorest/openapi.json

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
"Widgets"
181181
],
182182
"description": "Analyze a widget",
183+
"produces": [
184+
"text/plain",
185+
"application/json"
186+
],
183187
"parameters": [
184188
{
185189
"name": "id",

packages/samples/test/output/core/nested/@azure-tools/typespec-autorest/openapi.json

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"/": {
2424
"post": {
2525
"operationId": "SubC_AnotherOp",
26+
"produces": [
27+
"text/plain"
28+
],
2629
"parameters": [
2730
{
2831
"name": "body",
@@ -58,6 +61,9 @@
5861
"/sub/a/subsub": {
5962
"post": {
6063
"operationId": "SubSubA_DoSomething",
64+
"produces": [
65+
"text/plain"
66+
],
6167
"parameters": [
6268
{
6369
"name": "thing",
@@ -81,6 +87,9 @@
8187
"/sub/b": {
8288
"post": {
8389
"operationId": "SubB_DoSomething",
90+
"produces": [
91+
"text/plain"
92+
],
8493
"parameters": [
8594
{
8695
"name": "thing",

packages/samples/test/output/core/optional/@azure-tools/typespec-autorest/openapi.json

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"/test": {
2424
"get": {
2525
"operationId": "OptionalMethods_Read",
26+
"consumes": [
27+
"text/plain"
28+
],
2629
"parameters": [
2730
{
2831
"name": "queryString",

packages/samples/test/output/core/simple/@azure-tools/typespec-autorest/openapi.json

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"/alpha/{id}": {
2424
"get": {
2525
"operationId": "DoAlpha",
26+
"produces": [
27+
"text/plain"
28+
],
2629
"parameters": [
2730
{
2831
"name": "id",
@@ -44,6 +47,9 @@
4447
"/beta/{id}": {
4548
"get": {
4649
"operationId": "DoBeta",
50+
"produces": [
51+
"text/plain"
52+
],
4753
"parameters": [
4854
{
4955
"name": "id",

packages/samples/test/output/core/testserver/body-boolean/@azure-tools/typespec-autorest/openapi.json

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
"put": {
4747
"operationId": "bool_putFalse",
4848
"description": "Set Boolean value false",
49+
"produces": [
50+
"text/plain",
51+
"application/json"
52+
],
4953
"parameters": [
5054
{
5155
"name": "value",
@@ -79,6 +83,10 @@
7983
"get": {
8084
"operationId": "bool_getInvalid",
8185
"description": "Get invalid Boolean value",
86+
"produces": [
87+
"text/plain",
88+
"application/json"
89+
],
8290
"parameters": [],
8391
"responses": {
8492
"200": {
@@ -100,6 +108,10 @@
100108
"get": {
101109
"operationId": "bool_getNull",
102110
"description": "Get null Boolean value",
111+
"produces": [
112+
"text/plain",
113+
"application/json"
114+
],
103115
"parameters": [],
104116
"responses": {
105117
"200": {

packages/samples/test/output/core/testserver/body-string/@azure-tools/typespec-autorest/openapi.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
"String Operations"
3232
],
3333
"description": "Get value that is base64 encoded",
34+
"produces": [
35+
"application/octet-stream",
36+
"application/json"
37+
],
3438
"parameters": [],
3539
"responses": {
3640
"200": {
3741
"description": "The request has succeeded.",
3842
"schema": {
39-
"type": "string",
40-
"format": "byte"
43+
"type": "file"
4144
}
4245
},
4346
"default": {
@@ -54,14 +57,17 @@
5457
"String Operations"
5558
],
5659
"description": "Put value that is base64 encoded",
60+
"consumes": [
61+
"application/octet-stream"
62+
],
5763
"parameters": [
5864
{
5965
"name": "value",
6066
"in": "body",
6167
"required": true,
6268
"schema": {
6369
"type": "string",
64-
"format": "byte"
70+
"format": "binary"
6571
}
6672
}
6773
],

packages/samples/test/output/core/testserver/body-time/@azure-tools/typespec-autorest/openapi.json

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"get": {
2525
"operationId": "Time_Get",
2626
"description": "Get time value \"11:34:56\"",
27+
"produces": [
28+
"text/plain",
29+
"application/json"
30+
],
2731
"parameters": [],
2832
"responses": {
2933
"200": {
@@ -44,6 +48,9 @@
4448
"put": {
4549
"operationId": "Time_Put",
4650
"description": "Put time value \"08:07:56\"",
51+
"consumes": [
52+
"text/plain"
53+
],
4754
"parameters": [
4855
{
4956
"name": "value",

packages/samples/test/output/core/testserver/media-types/@azure-tools/typespec-autorest/openapi.json

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"post": {
2525
"operationId": "AnalyzeBody",
2626
"description": "Analyze body, that could be different media types.",
27+
"produces": [
28+
"text/plain"
29+
],
2730
"consumes": [
2831
"application/pdf",
2932
"application/json",
@@ -50,6 +53,9 @@
5053
"post": {
5154
"operationId": "contentTypeWithEncoding",
5255
"description": "Pass in contentType 'text/plain; encoding=UTF-8' to pass test. Value for input does not matter",
56+
"produces": [
57+
"text/plain"
58+
],
5359
"consumes": [
5460
"text/plain"
5561
],

packages/samples/test/output/core/testserver/multiple-inheritance/@azure-tools/typespec-autorest/openapi.json

+35
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"get": {
2525
"operationId": "MultipleInheritance_GetCat",
2626
"description": "Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true",
27+
"produces": [
28+
"application/json",
29+
"text/plain"
30+
],
2731
"parameters": [],
2832
"responses": {
2933
"200": {
@@ -43,6 +47,9 @@
4347
"put": {
4448
"operationId": "MultipleInheritance_PutCat",
4549
"description": "Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true",
50+
"produces": [
51+
"text/plain"
52+
],
4653
"parameters": [
4754
{
4855
"name": "cat",
@@ -73,6 +80,10 @@
7380
"get": {
7481
"operationId": "MultipleInheritance_GetFeline",
7582
"description": "Get a feline where meows and hisses are true",
83+
"produces": [
84+
"application/json",
85+
"text/plain"
86+
],
7687
"parameters": [],
7788
"responses": {
7889
"200": {
@@ -92,6 +103,9 @@
92103
"put": {
93104
"operationId": "MultipleInheritance_PutFeline",
94105
"description": "Put a feline who hisses and doesn't meow",
106+
"produces": [
107+
"text/plain"
108+
],
95109
"parameters": [
96110
{
97111
"name": "feline",
@@ -122,6 +136,10 @@
122136
"get": {
123137
"operationId": "MultipleInheritance_GetHorse",
124138
"description": "Get a horse with name 'Fred' and isAShowHorse true",
139+
"produces": [
140+
"application/json",
141+
"text/plain"
142+
],
125143
"parameters": [],
126144
"responses": {
127145
"200": {
@@ -141,6 +159,9 @@
141159
"put": {
142160
"operationId": "MultipleInheritance_PutHorse",
143161
"description": "Put a horse with name 'General' and isAShowHorse false",
162+
"produces": [
163+
"text/plain"
164+
],
144165
"parameters": [
145166
{
146167
"name": "horse",
@@ -171,6 +192,10 @@
171192
"get": {
172193
"operationId": "MultipleInheritance_GetKitten",
173194
"description": "Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false",
195+
"produces": [
196+
"application/json",
197+
"text/plain"
198+
],
174199
"parameters": [],
175200
"responses": {
176201
"200": {
@@ -190,6 +215,9 @@
190215
"put": {
191216
"operationId": "MultipleInheritance_PutKitten",
192217
"description": "Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true",
218+
"produces": [
219+
"text/plain"
220+
],
193221
"parameters": [
194222
{
195223
"name": "kitten",
@@ -220,6 +248,10 @@
220248
"get": {
221249
"operationId": "MultipleInheritance_GetPet",
222250
"description": "Get a pet with name 'Peanut'",
251+
"produces": [
252+
"application/json",
253+
"text/plain"
254+
],
223255
"parameters": [],
224256
"responses": {
225257
"200": {
@@ -239,6 +271,9 @@
239271
"put": {
240272
"operationId": "MultipleInheritance_PutPet",
241273
"description": "Put a pet with name 'Butter'",
274+
"produces": [
275+
"text/plain"
276+
],
242277
"parameters": [
243278
{
244279
"name": "horse",

packages/typespec-autorest-canonical/test/return-types.test.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,8 @@ describe("binary responses", () => {
545545
@get op read(): bytes;
546546
`);
547547
const operation = res.paths["/"].get;
548-
deepStrictEqual(operation.produces, undefined);
549-
strictEqual(operation.responses["200"].schema.type, "string");
550-
strictEqual(operation.responses["200"].schema.format, "byte");
548+
deepStrictEqual(operation.produces, ["application/octet-stream"]);
549+
strictEqual(operation.responses["200"].schema.type, "file");
551550
});
552551

553552
it("@body body: bytes responses should produce application/json with byte schema", async () => {
@@ -556,9 +555,8 @@ describe("binary responses", () => {
556555
`);
557556

558557
const operation = res.paths["/"].get;
559-
deepStrictEqual(operation.produces, undefined);
560-
strictEqual(operation.responses["200"].schema.type, "string");
561-
strictEqual(operation.responses["200"].schema.format, "byte");
558+
deepStrictEqual(operation.produces, ["application/octet-stream"]);
559+
strictEqual(operation.responses["200"].schema.type, "file");
562560
});
563561

564562
it("@header contentType should override content type and set type to file", async () => {

packages/typespec-autorest/test/metadata.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ describe("typespec-autorest: metadata", () => {
341341
"/single/{p}": {
342342
get: {
343343
operationId: "Single",
344+
produces: ["text/plain"],
344345
parameters: [
345346
{ $ref: "#/parameters/Parameters.q" },
346347
{ $ref: "#/parameters/Parameters.p" },
@@ -357,6 +358,7 @@ describe("typespec-autorest: metadata", () => {
357358
"/batch": {
358359
get: {
359360
operationId: "Batch",
361+
produces: ["text/plain"],
360362
responses: {
361363
"200": {
362364
description: "The request has succeeded.",

packages/typespec-autorest/test/openapi-output.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,11 @@ describe("typespec-autorest: request", () => {
587587
@post op read(@body body: bytes): {};
588588
`);
589589
const operation = res.paths["/"].post;
590-
deepStrictEqual(operation.consumes, undefined);
590+
deepStrictEqual(operation.consumes, ["application/octet-stream"]);
591591
const requestBody = operation.parameters[0];
592592
ok(requestBody);
593593
strictEqual(requestBody.schema.type, "string");
594-
strictEqual(requestBody.schema.format, "byte");
594+
strictEqual(requestBody.schema.format, "binary");
595595
});
596596

597597
it("bytes request should respect @header contentType", async () => {

packages/typespec-autorest/test/parameters.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ describe("content type parameter", () => {
478478
): void;
479479
`,
480480
);
481-
strictEqual(res.paths["/"].post.consumes, undefined);
481+
deepStrictEqual(res.paths["/"].post.consumes, ["text/plain"]);
482482
});
483483
});
484484

packages/typespec-autorest/test/return-types.test.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,8 @@ describe("typespec-autorest: return types", () => {
543543
@get op read(): bytes;
544544
`);
545545
const operation = res.paths["/"].get;
546-
deepStrictEqual(operation.produces, undefined);
547-
strictEqual(operation.responses["200"].schema.type, "string");
548-
strictEqual(operation.responses["200"].schema.format, "byte");
546+
deepStrictEqual(operation.produces, ["application/octet-stream"]);
547+
strictEqual(operation.responses["200"].schema.type, "file");
549548
});
550549

551550
it("@body body: bytes responses should produce application/json with byte schema", async () => {
@@ -554,9 +553,8 @@ describe("typespec-autorest: return types", () => {
554553
`);
555554

556555
const operation = res.paths["/"].get;
557-
deepStrictEqual(operation.produces, undefined);
558-
strictEqual(operation.responses["200"].schema.type, "string");
559-
strictEqual(operation.responses["200"].schema.format, "byte");
556+
deepStrictEqual(operation.produces, ["application/octet-stream"]);
557+
strictEqual(operation.responses["200"].schema.type, "file");
560558
});
561559

562560
it("@header contentType should override content type and set type to file", async () => {

0 commit comments

Comments
 (0)