Skip to content

Commit

Permalink
Merge pull request #315 from hey-api/fix/escape-description-zendesk
Browse files Browse the repository at this point in the history
fix(parser): escape backticks in strings starting with backtick
  • Loading branch information
mrlubos authored Apr 9, 2024
2 parents 58a1dcb + c8e0718 commit 80f192e
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-beans-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix: escape backticks in strings starting with backtick
10 changes: 5 additions & 5 deletions packages/openapi-ts/src/compiler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ export const ots = {
if (unescape) {
value = unescapeName(value);
}
if (
(value.includes('\n') || (value.includes("'") && value.includes('"'))) &&
!value.startsWith('`') &&
!value.endsWith('`')
) {
const hasBothQuotes = value.includes("'") && value.includes('"');
const hasNewlines = value.includes('\n');
const hasUnescapedBackticks = value.startsWith('`');
const isBacktickEscaped = value.startsWith('\\`') && value.endsWith('\\`');
if ((hasNewlines || hasBothQuotes || hasUnescapedBackticks) && !isBacktickEscaped) {
value = `\`${value.replace(/`/g, '\\`')}\``;
}
const text = encodeURIComponent(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ export type ModelWithString = {
prop?: string;
};

/**
* `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)
*/
export type ModelFromZendesk = string;

/**
* This is a model with one string property
*/
Expand Down Expand Up @@ -835,7 +840,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const $ModelWithString = {
},
} as const;

export const $ModelFromZendesk = {
description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`,
type: 'string',
} as const;

export const $ModelWithNullableString = {
description: 'This is a model with one string property',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DefaultService {

export class SimpleService {
/**
* @returns ModelWithString Success
* @returns ModelFromZendesk Success
* @throws ApiError
*/
public static apiVVersionOdataControllerCount(): CancelablePromise<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export type ModelWithString = {
prop?: string;
};

/**
* `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)
*/
export type ModelFromZendesk = string;

/**
* This is a model with one string property
*/
Expand Down Expand Up @@ -732,7 +737,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const $ModelWithString = {
},
} as const;

export const $ModelFromZendesk = {
description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`,
type: 'string',
} as const;

export const $ModelWithNullableString = {
description: 'This is a model with one string property',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SimpleService {
constructor(public readonly http: HttpClient) {}

/**
* @returns ModelWithString Success
* @returns ModelFromZendesk Success
* @throws ApiError
*/
public apiVVersionOdataControllerCount(): Observable<SimpleData['responses']['ApiVversionOdataControllerCount']> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ export type ModelWithString = {
prop?: string;
};

/**
* `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)
*/
export type ModelFromZendesk = string;

/**
* This is a model with one string property
*/
Expand Down Expand Up @@ -835,7 +840,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SimpleService {
constructor(public readonly httpRequest: BaseHttpRequest) {}

/**
* @returns ModelWithString Success
* @returns ModelFromZendesk Success
* @throws ApiError
*/
public apiVVersionOdataControllerCount(): CancelablePromise<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const $ModelWithString = {
},
} as const;

export const $ModelFromZendesk = {
description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`,
type: 'string',
} as const;

export const $ModelWithNullableString = {
description: 'This is a model with one string property',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ export type ModelWithString = {
prop?: string;
};

/**
* `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)
*/
export type ModelFromZendesk = string;

/**
* This is a model with one string property
*/
Expand Down Expand Up @@ -777,7 +782,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const $ModelWithString = {
},
} as const;

export const $ModelFromZendesk = {
description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`,
type: 'string',
} as const;

export const $ModelWithNullableString = {
description: 'This is a model with one string property',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DefaultService {

export class SimpleService {
/**
* @returns ModelWithString Success
* @returns ModelFromZendesk Success
* @throws ApiError
*/
public static apiVVersionOdataControllerCount(): CancelablePromise<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export type ModelWithString = {
prop?: string;
};

/**
* `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)
*/
export type ModelFromZendesk = string;

/**
* This is a model with one string property
*/
Expand Down Expand Up @@ -734,7 +739,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const $ModelWithString = {
},
} as const;

export const $ModelFromZendesk = {
description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`,
type: 'string',
} as const;

export const $ModelWithNullableString = {
description: 'This is a model with one string property',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DefaultService {

export class SimpleService {
/**
* @returns ModelWithString Success
* @returns ModelFromZendesk Success
* @throws ApiError
*/
public static apiVVersionOdataControllerCount(): CancelablePromise<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export type ModelWithString = {
prop?: string;
};

/**
* `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)
*/
export type ModelFromZendesk = string;

/**
* This is a model with one string property
*/
Expand Down Expand Up @@ -732,7 +737,7 @@ export type DefaultData = {

export type SimpleData = {
responses: {
ApiVversionOdataControllerCount: ModelWithString;
ApiVversionOdataControllerCount: ModelFromZendesk;
GetCallWithoutParametersAndResponse: void;
PutCallWithoutParametersAndResponse: void;
PostCallWithoutParametersAndResponse: void;
Expand Down
6 changes: 5 additions & 1 deletion packages/openapi-ts/test/spec/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"content": {
"application/json; type=collection": {
"schema": {
"$ref": "#/components/schemas/ModelWithString"
"$ref": "#/components/schemas/ModelFromZendesk"
}
}
}
Expand Down Expand Up @@ -2048,6 +2048,10 @@
}
}
},
"ModelFromZendesk": {
"description": "`Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)",
"type": "string"
},
"ModelWithNullableString": {
"description": "This is a model with one string property",
"type": "object",
Expand Down

0 comments on commit 80f192e

Please sign in to comment.