(
enumName: string,
values: string[],
ctx: PyCodegenCtx,
description?: string,
enumValueDescriptions?: EnumValueDescriptions,
deprecated?: boolean,
experimental?: boolean
)
| 1838 | } |
| 1839 | |
| 1840 | function getOrCreatePyEnum( |
| 1841 | enumName: string, |
| 1842 | values: string[], |
| 1843 | ctx: PyCodegenCtx, |
| 1844 | description?: string, |
| 1845 | enumValueDescriptions?: EnumValueDescriptions, |
| 1846 | deprecated?: boolean, |
| 1847 | experimental?: boolean |
| 1848 | ): string { |
| 1849 | const existing = ctx.enumsByName.get(enumName); |
| 1850 | if (existing) { |
| 1851 | return existing; |
| 1852 | } |
| 1853 | |
| 1854 | const lines: string[] = []; |
| 1855 | if (experimental) { |
| 1856 | pushPyExperimentalComment(lines, "enum"); |
| 1857 | } |
| 1858 | if (deprecated) { |
| 1859 | lines.push(`# Deprecated: this enum is deprecated and will be removed in a future version.`); |
| 1860 | } |
| 1861 | if (description) { |
| 1862 | lines.push(`class ${enumName}(Enum):`); |
| 1863 | lines.push(` ${pyDocstringLiteral(description)}`); |
| 1864 | } else { |
| 1865 | lines.push(`class ${enumName}(Enum):`); |
| 1866 | } |
| 1867 | for (const value of values) { |
| 1868 | const valueDescription = enumValueDescriptions?.[value]; |
| 1869 | if (valueDescription) { |
| 1870 | for (const line of valueDescription.split(/\r?\n/)) { |
| 1871 | lines.push(` # ${line.trimEnd()}`); |
| 1872 | } |
| 1873 | } |
| 1874 | lines.push(` ${toEnumMemberName(value)} = ${JSON.stringify(value)}`); |
| 1875 | } |
| 1876 | ctx.enumsByName.set(enumName, enumName); |
| 1877 | ctx.enums.push(lines.join("\n")); |
| 1878 | return enumName; |
| 1879 | } |
| 1880 | |
| 1881 | function resolvePyPropertyType( |
| 1882 | propSchema: JSONSchema7, |
no test coverage detected
searching dependent graphs…