This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
/** | ||
* Object that contain the license information as defined in | ||
* https://spec.openapis.org/oas/v3.0.3.html#contactObject | ||
*/ | ||
export interface ContactObject { | ||
name?: string, | ||
url?: string, | ||
email?: string | ||
} | ||
|
||
/** | ||
* Object that contain the license information as defined in | ||
* https://spec.openapis.org/oas/v3.0.3.html#licenseObject | ||
*/ | ||
export interface LicenseObject { | ||
name: string, | ||
url?: string | ||
} | ||
|
||
/** | ||
* Object that contain the api information as defined in | ||
* https://spec.openapis.org/oas/v3.0.3.html#info-object | ||
*/ | ||
export interface InfoObject { | ||
title?: string, | ||
description?: string, | ||
termsOfService?: string, | ||
contact?: ContactObject, | ||
license?: LicenseObject, | ||
version?: string, | ||
} | ||
|
||
/** | ||
* Object that contain the servers information as defined in | ||
* https://spec.openapis.org/oas/v3.0.3.html#server-object | ||
* field `variables`is not supported yet | ||
*/ | ||
export interface ServerObject { | ||
url: string, | ||
description?: string | ||
} | ||
|
||
/** | ||
* Object that contain the servers information as defined in | ||
* https://spec.openapis.org/oas/v3.0.3.html#security-scheme-object | ||
*/ | ||
export interface SecurityObject { | ||
type: 'http', | ||
description?: string, | ||
scheme: 'bearer' | 'basic', | ||
bearerFormat?: string | ||
} | ||
|
||
export interface AuthOptions { | ||
[key: string]: SecurityObject | ||
} | ||
|
||
/** | ||
* Object that contain the external docs information as defined in | ||
* https://spec.openapis.org/oas/v3.0.3.html#external-documentation-object | ||
*/ | ||
export interface ExternalDocsObject { | ||
description?: string, | ||
url?: string | ||
} | ||
|
||
export interface FoldersOption { | ||
concat: boolean, | ||
separator: string | ||
} | ||
|
||
export interface Options { | ||
info?: InfoObject, | ||
defaultTag?: string, | ||
pathDepth?: number, | ||
auth?: AuthOptions, | ||
servers?: Array<ServerObject>, | ||
externalDocs?: ExternalDocsObject, | ||
folders?: FoldersOption | ||
} | ||
|
||
export function postmanToOpenApi (input: string, output?: string, options?: Options) : string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["ES6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"baseUrl": "../", | ||
"typeRoots": ["../"], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
|
||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"typescript-test.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
'use strict' | ||
|
||
import { | ||
Options, ContactObject, LicenseObject, InfoObject, | ||
ServerObject, SecurityObject, ExternalDocsObject, | ||
FoldersOption, postmanToOpenApi | ||
} from './index.d' | ||
|
||
const contact:ContactObject = { | ||
name: 'My Enterprise', | ||
url: 'http://fancyEnterprise.com', | ||
email: 'support@myfancy.com' | ||
} | ||
|
||
const license:LicenseObject = { | ||
name: 'MIT', | ||
url: 'http://fancyEnterprise.com/mit' | ||
} | ||
|
||
const info:InfoObject = { | ||
title: 'Amazing API', | ||
description: 'The best API you can find out there', | ||
termsOfService: 'http://fancyEnterprise.com/tos', | ||
contact, | ||
license, | ||
version: '1.0.1' | ||
} | ||
|
||
const serverDev: ServerObject = { | ||
url: 'http://fancyEnterprise.com/dev', | ||
description: 'Development environment' | ||
} | ||
|
||
const serverPro: ServerObject = { | ||
url: 'http://fancyEnterprise.com/api', | ||
description: 'Live environment' | ||
} | ||
|
||
const basicAuth:SecurityObject = { | ||
type: 'http', | ||
description: 'Basic authentication using user and password', | ||
scheme: 'basic' | ||
} | ||
|
||
const bearerAuth:SecurityObject = { | ||
type: 'http', | ||
description: 'Bearer authentication', | ||
scheme: 'bearer', | ||
bearerFormat: 'Signed JWT' | ||
} | ||
|
||
const externalDocs:ExternalDocsObject = { | ||
description: 'Fancy API documentation in detail', | ||
url: 'http://fancyEnterprise.com/dev' | ||
} | ||
|
||
const folders:FoldersOption = { | ||
concat: true, | ||
separator: '->' | ||
} | ||
|
||
const options:Options = { | ||
info, | ||
defaultTag: 'my Tag', | ||
pathDepth: 0, | ||
auth: { | ||
'basicAuth': basicAuth, | ||
'bearerAuth': bearerAuth | ||
}, | ||
servers: [serverDev, serverPro], | ||
externalDocs, | ||
folders | ||
}; | ||
|
||
(async () => { | ||
|
||
const openAPI1 = postmanToOpenApi('./path/to/postman_collection.json') | ||
|
||
const openAPI2 = postmanToOpenApi('./path/to/postman_collection.json', './path/to/result/openApi.yml') | ||
|
||
const openAPI3 = postmanToOpenApi('./path/to/postman_collection.json', './path/to/result/openApi.yml', options) | ||
|
||
})(); | ||
// TODO what is really mandatory or not as is not the same that the object is mandatory | ||
// and then inside the object what should be complete, example type in auth? |