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.

feat: add class method node

Lubos 4f42c501 a92a301f

+38 -20
+10 -10
packages/openapi-python-tests/sdks/__snapshots__/opencode/default/sdk_gen.py
··· 35 35 36 36 37 37 class Project(Client): 38 - def list_(self): 38 + def list(self): 39 39 """ 40 40 List all projects 41 41 ··· 64 64 65 65 66 66 class Pty(Client): 67 - def list_(self): 67 + def list(self): 68 68 """ 69 69 List PTY sessions 70 70 ··· 158 158 159 159 return self.client.get("/experimental/tool/ids") 160 160 161 - def list_(self): 161 + def list(self): 162 162 """ 163 163 List tools 164 164 ··· 202 202 203 203 204 204 class Session(Client): 205 - def list_(self): 205 + def list(self): 206 206 """ 207 207 List sessions 208 208 ··· 443 443 444 444 return self.client.post("/permission/{requestID}/reply") 445 445 446 - def list_(self): 446 + def list(self): 447 447 """ 448 448 List pending permissions 449 449 ··· 454 454 455 455 456 456 class Command(Client): 457 - def list_(self): 457 + def list(self): 458 458 """ 459 459 List commands 460 460 ··· 485 485 486 486 487 487 class Provider(Client): 488 - def list_(self): 488 + def list(self): 489 489 """ 490 490 List providers 491 491 ··· 538 538 539 539 540 540 class File(Client): 541 - def list_(self): 541 + def list(self): 542 542 """ 543 543 List files 544 544 ··· 681 681 682 682 683 683 class Control(Client): 684 - def next_(self): 684 + def next(self): 685 685 """ 686 686 Get next TUI request 687 687 ··· 797 797 798 798 799 799 class Auth_2(Client): 800 - def set_(self): 800 + def set(self): 801 801 """ 802 802 Set auth credentials 803 803
+2 -2
packages/openapi-python/src/plugins/@hey-api/sdk/v1/node.ts
··· 72 72 const cachedProp = plugin.external('functools.cached_property'); 73 73 74 74 return [ 75 - $.func(memberName) 75 + $.method(memberName) 76 76 .decorator(cachedProp) 77 77 .param('self') 78 78 .returns(refChild) ··· 196 196 } else { 197 197 if (index > 0 || node.hasBody) node.newline(); 198 198 const method = implementFn({ 199 - node: $.func(createFnSymbol(plugin, item), (m) => 199 + node: $.method(createFnSymbol(plugin, item), (m) => 200 200 attachComment({ 201 201 node: m, 202 202 operation,
+8 -3
packages/openapi-python/src/py-dsl/decl/func.ts
··· 1 - import type { AnalysisContext, NodeName } from '@hey-api/codegen-core'; 1 + import type { AnalysisContext, NodeName, NodeNameSanitizer } from '@hey-api/codegen-core'; 2 2 import { isSymbol } from '@hey-api/codegen-core'; 3 3 4 4 import { py } from '../../ts-python'; ··· 22 22 23 23 export class FuncPyDsl extends Mixed { 24 24 readonly '~dsl' = 'FuncPyDsl'; 25 - override readonly nameSanitizer = safeRuntimeName; 25 + override readonly nameSanitizer: NodeNameSanitizer; 26 26 27 - constructor(name: NodeName, fn?: (f: FuncPyDsl) => void) { 27 + constructor( 28 + name: NodeName, 29 + fn?: (f: FuncPyDsl) => void, 30 + options?: { nameSanitizer?: NodeNameSanitizer }, 31 + ) { 28 32 super(); 33 + this.nameSanitizer = options?.nameSanitizer ?? safeRuntimeName; 29 34 this.name.set(name); 30 35 if (isSymbol(name)) { 31 36 name.setKind('function');
+10 -5
packages/openapi-python/src/py-dsl/index.ts
··· 71 71 // import { TypeTemplatePyDsl } from './type/template'; 72 72 // import { TypeTuplePyDsl } from './type/tuple'; 73 73 import { LazyPyDsl } from './utils/lazy'; 74 + import { safeKeywordName } from './utils/name'; 74 75 75 76 const pyDsl = { 76 77 /** Creates an array literal expression (e.g. `[1, 2, 3]`). */ ··· 147 148 /** Creates an import statement. */ 148 149 import: (...args: ConstructorParameters<typeof ImportPyDsl>) => new ImportPyDsl(...args), 149 150 150 - /** Creates a keyword argument expression (e.g. `name=value`). */ 151 - kwarg: (...args: ConstructorParameters<typeof KwargPyDsl>) => new KwargPyDsl(...args), 152 - 153 151 /** Creates an initialization block or statement. */ 154 152 // init: (...args: ConstructorParameters<typeof InitTsDsl>) => new InitTsDsl(...args), 153 + 154 + /** Creates a keyword argument expression (e.g. `name=value`). */ 155 + kwarg: (...args: ConstructorParameters<typeof KwargPyDsl>) => new KwargPyDsl(...args), 155 156 156 157 /** Creates a lazy, context-aware node with deferred evaluation. */ 157 158 lazy: <T extends py.Node>(...args: ConstructorParameters<typeof LazyPyDsl<T>>) => ··· 166 167 /** Creates an enum member declaration. */ 167 168 // member: (...args: ConstructorParameters<typeof EnumMemberTsDsl>) => new EnumMemberTsDsl(...args), 168 169 169 - /** Creates a method declaration inside a class or object. */ 170 - // method: (...args: ConstructorParameters<typeof MethodTsDsl>) => new MethodTsDsl(...args), 170 + /** Creates a class method declaration. */ 171 + method: ((name: NodeName, fn?: (f: FuncPyDsl) => void) => 172 + new FuncPyDsl(name, fn, { nameSanitizer: safeKeywordName })) as { 173 + (name: NodeName): FuncPyDsl; 174 + (name: NodeName, fn: (f: FuncPyDsl) => void): FuncPyDsl; 175 + }, 171 176 172 177 /** Creates a negation expression (`-x`). */ 173 178 // neg: (...args: ConstructorParameters<typeof PrefixTsDsl>) => new PrefixTsDsl(...args).neg(),
+2
packages/openapi-python/src/py-dsl/utils/name.ts
··· 51 51 }; 52 52 53 53 export const safeRuntimeName = (name: string): string => safeName(name, reserved.runtime); 54 + 55 + export const safeKeywordName = (name: string): string => safeName(name, reserved.keywords);
+6
packages/openapi-python/src/py-dsl/utils/reserved.ts
··· 29 29 } 30 30 31 31 const runtimeReserved = new ReservedList([...keywords.pythonKeywords, ...keywords.pythonBuiltins]); 32 + const keywordReserved = new ReservedList([...keywords.pythonKeywords]); 32 33 33 34 /** 34 35 * Reserved names for identifiers. These names will not be used 35 36 * for variables, functions, classes, or other identifiers in generated code. 36 37 */ 37 38 export const reserved = { 39 + /** 40 + * Reserved names for Python language keywords. These names are syntactically 41 + * invalid as identifiers in any scope. 42 + */ 43 + keywords: keywordReserved, 38 44 /** 39 45 * Reserved names for runtime identifiers. These names will not be used 40 46 * for variables, functions, classes, or other runtime identifiers in