2017-11-30 7 views
0

odata metadata.xmlファイルをjsonに変換するために 'akorchev/odata2openapi'モジュールを使用しようとしています。ドキュメントごとに、次のコードを実装しました。oDataファイルの解析で約束する

const o2oapi = require('odata2openapi'); 

function_B (content) { 
    o2oapi.parse(content) 
    .then(entitySets => convert(entitySets)) 
    .then(swagger => console.log(JSON.stringify(swagger, null, 2))) 
    .catch(error => console.error(error)); 
} 

コンテンツ変数は、コンソールに表示できるメタデータのxmlストリームです。関数Bの解析方法ログインするときに、私はまた、次のような結果を見ることができます:残念ながら

Promise { 
{ entitySets: [ [Object], [Object] ], 
    version: '1.0', 
    complexTypes: [], 
    singletons: [], 
    actions: [], 
    functions: [], 
    defaultNamespace: 'ZEXAMPLE_SRV', 
    entityTypes: [ [Object], [Object] ] } } 

を、私は他の機能C.

function_A (content, x, y, z){ 
    function_C (function_B (content), x, y ,z); 
} 
に渡す「闊歩から」最終的な結果を得ることができないのです

私は自分のコードを成功させることなく適応させようとしました。アドバイスをお願いしますか?

+1

'convert'何をしますか? 'parse'によって出力される' entitySets'プロパティの内容を期待していますか?あなたはそのオブジェクト全体ではなく、そのプロパティを渡しているからです。あなたは 'then'関数の中でコンソールにログアウトし、何が起こっているのかを見ることができます。 –

答えて

1

私は最終的に複数の変更で問題を解決できました。 @ ethan-jewettの示唆したように、入力が間違っていることを確認するためにconvertメソッドをデバッグする必要がありました。さらに、@moshimoshiの示唆しているように、私は非同期関数をカスケードする必要がありました。ここで

、関数Bの最終的なコードの実装:

function_B(content) { 
    return new Promise(function (resolve, reject) { 

     const options = { 
      host: '', 
      path: '' 
     }; 

     parse(content) 
      .then(entitySets => convert(entitySets.entitySets, options)) 
      .then(function(swagger) { 
       var result = JSON.stringify(swagger, null, 2); 
       resolve(result); 
      })  
      .catch(error => { 
       reject(error); 
      }); 
    });   
} 

関数Aの場合:

function_A (content, x, y, z){ 
    function_B (content).then(result => function_C (result , x, y ,z)); 
}