Skip to content

Commit c1e0361

Browse files
authored
[typescript-*]: Improve literal regexp for JSON MIME-type (#23319)
- Use a literal regex as suggested by SonarQube analysis typescript:S6325 - Remove the explicit test against json-patch that is already included in the regexp
1 parent ff66e1b commit c1e0361

55 files changed

Lines changed: 91 additions & 91 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
181181
* @return True if the given MIME is JSON, false otherwise.
182182
*/
183183
public isJsonMime(mime: string): boolean {
184-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
185-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
184+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
185+
return mime !== null && jsonMime.test(mime);
186186
}
187187

188188
public lookupCredential(key: string): string | undefined {

modules/openapi-generator/src/main/resources/typescript-axios/configuration.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class Configuration {
108108
* @return True if the given MIME is JSON, false otherwise.
109109
*/
110110
public isJsonMime(mime: string): boolean {
111-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
112-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
111+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
112+
return mime !== null && jsonMime.test(mime);
113113
}
114114
}

modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const DefaultConfig = new Configuration();
8181
*/
8282
export class BaseAPI {
8383
84-
private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i');
84+
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
8585
private middleware: Middleware[];
8686
8787
constructor(protected configuration = DefaultConfig) {

modules/openapi-generator/src/main/resources/typescript-nestjs/configuration.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export class Configuration {
8484
* @return True if the given MIME is JSON, false otherwise.
8585
*/
8686
public isJsonMime(mime: string): boolean {
87-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
88-
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
87+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
88+
return mime !== null && jsonMime.test(mime);
8989
}
9090
}
9191

samples/client/echo_api/typescript-axios/build/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class Configuration {
116116
* @return True if the given MIME is JSON, false otherwise.
117117
*/
118118
public isJsonMime(mime: string): boolean {
119-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
120-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
119+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
120+
return mime !== null && jsonMime.test(mime);
121121
}
122122
}

samples/client/others/typescript-angular-v20/builds/query-param-deep-object/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
142142
* @return True if the given MIME is JSON, false otherwise.
143143
*/
144144
public isJsonMime(mime: string): boolean {
145-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
146-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
145+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
146+
return mime !== null && jsonMime.test(mime);
147147
}
148148

149149
public lookupCredential(key: string): string | undefined {

samples/client/others/typescript-angular-v20/builds/query-param-form/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
142142
* @return True if the given MIME is JSON, false otherwise.
143143
*/
144144
public isJsonMime(mime: string): boolean {
145-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
146-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
145+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
146+
return mime !== null && jsonMime.test(mime);
147147
}
148148

149149
public lookupCredential(key: string): string | undefined {

samples/client/others/typescript-angular-v20/builds/query-param-json/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
142142
* @return True if the given MIME is JSON, false otherwise.
143143
*/
144144
public isJsonMime(mime: string): boolean {
145-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
146-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
145+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
146+
return mime !== null && jsonMime.test(mime);
147147
}
148148

149149
public lookupCredential(key: string): string | undefined {

samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
142142
* @return True if the given MIME is JSON, false otherwise.
143143
*/
144144
public isJsonMime(mime: string): boolean {
145-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
146-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
145+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
146+
return mime !== null && jsonMime.test(mime);
147147
}
148148

149149
public lookupCredential(key: string): string | undefined {

samples/client/others/typescript-angular/builds/composed-schemas/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
142142
* @return True if the given MIME is JSON, false otherwise.
143143
*/
144144
public isJsonMime(mime: string): boolean {
145-
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
146-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
145+
const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
146+
return mime !== null && jsonMime.test(mime);
147147
}
148148

149149
public lookupCredential(key: string): string | undefined {

0 commit comments

Comments
 (0)