-
Notifications
You must be signed in to change notification settings - Fork 84
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
21 changed files
with
712 additions
and
147 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {Command, flags} from '@oclif/command' | ||
import * as fs from 'fs-extra' | ||
import * as clipboardy from 'clipboardy' | ||
// @ts-ignore | ||
import * as niceTry from 'nice-try' | ||
import * as path from 'path' | ||
// @ts-ignore | ||
import * as opticEngine from '../../../provided/domain.js' | ||
import cli from 'cli-ux' | ||
// @ts-ignore | ||
import * as fetch from 'node-fetch' | ||
import {getPaths} from '../../Paths' | ||
import {prepareEvents} from '../../PersistUtils' | ||
import analytics from '../../lib/analytics' | ||
import * as yaml from 'js-yaml' | ||
|
||
|
||
export default class GenerateOas extends Command { | ||
|
||
static description = 'export an OpenAPI 3.1 spec' | ||
|
||
static flags = { | ||
json: flags.boolean(), | ||
yaml: flags.boolean(), | ||
} | ||
|
||
async run() { | ||
|
||
const {flags} = this.parse(GenerateOas) | ||
// @ts-ignore | ||
const {outputPath, specStorePath} = await getPaths() | ||
|
||
const oasGenerator = opticEngine.com.seamless.contexts.rfc.projections.OASProjectionHelper() | ||
|
||
const fileContents = niceTry(() => fs.readFileSync(specStorePath).toString()) || '[]' | ||
cli.action.start('Generating OAS file') | ||
|
||
try { | ||
const specAsJson = oasGenerator.fromEventString(fileContents) | ||
|
||
const writeJson = flags.json || (!flags.json && !flags.yaml) | ||
const writeYaml = flags.yaml | ||
|
||
cli.action.stop('Done!') | ||
|
||
if (writeJson) { | ||
fs.ensureDirSync(outputPath) | ||
const oasPath = path.join(outputPath, 'openapi.json') | ||
fs.writeFileSync(path.join(outputPath, 'openapi.json'), JSON.stringify(specAsJson, null, 2)) | ||
return this.log('OpenAPI written to ' + oasPath) | ||
} | ||
|
||
if (writeYaml) { | ||
fs.ensureDirSync(outputPath) | ||
const oasPath = path.join(outputPath, 'openapi.yaml') | ||
fs.writeFileSync(path.join(outputPath, 'openapi.yaml'), yaml.safeDump(specAsJson, {indent: 1})) | ||
return this.log('OpenAPI written to ' + oasPath) | ||
} | ||
|
||
} catch (e) { | ||
console.error('Error generating OpenAPI ') | ||
console.log(e) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.