зеркало из https://github.com/Azure/autorest.git
Modelerfour set correct known media type when `application/json` with `type: string` (#4506)
This commit is contained in:
Родитель
fdbf8d4967
Коммит
34a9352054
|
@ -1,6 +1,18 @@
|
|||
{
|
||||
"name": "@autorest/modelerfour",
|
||||
"entries": [
|
||||
{
|
||||
"version": "4.23.2",
|
||||
"tag": "@autorest/modelerfour_v4.23.2",
|
||||
"date": "Thu, 07 Apr 2022 20:47:30 GMT",
|
||||
"comments": {
|
||||
"patch": [
|
||||
{
|
||||
"comment": "Modelerfour set correct known media type when `application/json` with `type: string`"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"version": "4.23.1",
|
||||
"tag": "@autorest/modelerfour_v4.23.1",
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
# Change Log - @autorest/modelerfour
|
||||
|
||||
This log was last generated on Mon, 21 Mar 2022 15:38:03 GMT and should not be manually modified.
|
||||
This log was last generated on Thu, 07 Apr 2022 20:47:30 GMT and should not be manually modified.
|
||||
|
||||
## 4.23.2
|
||||
Thu, 07 Apr 2022 20:47:30 GMT
|
||||
|
||||
### Patches
|
||||
|
||||
- Modelerfour set correct known media type when `application/json` with `type: string`
|
||||
|
||||
## 4.23.1
|
||||
Mon, 21 Mar 2022 15:38:03 GMT
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@autorest/modelerfour",
|
||||
"version": "4.23.1",
|
||||
"version": "4.23.2",
|
||||
"description": "AutoRest Modeler Version Four (component)",
|
||||
"directories": {
|
||||
"doc": "docs"
|
||||
|
|
|
@ -118,7 +118,10 @@ export class BodyProcessor {
|
|||
return KnownMediaType.Binary;
|
||||
}
|
||||
|
||||
if (isSchemaString(body)) {
|
||||
if (
|
||||
isSchemaString(body) &&
|
||||
(mediaTypes.length !== 1 || (mediaTypes[0] !== "application/json" && mediaTypes[0] !== "application/xml"))
|
||||
) {
|
||||
return KnownMediaType.Text;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import assert from "assert";
|
||||
import { inspect } from "util";
|
||||
import {
|
||||
BinarySchema,
|
||||
ByteArraySchema,
|
||||
|
@ -20,6 +21,7 @@ import {
|
|||
SealedChoiceSchema,
|
||||
StringSchema,
|
||||
} from "@autorest/codemodel";
|
||||
import { KnownMediaType } from "@azure-tools/codegen";
|
||||
import { HttpOperation, JsonType, ParameterLocation, RequestBody } from "@azure-tools/openapi";
|
||||
import * as oai3 from "@azure-tools/openapi";
|
||||
import { addOperation, createTestSpec, findByName } from "../utils";
|
||||
|
@ -107,6 +109,28 @@ describe("Modelerfour.Request.Body", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Body schema is type: string with application/json content type", () => {
|
||||
let operation: Operation;
|
||||
|
||||
beforeEach(async () => {
|
||||
operation = await runModelerWithBody({
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: { type: JsonType.String },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("only create one request", async () => {
|
||||
expect(operation.requests).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("known media type is json", async () => {
|
||||
expect(operation.requests![0].protocol.http!.knownMediaType).toEqual(KnownMediaType.Json);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Body is an object with application/json content-type", () => {
|
||||
let operation: Operation;
|
||||
|
||||
|
@ -336,7 +360,7 @@ describe("Modelerfour.Request.Body", () => {
|
|||
[{ enum: ["one", "two"] }, ChoiceSchema],
|
||||
] as const;
|
||||
scenarios.forEach(([extra, type]) => {
|
||||
describe(`format:${extra} with application/json`, () => {
|
||||
describe(`format:${inspect(extra)} with application/json`, () => {
|
||||
let operation: Operation;
|
||||
|
||||
beforeEach(async () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче