fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #431 from hey-api/fix/template-bugs

fix: template bugs

authored by

Lubos and committed by
GitHub
70222a25 0e1776bd

+280 -6
+5
.changeset/heavy-pumas-bow.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: properly escape backticks in template literals
+5
.changeset/slimy-wolves-relax.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: properly escape expressions in template literals
+1 -1
packages/openapi-ts/src/compiler/utils.ts
··· 98 98 (hasNewlines || hasBothQuotes || hasUnescapedBackticks) && 99 99 !isBacktickEscaped 100 100 ) { 101 - value = `\`${value.replace(/`/g, '\\`')}\``; 101 + value = `\`${value.replace(/(?<!\\)`/g, '\\`').replace(/\${/g, '\\${')}\``; 102 102 } 103 103 const text = encodeURIComponent(value); 104 104 if (value.startsWith('`')) {
+37
packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap
··· 1670 1670 }, 1671 1671 }, 1672 1672 } as const; 1673 + 1674 + export const $ModelWithBackticksInDescription = { 1675 + description: 'Some description with `back ticks`', 1676 + type: 'object', 1677 + properties: { 1678 + template: { 1679 + type: 'string', 1680 + description: `The template \`that\` should be used for parsing and importing the contents of the CSV file. 1681 + 1682 + <br/><p>There is one placeholder currently supported:<ul> <li><b>\${x}</b> - refers to the n-th column in the CSV file, e.g. \${1}, \${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 1683 + <pre> 1684 + [ 1685 + { 1686 + "resourceType": "Asset", 1687 + "identifier": { 1688 + "name": "\${1}", 1689 + "domain": { 1690 + "name": "\${2}", 1691 + "community": { 1692 + "name": "Some Community" 1693 + } 1694 + } 1695 + }, 1696 + "attributes" : { 1697 + "00000000-0000-0000-0000-000000003115" : [ { 1698 + "value" : "\${3}" 1699 + } ], 1700 + "00000000-0000-0000-0000-000000000222" : [ { 1701 + "value" : "\${4}" 1702 + } ] 1703 + } 1704 + } 1705 + ] 1706 + </pre>`, 1707 + }, 1708 + }, 1709 + } as const;
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap
··· 783 783 parameterReference, 784 784 }, 785 785 errors: { 786 - 400: '400 server error', 786 + 400: '400 `server` error', 787 787 500: '500 server error', 788 788 }, 789 789 });
+36
packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap
··· 838 838 }; 839 839 840 840 /** 841 + * Some description with `back ticks` 842 + */ 843 + export type ModelWithBackticksInDescription = { 844 + /** 845 + * The template `that` should be used for parsing and importing the contents of the CSV file. 846 + * 847 + * <br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 848 + * <pre> 849 + * [ 850 + * { 851 + * "resourceType": "Asset", 852 + * "identifier": { 853 + * "name": "${1}", 854 + * "domain": { 855 + * "name": "${2}", 856 + * "community": { 857 + * "name": "Some Community" 858 + * } 859 + * } 860 + * }, 861 + * "attributes" : { 862 + * "00000000-0000-0000-0000-000000003115" : [ { 863 + * "value" : "${3}" 864 + * } ], 865 + * "00000000-0000-0000-0000-000000000222" : [ { 866 + * "value" : "${4}" 867 + * } ] 868 + * } 869 + * } 870 + * ] 871 + * </pre> 872 + */ 873 + template?: string; 874 + }; 875 + 876 + /** 841 877 * This is a reusable parameter 842 878 */ 843 879 export type SimpleParameter = string;
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap
··· 874 874 parameterReference, 875 875 }, 876 876 errors: { 877 - 400: '400 server error', 877 + 400: '400 `server` error', 878 878 500: '500 server error', 879 879 }, 880 880 });
+36
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap
··· 838 838 }; 839 839 840 840 /** 841 + * Some description with `back ticks` 842 + */ 843 + export type ModelWithBackticksInDescription = { 844 + /** 845 + * The template `that` should be used for parsing and importing the contents of the CSV file. 846 + * 847 + * <br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 848 + * <pre> 849 + * [ 850 + * { 851 + * "resourceType": "Asset", 852 + * "identifier": { 853 + * "name": "${1}", 854 + * "domain": { 855 + * "name": "${2}", 856 + * "community": { 857 + * "name": "Some Community" 858 + * } 859 + * } 860 + * }, 861 + * "attributes" : { 862 + * "00000000-0000-0000-0000-000000003115" : [ { 863 + * "value" : "${3}" 864 + * } ], 865 + * "00000000-0000-0000-0000-000000000222" : [ { 866 + * "value" : "${4}" 867 + * } ] 868 + * } 869 + * } 870 + * ] 871 + * </pre> 872 + */ 873 + template?: string; 874 + }; 875 + 876 + /** 841 877 * This is a reusable parameter 842 878 */ 843 879 export type SimpleParameter = string;
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap
··· 820 820 parameterReference, 821 821 }, 822 822 errors: { 823 - 400: '400 server error', 823 + 400: '400 `server` error', 824 824 500: '500 server error', 825 825 }, 826 826 });
+36
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap
··· 838 838 }; 839 839 840 840 /** 841 + * Some description with `back ticks` 842 + */ 843 + export type ModelWithBackticksInDescription = { 844 + /** 845 + * The template `that` should be used for parsing and importing the contents of the CSV file. 846 + * 847 + * <br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 848 + * <pre> 849 + * [ 850 + * { 851 + * "resourceType": "Asset", 852 + * "identifier": { 853 + * "name": "${1}", 854 + * "domain": { 855 + * "name": "${2}", 856 + * "community": { 857 + * "name": "Some Community" 858 + * } 859 + * } 860 + * }, 861 + * "attributes" : { 862 + * "00000000-0000-0000-0000-000000003115" : [ { 863 + * "value" : "${3}" 864 + * } ], 865 + * "00000000-0000-0000-0000-000000000222" : [ { 866 + * "value" : "${4}" 867 + * } ] 868 + * } 869 + * } 870 + * ] 871 + * </pre> 872 + */ 873 + template?: string; 874 + }; 875 + 876 + /** 841 877 * This is a reusable parameter 842 878 */ 843 879 export type SimpleParameter = string;
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap
··· 783 783 parameterReference, 784 784 }, 785 785 errors: { 786 - 400: '400 server error', 786 + 400: '400 `server` error', 787 787 500: '500 server error', 788 788 }, 789 789 });
+36
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap
··· 838 838 }; 839 839 840 840 /** 841 + * Some description with `back ticks` 842 + */ 843 + export type ModelWithBackticksInDescription = { 844 + /** 845 + * The template `that` should be used for parsing and importing the contents of the CSV file. 846 + * 847 + * <br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 848 + * <pre> 849 + * [ 850 + * { 851 + * "resourceType": "Asset", 852 + * "identifier": { 853 + * "name": "${1}", 854 + * "domain": { 855 + * "name": "${2}", 856 + * "community": { 857 + * "name": "Some Community" 858 + * } 859 + * } 860 + * }, 861 + * "attributes" : { 862 + * "00000000-0000-0000-0000-000000003115" : [ { 863 + * "value" : "${3}" 864 + * } ], 865 + * "00000000-0000-0000-0000-000000000222" : [ { 866 + * "value" : "${4}" 867 + * } ] 868 + * } 869 + * } 870 + * ] 871 + * </pre> 872 + */ 873 + template?: string; 874 + }; 875 + 876 + /** 841 877 * This is a reusable parameter 842 878 */ 843 879 export type SimpleParameter = string;
+36
packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap
··· 838 838 }; 839 839 840 840 /** 841 + * Some description with `back ticks` 842 + */ 843 + export type ModelWithBackticksInDescription = { 844 + /** 845 + * The template `that` should be used for parsing and importing the contents of the CSV file. 846 + * 847 + * <br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 848 + * <pre> 849 + * [ 850 + * { 851 + * "resourceType": "Asset", 852 + * "identifier": { 853 + * "name": "${1}", 854 + * "domain": { 855 + * "name": "${2}", 856 + * "community": { 857 + * "name": "Some Community" 858 + * } 859 + * } 860 + * }, 861 + * "attributes" : { 862 + * "00000000-0000-0000-0000-000000003115" : [ { 863 + * "value" : "${3}" 864 + * } ], 865 + * "00000000-0000-0000-0000-000000000222" : [ { 866 + * "value" : "${4}" 867 + * } ] 868 + * } 869 + * } 870 + * ] 871 + * </pre> 872 + */ 873 + template?: string; 874 + }; 875 + 876 + /** 841 877 * This is a reusable parameter 842 878 */ 843 879 export type SimpleParameter = string;
+37
packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap
··· 1670 1670 }, 1671 1671 }, 1672 1672 } as const; 1673 + 1674 + export const $ModelWithBackticksInDescription = { 1675 + description: 'Some description with `back ticks`', 1676 + type: 'object', 1677 + properties: { 1678 + template: { 1679 + type: 'string', 1680 + description: `The template \`that\` should be used for parsing and importing the contents of the CSV file. 1681 + 1682 + <br/><p>There is one placeholder currently supported:<ul> <li><b>\${x}</b> - refers to the n-th column in the CSV file, e.g. \${1}, \${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 1683 + <pre> 1684 + [ 1685 + { 1686 + "resourceType": "Asset", 1687 + "identifier": { 1688 + "name": "\${1}", 1689 + "domain": { 1690 + "name": "\${2}", 1691 + "community": { 1692 + "name": "Some Community" 1693 + } 1694 + } 1695 + }, 1696 + "attributes" : { 1697 + "00000000-0000-0000-0000-000000003115" : [ { 1698 + "value" : "\${3}" 1699 + } ], 1700 + "00000000-0000-0000-0000-000000000222" : [ { 1701 + "value" : "\${4}" 1702 + } ] 1703 + } 1704 + } 1705 + ] 1706 + </pre>`, 1707 + }, 1708 + }, 1709 + } as const;
+11 -1
packages/openapi-ts/test/spec/v3.json
··· 1292 1292 } 1293 1293 }, 1294 1294 "400": { 1295 - "description": "400 server error" 1295 + "description": "400 `server` error" 1296 1296 }, 1297 1297 "500": { 1298 1298 "description": "500 server error" ··· 3181 3181 "type": "number", 3182 3182 "description": "Период", 3183 3183 "enum": [1, 3, 6, 12] 3184 + } 3185 + } 3186 + }, 3187 + "ModelWithBackticksInDescription": { 3188 + "description": "Some description with `back ticks`", 3189 + "type": "object", 3190 + "properties": { 3191 + "template": { 3192 + "type": "string", 3193 + "description": "The template `that` should be used for parsing and importing the contents of the CSV file.\n\n<br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p>\n<pre>\n[\n {\n \"resourceType\": \"Asset\",\n \"identifier\": {\n \"name\": \"${1}\",\n \"domain\": {\n \"name\": \"${2}\",\n \"community\": {\n \"name\": \"Some Community\"\n }\n }\n },\n \"attributes\" : {\n \"00000000-0000-0000-0000-000000003115\" : [ {\n \"value\" : \"${3}\" \n } ],\n \"00000000-0000-0000-0000-000000000222\" : [ {\n \"value\" : \"${4}\"\n } ]\n }\n }\n]\n</pre>" 3184 3194 } 3185 3195 } 3186 3196 }