@@ -428,100 +428,8 @@ const eventDefaults = event => {
428428 return event
429429}
430430
431- const createEventResultSchemaFromProperty = ( property , type = 'Changed' ) => {
432- const subscriberType = property . tags . map ( t => t [ 'x-subscriber-type' ] ) . find ( t => typeof t === 'string' ) || 'context'
433-
434- const caps = property . tags . find ( t => t . name === 'capabilities' )
435- let name = caps [ 'x-provided-by' ] ? caps [ 'x-provided-by' ] . split ( '.' ) . pop ( ) . replace ( 'onRequest' , '' ) : property . name
436- name = name . charAt ( 0 ) . toUpperCase ( ) + name . substring ( 1 )
437-
438- if ( subscriberType === 'global' ) {
439- // wrap the existing result and the params in a new result object
440- const schema = {
441- title : methodRename ( property , name => name . charAt ( 0 ) . toUpperCase ( ) + name . substring ( 1 ) + type + 'Info' ) . split ( '.' ) . pop ( ) ,
442- type : "object" ,
443- properties : {
444-
445- } ,
446- required : [ ]
447- }
448-
449- // add all of the params
450- property . params . filter ( p => p . name !== 'listen' ) . forEach ( p => {
451- schema . properties [ p . name ] = p . schema
452- schema . required . push ( p . name )
453- } )
454-
455- // add the result (which might override a param of the same name)
456- schema . properties [ property . result . name ] = property . result . schema
457- ! schema . required . includes ( property . result . name ) && schema . required . push ( property . result . name )
458-
459- return schema
460- }
461- }
462-
463- const createEventFromProperty = ( property , type = '' , alternative , json ) => {
464- const provider = ( property . tags . find ( t => t [ 'x-provided-by' ] ) || { } ) [ 'x-provided-by' ]
465- const pusher = provider ? provider . replace ( 'onRequest' , '' ) . split ( '.' ) . map ( ( x , i , arr ) => ( i === arr . length - 1 ) ? x . charAt ( 0 ) . toLowerCase ( ) + x . substr ( 1 ) : x ) . join ( '.' ) : undefined
466- const event = eventDefaults ( JSON . parse ( JSON . stringify ( property ) ) )
467- // event.name = (module ? module + '.' : '') + 'on' + event.name.charAt(0).toUpperCase() + event.name.substr(1) + type
468- event . name = provider ? provider . split ( '.' ) . pop ( ) . replace ( 'onRequest' , '' ) : event . name . charAt ( 0 ) . toUpperCase ( ) + event . name . substr ( 1 ) + type
469- event . name = event . name . split ( '.' ) . map ( ( x , i , arr ) => ( i === arr . length - 1 ) ? 'on' + x . charAt ( 0 ) . toUpperCase ( ) + x . substr ( 1 ) : x ) . join ( '.' )
470- const subscriberFor = pusher || ( json . info . title + '.' + property . name )
471-
472- const old_tags = JSON . parse ( JSON . stringify ( property . tags ) )
473-
474- alternative && ( event . tags [ 0 ] [ 'x-alternative' ] = alternative )
475-
476- ! provider && event . tags . unshift ( {
477- name : "subscriber" ,
478- 'x-subscriber-for' : subscriberFor
479- } )
480-
481- const subscriberType = property . tags . map ( t => t [ 'x-subscriber-type' ] ) . find ( t => typeof t === 'string' ) || 'context'
482-
483- // if the subscriber type is global, zap all of the parameters and change the result type to the schema that includes them
484- if ( subscriberType === 'global' ) {
485-
486- // wrap the existing result and the params in a new result object
487- const result = {
488- name : "data" ,
489- schema : {
490- $ref : "#/components/schemas/" + event . name . substring ( 2 ) + 'Info'
491- }
492- }
493-
494- event . examples . map ( example => {
495- const result = { }
496- example . params . filter ( p => p . name !== 'listen' ) . forEach ( p => {
497- result [ p . name ] = p . value
498- } )
499- result [ example . result . name ] = example . result . value
500- example . params = example . params . filter ( p => p . name === 'listen' )
501- example . result . name = "data"
502- example . result . value = result
503- } )
504-
505- event . result = result
506-
507- // remove the params
508- event . params = event . params . filter ( p => p . name === 'listen' )
509- }
510-
511- old_tags . forEach ( t => {
512- if ( t . name !== 'property' && ! t . name . startsWith ( 'property:' ) && t . name !== 'push-pull' )
513- {
514- event . tags . push ( t )
515- }
516- } )
517-
518- provider && ( event . tags . find ( t => t . name === 'capabilities' ) [ 'x-provided-by' ] = subscriberFor )
519-
520- return event
521- }
522431
523432const createNotifierFromProperty = ( property , type = 'Changed' ) => {
524- const subscriberType = property . tags . map ( t => t [ 'x-subscriber-type' ] ) . find ( t => typeof t === 'string' ) || 'context'
525433
526434 const notifier = JSON . parse ( JSON . stringify ( property ) )
527435 notifier . name = methodRename ( notifier , name => name + type )
@@ -532,40 +440,13 @@ const createNotifierFromProperty = (property, type='Changed') => {
532440 'x-event' : methodRename ( notifier , name => 'on' + name . charAt ( 0 ) . toUpperCase ( ) + name . substring ( 1 ) )
533441 } )
534442
535- if ( subscriberType === 'global' ) {
536- notifier . params = [
537- {
538- name : "info" ,
539- schema : {
540- "$ref" : "#/components/schemas/" + methodRename ( notifier , name => name . charAt ( 0 ) . toUpperCase ( ) + name . substr ( 1 ) + 'Info' )
541- }
542- }
543- ]
544- }
545- else {
546- notifier . params . push ( notifier . result )
547- }
548-
443+ notifier . params . push ( notifier . result )
444+
549445 delete notifier . result
550-
551- if ( subscriberType === 'global' ) {
552- notifier . examples = property . examples . map ( example => ( {
553- name : example . name ,
554- params : [
555- {
556- name : "info" ,
557- value : Object . assign ( Object . fromEntries ( example . params . map ( p => [ p . name , p . value ] ) ) , Object . fromEntries ( [ [ example . result . name , example . result . value ] ] ) )
558- }
559- ]
560- } ) )
561- }
562- else {
563- notifier . examples . forEach ( example => {
446+ notifier . examples . forEach ( example => {
564447 example . params . push ( example . result )
565448 delete example . result
566449 } )
567- }
568-
569450 return notifier
570451}
571452
@@ -602,10 +483,6 @@ const createNotifierFromEvent = (event, json) => {
602483 return push
603484}
604485
605- const createPushEvent = ( requestor , json ) => {
606- return createEventFromProperty ( requestor , '' , undefined , json )
607- }
608-
609486const createPullEventFromPush = ( pusher , json ) => {
610487 const event = JSON . parse ( JSON . stringify ( pusher ) )
611488 event . params = [ ]
@@ -1042,17 +919,11 @@ const generatePropertyEvents = json => {
1042919
1043920 properties . forEach ( property => {
1044921 json . methods . push ( createNotifierFromProperty ( property ) )
1045- const schema = createEventResultSchemaFromProperty ( property )
1046- if ( schema ) {
1047- json . components . schemas [ property . name . split ( '.' ) . shift ( ) + '.' + schema . title ] = schema
1048- }
922+
1049923 } )
1050924 readonlies . forEach ( property => {
1051925 json . methods . push ( createNotifierFromProperty ( property ) )
1052- const schema = createEventResultSchemaFromProperty ( property )
1053- if ( schema ) {
1054- json . components . schemas [ property . name . split ( '.' ) . shift ( ) + '.' + schema . title ] = schema
1055- }
926+
1056927 } )
1057928
1058929 return json
@@ -1074,21 +945,6 @@ const generatePolymorphicPullEvents = json => {
1074945 return json
1075946}
1076947
1077- const generatePushPullMethods = json => {
1078- const requestors = json . methods . filter ( m => m . tags && m . tags . find ( t => t . name == 'push-pull' ) ) || [ ]
1079- requestors . forEach ( requestor => {
1080- json . methods . push ( createPushEvent ( requestor , json ) )
1081-
1082- const schema = createEventResultSchemaFromProperty ( requestor )
1083- if ( schema ) {
1084- json . components = json . components || { }
1085- json . components . schemas = json . components . schemas || { }
1086- json . components . schemas [ schema . title ] = schema
1087- }
1088- } )
1089-
1090- return json
1091- }
1092948
1093949const generateProvidedByMethods = json => {
1094950 const requestors = json . methods . filter ( m => ! m . tags . find ( t => t . name === 'notifier' ) ) . filter ( m => m . tags && m . tags . find ( t => t [ 'x-provided-by' ] ) ) || [ ]
0 commit comments