Closed yukonn closed 6 years ago
I see the same problem with custom ports on http...
Providing customized port can be easily done with adding it on Options. This will help community.
This has already been accomplished in two merge requests #1 and #14. We just need one or the other merged in.
Hi guys,
Sorry for not responding earlier and not merging the pull requests.
The fact that most of the issues and pull requests are related to downloading the metadata got me thinking. This isn't really what this small library is supposed to do is it? It should convert OData to OpeanAPI. Downloading a file is not a core feature - it is easy for one to add custom ports, headers and HTTP support.
This is why I decided to deprecate the odata2openapi
function. One will have to download the metadata on their own and pass it as a string to the parse
function. There is plenty of code online for downloading a file. You can even use the current get
function as a starting point:
import * as http from 'http';
import * as https from 'https';
import * as url from 'url';
function get(protocol, host, path): Promise<string> {
return new Promise<string>((resolve, reject) => {
const options = {
host,
method: 'GET',
headers: {
'Accept': '*/*',
'User-Agent': 'odata2openapi'
},
path
};
const fetcher = (protocol.startsWith('https:') ? https.request : http.request);
const request = fetcher(options, (response) => {
let result = '';
response.on('data', (chunk) => {
result += chunk;
})
response.on('end', () => {
const { statusCode, headers } = response
if (statusCode >= 300 && statusCode < 400) {
const u = url.parse(headers['location']);
get(u.protocol, u.host, u.path).then(resolve, reject);
} else if (statusCode >= 200 && statusCode < 300) {
resolve(result);
} else {
reject(new Error(`Unexpected response: ${response}`));
}
})
});
request.on('error', reject);
request.end();
});
}
export default get;
I know this could be disappointing but I believe it is for the better - people could implement their own download logic this way.
example is working with http. but it does not work with "https" is binding with different port (443). And no way to pass the authenication.
Example OData Link : https://abc.com:90/example/OData/$metadata
odata2openapi('https://abc.com:90/example/OData/$metadata') .then(swagger => console.log(JSON.stringify(swagger, null, 2))) .catch(error => console.error(error)
{ Error: getaddrinfo ENOTFOUND abc.com:90 abc.com:90:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'abc.com:90', host: 'abc.com:90', port: 443 }