@@ -43,6 +43,7 @@ interface ConfigInterface {
4343 apiUsername : string | null ;
4444 userApiKey ?: string | null ;
4545 baseUrl ?: string | null ;
46+ camelCase ?: boolean ;
4647}
4748
4849export interface DiscourseInterface {
@@ -73,27 +74,33 @@ export default class Discourse implements DiscourseInterface {
7374 _API_KEY : string | null ;
7475 _API_USERNAME : string | null ;
7576 isUsingAdminAPI : string ;
77+ camelCase : boolean ;
7678
7779 constructor (
7880 userApiKey : string ,
7981 baseUrl : string ,
8082 apiKey : string | null = null ,
83+ camelCase : boolean = false ,
8184 ) {
8285 this . _BASE_URL = baseUrl ;
8386 this . _USER_API_KEY = userApiKey ;
8487
8588 // Admin User API
8689 this . _API_KEY = apiKey ;
8790
91+ // Return camelCase data from DiscourseJS
92+ this . camelCase = camelCase ;
93+
8894 for ( let resource in resources ) {
8995 this [ resource . toLowerCase ( ) ] = new resources [ resource ] ( this ) ;
9096 }
9197 }
9298
9399 config = (
94- { userApiKey, baseUrl, apiUsername, apiKey } : ConfigInterface = {
100+ { userApiKey, baseUrl, apiUsername, apiKey, camelCase } : ConfigInterface = {
95101 apiUsername : null ,
96102 apiKey : null ,
103+ camelCase : false ,
97104 } ,
98105 ) => {
99106 this . _USER_API_KEY = userApiKey ;
@@ -103,6 +110,9 @@ export default class Discourse implements DiscourseInterface {
103110 this . _API_KEY = apiKey ;
104111 this . _API_USERNAME = apiUsername ;
105112
113+ // Return camelCase data from DiscourseJS
114+ this . camelCase = camelCase ;
115+
106116 // If we are using the Admin API then we'll need to include
107117 // the API key and username in each request either as part
108118 // of our URL params or as part of our POST body
@@ -184,7 +194,9 @@ export default class Discourse implements DiscourseInterface {
184194 const contentType = response . headers . get ( 'content-type' ) ;
185195 if ( response . ok ) {
186196 if ( contentType && contentType . indexOf ( 'application/json' ) !== - 1 ) {
187- return camelizeKeys ( response . json ( ) ) ;
197+ return this . camelCase
198+ ? camelizeKeys ( response . json ( ) )
199+ : response . json ( ) ;
188200 } else {
189201 /**
190202 * If our response is OK but is not json
0 commit comments