@@ -8,57 +8,17 @@ import { pascalCase, snakeCase } from 'change-case'
88import { convertCustomResourceName } from '../custom-resource-name-conversions.js'
99import { mapPropertyToPythonType } from '../python-type.js'
1010
11- // Python hard keywords cannot be used as identifiers. When a property name
12- // collides with one (e.g. "from"), the dataclass field and keyword argument
13- // are suffixed with an underscore while the original name is preserved as the
14- // dict key.
15- const PYTHON_KEYWORDS = new Set ( [
16- 'False' ,
17- 'None' ,
18- 'True' ,
19- 'and' ,
20- 'as' ,
21- 'assert' ,
22- 'async' ,
23- 'await' ,
24- 'break' ,
25- 'class' ,
26- 'continue' ,
27- 'def' ,
28- 'del' ,
29- 'elif' ,
30- 'else' ,
31- 'except' ,
32- 'finally' ,
33- 'for' ,
34- 'from' ,
35- 'global' ,
36- 'if' ,
37- 'import' ,
38- 'in' ,
39- 'is' ,
40- 'lambda' ,
41- 'nonlocal' ,
42- 'not' ,
43- 'or' ,
44- 'pass' ,
45- 'raise' ,
46- 'return' ,
47- 'try' ,
48- 'while' ,
49- 'with' ,
50- 'yield' ,
51- ] )
52-
53- const toSafeIdentifier = ( name : string ) : string =>
54- PYTHON_KEYWORDS . has ( name ) ? `${ name } _` : name
55-
5611export interface ResourceLayoutContext {
5712 className : string
5813 moduleName : string
14+ description : string
15+ isDeprecated : boolean
16+ deprecationMessage : string
5917 properties : Array < {
6018 name : string
61- safeName : string
19+ description : string
20+ isDeprecated : boolean
21+ deprecationMessage : string
6222 type : string
6323 isDictParam : boolean
6424 } >
@@ -84,29 +44,58 @@ const mergeResourceProperties = (resources: Resource[]): Property[] => {
8444export const getResourceLayoutContexts = (
8545 blueprint : Blueprint ,
8646) : ResourceLayoutContext [ ] => {
87- const models = new Map < string , Property [ ] > ( )
47+ const models = new Map <
48+ string ,
49+ {
50+ properties : Property [ ]
51+ description : string
52+ isDeprecated : boolean
53+ deprecationMessage : string
54+ }
55+ > ( )
8856
8957 for ( const resource of blueprint . resources ) {
90- models . set ( resource . resourceType , resource . properties )
58+ models . set ( resource . resourceType , resource )
9159 }
9260
9361 // The event and action attempt variants merge into a single dataclass with
9462 // the union of the variant properties, overriding the base resource schema.
95- models . set (
96- 'action_attempt' ,
97- mergeResourceProperties ( blueprint . actionAttempts ) ,
98- )
99- models . set ( 'event' , mergeResourceProperties ( blueprint . events ) )
63+ const actionAttemptModel = models . get ( 'action_attempt' )
64+ models . set ( 'action_attempt' , {
65+ properties : mergeResourceProperties ( blueprint . actionAttempts ) ,
66+ description :
67+ actionAttemptModel ?. description ??
68+ 'An attempt to perform an action in the Seam API.' ,
69+ isDeprecated : actionAttemptModel ?. isDeprecated ?? false ,
70+ deprecationMessage : actionAttemptModel ?. deprecationMessage ?? '' ,
71+ } )
72+ const eventModel = models . get ( 'event' )
73+ models . set ( 'event' , {
74+ properties : mergeResourceProperties ( blueprint . events ) ,
75+ description : eventModel ?. description ?? 'An event emitted by the Seam API.' ,
76+ isDeprecated : eventModel ?. isDeprecated ?? false ,
77+ deprecationMessage : eventModel ?. deprecationMessage ?? '' ,
78+ } )
10079
10180 if ( blueprint . pagination != null ) {
102- models . set ( 'pagination' , blueprint . pagination . properties )
81+ models . set ( 'pagination' , {
82+ properties : blueprint . pagination . properties ,
83+ description : blueprint . pagination . description ,
84+ isDeprecated : false ,
85+ deprecationMessage : '' ,
86+ } )
10387 }
10488
10589 return [ ...models . entries ( ) ]
106- . map ( ( [ name , properties ] ) => {
90+ . map ( ( [ name , model ] ) => {
91+ const { properties, description, isDeprecated, deprecationMessage } =
92+ model
10793 const className = pascalCase ( convertCustomResourceName ( name ) )
10894 return {
10995 className,
96+ description,
97+ isDeprecated,
98+ deprecationMessage,
11099 // Derived from the class name rather than the resource type so the
111100 // module always matches the dataclass it exports (e.g. the "event"
112101 // resource becomes SeamEvent in seam_event.py).
@@ -115,7 +104,9 @@ export const getResourceLayoutContexts = (
115104 const type = mapPropertyToPythonType ( property )
116105 return {
117106 name : property . name ,
118- safeName : toSafeIdentifier ( property . name ) ,
107+ description : property . description ,
108+ isDeprecated : property . isDeprecated ,
109+ deprecationMessage : property . deprecationMessage ,
119110 type,
120111 isDictParam :
121112 type . startsWith ( 'Dict' ) || property . name === 'properties' ,
0 commit comments