mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	api_code_example: Use json instead of ujson; specify separators.
The Markdown extension that lives inside zerver/lib/bugdown/api_code_example.py previously used ujson. ujson's `dumps` function doesn't accept a `separators` argument, which means we have no control over how the JSON is pretty-printed. This resulted in JSON fixtures with no spaces after the colon, which looks unnecessarily convoluted. So now, we use the built-in `json` module to get around this. For further reading, this issue <https://github.com/esnme/ultrajson/issues/82> opened on ujson's repo explains why they are reluctant to support such formatting due to performance considerations.
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
import re
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
import ujson
 | 
			
		||||
import json
 | 
			
		||||
import inspect
 | 
			
		||||
 | 
			
		||||
from markdown.extensions import Extension
 | 
			
		||||
@@ -143,7 +143,8 @@ class APICodeExamplesPreprocessor(Preprocessor):
 | 
			
		||||
        else:
 | 
			
		||||
            fixture_dict = zerver.lib.api_test_helpers.FIXTURES[function]
 | 
			
		||||
 | 
			
		||||
        fixture_json = ujson.dumps(fixture_dict, indent=4, sort_keys=True)
 | 
			
		||||
        fixture_json = json.dumps(fixture_dict, indent=4, sort_keys=True,
 | 
			
		||||
                                  separators=(',', ': '))
 | 
			
		||||
 | 
			
		||||
        fixture.append('```')
 | 
			
		||||
        fixture.extend(fixture_json.splitlines())
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user