Use JSON.stringify()
for pure object in STP._string
This commit is contained in:
parent
9a5efccf0d
commit
469ba4d7bf
4 changed files with 15 additions and 4 deletions
|
@ -608,6 +608,8 @@ interface Task {
|
|||
This tool only supports `application/json` type for request and response body. Any other type like `multipart/form` or `image/*` are **not supported** and will be ignored.
|
||||
|
||||
## Versions
|
||||
#### 2.1.3
|
||||
- Use `JSON.stringify()` for pure object in `STP._string`
|
||||
#### 2.1.2
|
||||
- Fix axios query of array type in IClientAPI (add `{arrayFormat: 'repeat'}`)
|
||||
#### 2.1.1
|
||||
|
|
8
dist/utils/StrictTypeParser.js
vendored
8
dist/utils/StrictTypeParser.js
vendored
|
@ -19,6 +19,7 @@ exports.StrictTypeParser = void 0;
|
|||
var FullDate_1 = require("./FullDate");
|
||||
var StrictTypeParser;
|
||||
(function (StrictTypeParser) {
|
||||
var toStringDefault = {}.toString;
|
||||
var BadValueError = /** @class */ (function (_super) {
|
||||
__extends(BadValueError, _super);
|
||||
function BadValueError(label, message) {
|
||||
|
@ -69,8 +70,11 @@ var StrictTypeParser;
|
|||
function _string(x, label) {
|
||||
if (typeof x === 'string')
|
||||
return x;
|
||||
if (typeof x === 'object')
|
||||
return x.toString();
|
||||
if (typeof x === 'object') {
|
||||
return x.toString === toStringDefault ?
|
||||
JSON.stringify(x) : // pure object => JSON
|
||||
x.toString();
|
||||
}
|
||||
throw new BadTypeError(label, 'string', x);
|
||||
}
|
||||
StrictTypeParser._string = _string;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {FullDate} from './FullDate';
|
||||
|
||||
export module StrictTypeParser {
|
||||
const toStringDefault = {}.toString;
|
||||
export class BadValueError extends Error {
|
||||
constructor(public label: string, message: string) {
|
||||
super(message);
|
||||
|
@ -35,7 +36,11 @@ export module StrictTypeParser {
|
|||
}
|
||||
export function _string(x: any, label: string): string {
|
||||
if (typeof x === 'string') return x;
|
||||
if (typeof x === 'object') return x.toString();
|
||||
if (typeof x === 'object') {
|
||||
return x.toString === toStringDefault ?
|
||||
JSON.stringify(x) : // pure object => JSON
|
||||
x.toString();
|
||||
}
|
||||
throw new BadTypeError(label, 'string', x);
|
||||
}
|
||||
export function _boolean(x: any, label: string): boolean {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sup39/api-ts-gen",
|
||||
"version": "2.1.2",
|
||||
"version": "2.1.3",
|
||||
"description": "OpenAPI code generator for TypeScript",
|
||||
"main": "dist/lib/index.js",
|
||||
"types": "dist/lib/index.d.ts",
|
||||
|
|
Reference in a new issue