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

Update formatting to make request/responses easier to read #66

Merged
merged 2 commits into from Sep 18, 2019

Conversation

colinhumber
Copy link
Contributor

No description provided.

@pmusolino pmusolino added the enhancement New feature or request label Sep 18, 2019
Copy link
Owner

@pmusolino pmusolino left a comment

Choose a reason for hiding this comment

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

Hi @colinhumber! Thanks for this PR. Everything sounds good, but I don't understand why you replaced the method inside the RequestModelBeautifier.

  • Paolo

let jsonData = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let formattedJSON = String(data: jsonData, encoding: .utf8) else { return nil }

return formattedJSON.replacingOccurrences(of: "\\", with: "")
Copy link
Owner

Choose a reason for hiding this comment

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

This is a little bit weird... if a string contains \\ occurrences, you replace it. I'm not sure it's the best way to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good call. I did this a little haphazardly 😬. Just pushed an update that correctly replaces escaped forward slashes (\\/) with a normal slash (/).

- use Courier font when displaying JSON content
- use prettyPrinted option with JSONSerializer
- remove escaped slashes to allow URLs to render correctly
- add link detection to URLs in JSON payloads
@colinhumber
Copy link
Contributor Author

The prettyPrintedJSON method that was there before was generating some incorrect JSON. For example, in the /photos response there were some commas missing.

[
{
  "thumbnailUrl" : "https:\/\/via.placeholder.com\/150\/92c952",
  "url" : "https:\/\/via.placeholder.com\/600\/92c952",
  "title" : "accusamus beatae ad facilis cum similique qui sunt",
  "id" : 1,
  "albumId" : 1
}{ <-- here
  "albumId" : 1,
  "id" : 2,
  "title" : "reprehenderit est deserunt velit ipsam",
  "thumbnailUrl" : "https:\/\/via.placeholder.com\/150\/771796",
  "url" : "https:\/\/via.placeholder.com\/600\/771796"
}{ <-- here
  "id" : 3,
  "url" : "https:\/\/via.placeholder.com\/600\/24f355",
  "albumId" : 1,
  "thumbnailUrl" : "https:\/\/via.placeholder.com\/150\/24f355",
  "title" : "officia porro iure quia iusto qui ipsa ut modi"
}....

I switched it to let the system do the pretty printing as the Dictionary.prettyPrintedJSON was doing.

@colinhumber
Copy link
Contributor Author

@pmusolino Btw thanks for all the work on this library!

@pmusolino
Copy link
Owner

Thank you very much @colinhumber for clarifying this particular!

@pmusolino pmusolino merged commit 9d174c1 into pmusolino:master Sep 18, 2019
@colinhumber colinhumber deleted the formatting branch September 18, 2019 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants