You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've written a tsgen-odata.js script which consumes a csdl xml directly from $metadata endpoint and then calls tsgen-core.ts for entity generation. It uses datajs library to parse metadata as you do in breeze.js
var argv = require('yargs').argv;
var tsGenCore = require('./tsgen-core');
var fs = require('fs');
var doRequest = require('request');
require('datajs');
var xmldom = require('xmldom');
global.DOMParser = xmldom.DOMParser;
var metaPath = './tools/metadata.json';
try {
//var metaUrl = 'http://localhost:51163/odata/$metadata';
var metaUrl = argv.i || argv.input;
OData.defaultHttpClient = {
request: function(request, success, error) {
doRequest({
url: request.requestUri,
headers: request.headers
}, (err, resp, body) => {
var response;
if (!err && resp.statusCode >= 200 && resp.statusCode <= 299) {
response = { requestUri: request.requestUri, statusCode: resp.statusCode, statusText: resp.statusText, headers: resp.headers, body: body };
success(response);
} else {
error({ message: "HTTP request failed", request: request, response: response });
}
});
}
};
OData.read({
requestUri: metaUrl,
// headers: { "Accept": "application/json"}
headers: { 'Accept': 'application/*; odata.metadata=full'}
},
function (data) {
// data.dataServices.schema is an array of schemas. with properties of
// entityContainer[], association[], entityType[], and namespace.
if (!data || !data.dataServices) {
var error = new Error("Metadata query failed for: " + url);
return deferred.reject(error);
}
var csdlMetadata = data.dataServices;
//
var jsonStr = JSON.stringify(csdlMetadata);
fs.writeFile(metaPath, jsonStr, (err) => {
if (err) throw err;
var config = argvToConfig();
tsGenCore.generate(config);
});
},
function (error) {
var message = "Metadata query failed; " + (error.message || "");
console.log('Unexpected error occurred: ' + message);
},
OData.metadataHandler
);
} catch (e) {
console.log('Unexpected error occurred: ' + e.stack);
}
function argvToConfig() {
var config = {
inputFileName: metaPath,//argv.i || argv.input,
outputFolder: argv.o || argv.outputFolder,
sourceFilesFolder: argv.s || argv.sourceFiles,
baseClassName: argv.b || argv.baseClass,
camelCase: !!(argv.c || argv.camelCase),
kebabCaseFileNames: !!(argv.k || argv.kebabCaseFileNames),
useEnumTypes: !!(argv.e || argv.useEnumTypes)
};
return config;
}
You may treat this as a feature request
The text was updated successfully, but these errors were encountered:
I've written a tsgen-odata.js script which consumes a csdl xml directly from $metadata endpoint and then calls tsgen-core.ts for entity generation. It uses datajs library to parse metadata as you do in breeze.js
You may treat this as a feature request
The text was updated successfully, but these errors were encountered: