Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch JSON formatting from 'jsonc-parser' to 'js-beautify' #233

Merged
merged 5 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 76 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
"highlight.js": "^9.6.0",
"httpsnippet": "^1.16.5",
"iconv-lite": "^0.4.15",
"js-beautify": "^1.7.5",
"jsonc-parser": "^1.0.3",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this package in dependencies

"jsonpath": "^1.0.0",
"mime-types": "^2.1.14",
Expand Down
6 changes: 2 additions & 4 deletions src/utils/responseFormatUtility.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict';

import { applyEdits, format as JSONFormat } from "jsonc-parser/lib/umd/main";
import { EOL } from "os";
import { window } from 'vscode';
import { MimeUtility } from './mimeUtility';
const pd = require('pretty-data').pd;
const beautify = require('js-beautify').js_beautify;

export class ResponseFormatUtility {
public static formatBody(body: string, contentType: string, suppressValidation: boolean): string {
if (contentType) {
if (MimeUtility.isJSON(contentType)) {
if (ResponseFormatUtility.IsJsonString(body)) {
const edits = JSONFormat(body, undefined, { tabSize: 2, insertSpaces: true, eol: EOL });
body = applyEdits(body, edits);
body = beautify(body, { indent_size: 4 });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you increase the indent_size from 2 to 4 here?

} else if (!suppressValidation) {
window.showWarningMessage('The content type of response is application/json, while response body is not a valid json string');
}
Expand Down