Skip to content

Commit 7858941

Browse files
committed
Merge branch 'develop'
2 parents 828209f + 373800c commit 7858941

21 files changed

+712
-147
lines changed

api-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@useoptic/cli",
33
"description": "Optic's open source tool for building APIs that document & test themselves",
4-
"version": "6.5.0",
4+
"version": "6.5.1",
55
"author": "@useoptic",
66
"bin": {
77
"api": "./bin/run"

api-cli/src/Paths.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as findUp from 'find-up'
33
import * as fs from 'fs-extra'
44

55
export interface IPathMapping {
6-
6+
77
}
88
export async function getPaths(fallbackPath: (cwd: string) => string = (cwd) => path.join(cwd, '.api')) {
99
const rootPath = await (async () => {
@@ -13,7 +13,7 @@ export async function getPaths(fallbackPath: (cwd: string) => string = (cwd) =>
1313
}
1414
return fallbackPath(process.cwd())
1515
})()
16-
16+
1717
await fs.ensureDir(rootPath)
1818
process.chdir(path.resolve(rootPath, '../'))
1919

@@ -31,7 +31,7 @@ async function getPathsRelativeToCwd(cwd: string): Promise<IPathMapping> {
3131
const exampleRequestsPath = path.join(basePath, 'example-requests')
3232
await fs.ensureDir(sessionsPath)
3333
await fs.ensureDir(exampleRequestsPath)
34-
const outputPath = path.join(basePath, 'output')
34+
const outputPath = path.join(basePath, 'generated')
3535

3636
return {
3737
cwd,
@@ -44,4 +44,4 @@ async function getPathsRelativeToCwd(cwd: string): Promise<IPathMapping> {
4444
exampleRequestsPath,
4545
outputPath
4646
}
47-
}
47+
}

api-cli/src/commands/generate.ts

-70
This file was deleted.

api-cli/src/commands/generate/oas.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {Command, flags} from '@oclif/command'
2+
import * as fs from 'fs-extra'
3+
import * as clipboardy from 'clipboardy'
4+
// @ts-ignore
5+
import * as niceTry from 'nice-try'
6+
import * as path from 'path'
7+
// @ts-ignore
8+
import * as opticEngine from '../../../provided/domain.js'
9+
import cli from 'cli-ux'
10+
// @ts-ignore
11+
import * as fetch from 'node-fetch'
12+
import {getPaths} from '../../Paths'
13+
import {prepareEvents} from '../../PersistUtils'
14+
import analytics from '../../lib/analytics'
15+
import * as yaml from 'js-yaml'
16+
17+
18+
export default class GenerateOas extends Command {
19+
20+
static description = 'export an OpenAPI 3.1 spec'
21+
22+
static flags = {
23+
json: flags.boolean(),
24+
yaml: flags.boolean(),
25+
}
26+
27+
async run() {
28+
29+
const {flags} = this.parse(GenerateOas)
30+
// @ts-ignore
31+
const {outputPath, specStorePath} = await getPaths()
32+
33+
const oasGenerator = opticEngine.com.seamless.contexts.rfc.projections.OASProjectionHelper()
34+
35+
const fileContents = niceTry(() => fs.readFileSync(specStorePath).toString()) || '[]'
36+
cli.action.start('Generating OAS file')
37+
38+
try {
39+
const specAsJson = oasGenerator.fromEventString(fileContents)
40+
41+
const writeJson = flags.json || (!flags.json && !flags.yaml)
42+
const writeYaml = flags.yaml
43+
44+
cli.action.stop('Done!')
45+
46+
if (writeJson) {
47+
fs.ensureDirSync(outputPath)
48+
const oasPath = path.join(outputPath, 'openapi.json')
49+
fs.writeFileSync(path.join(outputPath, 'openapi.json'), JSON.stringify(specAsJson, null, 2))
50+
return this.log('OpenAPI written to ' + oasPath)
51+
}
52+
53+
if (writeYaml) {
54+
fs.ensureDirSync(outputPath)
55+
const oasPath = path.join(outputPath, 'openapi.yaml')
56+
fs.writeFileSync(path.join(outputPath, 'openapi.yaml'), yaml.safeDump(specAsJson, {indent: 1}))
57+
return this.log('OpenAPI written to ' + oasPath)
58+
}
59+
60+
} catch (e) {
61+
console.error('Error generating OpenAPI ')
62+
console.log(e)
63+
}
64+
}
65+
}

api-cli/src/commands/publish-oas.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import cli from 'cli-ux'
1010
import * as fetch from 'node-fetch'
1111
import {fromOptic} from '../lib/log-helper'
1212
import * as colors from 'colors'
13-
import Generate from './generate'
13+
import Oas from './generate/oas'
1414
import {exec, spawn, SpawnOptions} from 'child_process'
1515
import Init from './init'
1616
import {processSetting, readApiConfig} from './start'
@@ -37,7 +37,7 @@ export default class PublishOas extends Command {
3737
return this.error('No command registered for `publish-oas`. Add one to your api.yml file')
3838
}
3939

40-
const generated = await Generate.run(['oas'])
40+
const generated = await Oas.run(['oas'])
4141
if (generated) {
4242
console.log(generated)
4343
const commandToRun = processSetting(publishOasCommand, {OAS_PATH: generated})

api-cli/tsconfig.tsbuildinfo

+41-40
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
"signature": "aca36e2d27783f4bad7fc1786a532ff76024f0fc8575df48bcd9a5eb452fe7e7"
327327
},
328328
"./src/paths.ts": {
329-
"version": "cb8220ef6e1c6dcb45904a596b5df5f905674a71a7032a3e986499c522bdf8cd",
329+
"version": "b769654f69bd018154204952ed7b46a249c225eadfe6b80fd45902e31c28a7c2",
330330
"signature": "3c6be598c4405724e8ed2c5bd640c27341b23c15c654ad8943a37100271ede6f"
331331
},
332332
"./src/persistutils.ts": {
@@ -421,6 +421,10 @@
421421
"version": "b48640c615edeac46a37fa4c3f9427539c7b0c9c9dced07d374dcec44fc4ffb7",
422422
"signature": "b48640c615edeac46a37fa4c3f9427539c7b0c9c9dced07d374dcec44fc4ffb7"
423423
},
424+
"./node_modules/colors/index.d.ts": {
425+
"version": "a17e831d16c27cbe4d6f0bb238c1ded0d4a26c282009e431c68733be0b792f4f",
426+
"signature": "a17e831d16c27cbe4d6f0bb238c1ded0d4a26c282009e431c68733be0b792f4f"
427+
},
424428
"./node_modules/@oclif/errors/lib/handle.d.ts": {
425429
"version": "207218b7704a71e718a25a35101afb2206581fd07c878c34540038639ad2759e",
426430
"signature": "207218b7704a71e718a25a35101afb2206581fd07c878c34540038639ad2759e"
@@ -505,14 +509,6 @@
505509
"version": "72b62584101abbf031fd6e73a21842a99877186d422cb9e65aa470c2b98463f4",
506510
"signature": "60b33bcb9810f8e80f30a186b41f25d05b97a7781cf8f03edb9315d17a7aeaf1"
507511
},
508-
"./src/commands/generate.ts": {
509-
"version": "017f9750f51931f278a1fe68425c674d64372bec942b3d3e30cdef285ca00a71",
510-
"signature": "f6be6a1f6937bf42d3b2190e690070d2721913b5f162a1a359c189175d932696"
511-
},
512-
"./node_modules/colors/index.d.ts": {
513-
"version": "a17e831d16c27cbe4d6f0bb238c1ded0d4a26c282009e431c68733be0b792f4f",
514-
"signature": "a17e831d16c27cbe4d6f0bb238c1ded0d4a26c282009e431c68733be0b792f4f"
515-
},
516512
"./node_modules/open/index.d.ts": {
517513
"version": "1d5adf522de176e09dcabab58740bce14bb99356fb6474f621a152461a5e4703",
518514
"signature": "1d5adf522de176e09dcabab58740bce14bb99356fb6474f621a152461a5e4703"
@@ -1161,8 +1157,12 @@
11611157
"version": "0b0481c285c517664694fd9f2e7636dfcae7cafff4a54318d2c9453e61ed91b9",
11621158
"signature": "02d804c0bb60cd4693267f760804c914bd4145db7c176ae1a70f346f0fa104fc"
11631159
},
1160+
"./src/commands/generate/oas.ts": {
1161+
"version": "3f41d1d430eda1bcc52d60ce882522728679aacf461cc45fc53fdf52ac2275f7",
1162+
"signature": "7bbc3a0caebfd245e2b09fda2038ed29e8f8082081c2203ffe23b1f068eb0b10"
1163+
},
11641164
"./src/commands/publish-oas.ts": {
1165-
"version": "f334103858999564b3d2cf5c64855f970401acfb14a93fef2e78caf4e6060e92",
1165+
"version": "c6342852cf3fb843ccabb1429845f0676bf7f4d6c1ec9472149038cbbb772976",
11661166
"signature": "a5f91a172a7df9fb875aa8a83eee10175de0ff3ad2566ce4689b9ac27907615e"
11671167
},
11681168
"./node_modules/@types/anymatch/index.d.ts": {
@@ -1903,6 +1903,10 @@
19031903
"./node_modules/@types/node/util.d.ts",
19041904
"./node_modules/@types/node/ts3.2/util.d.ts"
19051905
],
1906+
"./node_modules/colors/index.d.ts": [
1907+
"./node_modules/@types/node/util.d.ts",
1908+
"./node_modules/@types/node/ts3.2/util.d.ts"
1909+
],
19061910
"./node_modules/@oclif/errors/lib/handle.d.ts": [
19071911
"./node_modules/@types/node/util.d.ts",
19081912
"./node_modules/@types/node/ts3.2/util.d.ts"
@@ -2010,23 +2014,6 @@
20102014
"./node_modules/@types/node/util.d.ts",
20112015
"./node_modules/@types/node/ts3.2/util.d.ts"
20122016
],
2013-
"./src/commands/generate.ts": [
2014-
"./node_modules/@oclif/command/lib/index.d.ts",
2015-
"./node_modules/@types/fs-extra/index.d.ts",
2016-
"./node_modules/clipboardy/index.d.ts",
2017-
"./node_modules/@types/node/path.d.ts",
2018-
"./node_modules/cli-ux/lib/index.d.ts",
2019-
"./src/paths.ts",
2020-
"./src/persistutils.ts",
2021-
"./node_modules/@types/js-yaml/index.d.ts",
2022-
"./src/lib/analytics.ts",
2023-
"./node_modules/@types/node/util.d.ts",
2024-
"./node_modules/@types/node/ts3.2/util.d.ts"
2025-
],
2026-
"./node_modules/colors/index.d.ts": [
2027-
"./node_modules/@types/node/util.d.ts",
2028-
"./node_modules/@types/node/ts3.2/util.d.ts"
2029-
],
20302017
"./node_modules/open/index.d.ts": [
20312018
"./node_modules/@types/node/child_process.d.ts",
20322019
"./node_modules/@types/node/ts3.2/index.d.ts",
@@ -3335,6 +3322,19 @@
33353322
"./node_modules/@types/node/util.d.ts",
33363323
"./node_modules/@types/node/ts3.2/util.d.ts"
33373324
],
3325+
"./src/commands/generate/oas.ts": [
3326+
"./node_modules/@oclif/command/lib/index.d.ts",
3327+
"./node_modules/@types/fs-extra/index.d.ts",
3328+
"./node_modules/clipboardy/index.d.ts",
3329+
"./node_modules/@types/node/path.d.ts",
3330+
"./node_modules/cli-ux/lib/index.d.ts",
3331+
"./src/paths.ts",
3332+
"./src/persistutils.ts",
3333+
"./src/lib/analytics.ts",
3334+
"./node_modules/@types/js-yaml/index.d.ts",
3335+
"./node_modules/@types/node/util.d.ts",
3336+
"./node_modules/@types/node/ts3.2/util.d.ts"
3337+
],
33383338
"./src/commands/publish-oas.ts": [
33393339
"./node_modules/@oclif/command/lib/index.d.ts",
33403340
"./node_modules/@types/fs-extra/index.d.ts",
@@ -3343,7 +3343,7 @@
33433343
"./node_modules/cli-ux/lib/index.d.ts",
33443344
"./src/lib/log-helper.ts",
33453345
"./node_modules/colors/index.d.ts",
3346-
"./src/commands/generate.ts",
3346+
"./src/commands/generate/oas.ts",
33473347
"./node_modules/@types/node/child_process.d.ts",
33483348
"./src/commands/init.ts",
33493349
"./src/commands/start.ts",
@@ -3720,6 +3720,13 @@
37203720
"./node_modules/@types/node/util.d.ts",
37213721
"./node_modules/@types/node/ts3.2/util.d.ts"
37223722
],
3723+
"./src/commands/generate/oas.ts": [
3724+
"./node_modules/@oclif/parser/lib/flags.d.ts",
3725+
"./node_modules/@oclif/command/lib/index.d.ts"
3726+
],
3727+
"./src/commands/publish-oas.ts": [
3728+
"./node_modules/@oclif/command/lib/index.d.ts"
3729+
],
37233730
"./src/commands/intercept.ts": [
37243731
"./node_modules/@oclif/parser/lib/flags.d.ts",
37253732
"./src/lib/proxy-capture-session.ts",
@@ -3742,16 +3749,10 @@
37423749
"./src/lib/proxy-capture-session.ts",
37433750
"./node_modules/@oclif/command/lib/index.d.ts"
37443751
],
3745-
"./src/commands/publish-oas.ts": [
3746-
"./node_modules/@oclif/command/lib/index.d.ts"
3747-
],
37483752
"./src/commands/init.ts": [
37493753
"./node_modules/@oclif/parser/lib/flags.d.ts",
37503754
"./node_modules/@oclif/command/lib/index.d.ts"
37513755
],
3752-
"./src/commands/generate.ts": [
3753-
"./node_modules/@oclif/command/lib/index.d.ts"
3754-
],
37553756
"./node_modules/@types/node/globals.d.ts": [
37563757
"./node_modules/@types/node/util.d.ts",
37573758
"./node_modules/@types/node/ts3.2/util.d.ts"
@@ -5439,10 +5440,6 @@
54395440
"./node_modules/@types/node/util.d.ts",
54405441
"./node_modules/@types/node/ts3.2/util.d.ts"
54415442
],
5442-
"./node_modules/colors/index.d.ts": [
5443-
"./node_modules/@types/node/util.d.ts",
5444-
"./node_modules/@types/node/ts3.2/util.d.ts"
5445-
],
54465443
"./node_modules/keytar/keytar.d.ts": [
54475444
"./node_modules/@types/node/util.d.ts",
54485445
"./node_modules/@types/node/ts3.2/util.d.ts"
@@ -5539,6 +5536,10 @@
55395536
"./node_modules/@types/node/util.d.ts",
55405537
"./node_modules/@types/node/ts3.2/util.d.ts"
55415538
],
5539+
"./node_modules/colors/index.d.ts": [
5540+
"./node_modules/@types/node/util.d.ts",
5541+
"./node_modules/@types/node/ts3.2/util.d.ts"
5542+
],
55425543
"./node_modules/clipboardy/index.d.ts": [
55435544
"./node_modules/@types/node/util.d.ts",
55445545
"./node_modules/@types/node/ts3.2/util.d.ts"
@@ -5757,6 +5758,7 @@
57575758
"./src/index.ts",
57585759
"./src/typescript-overrides.d.ts",
57595760
"./node_modules/clipboardy/index.d.ts",
5761+
"./node_modules/colors/index.d.ts",
57605762
"./node_modules/@oclif/errors/lib/handle.d.ts",
57615763
"./node_modules/@oclif/errors/lib/errors/cli.d.ts",
57625764
"./node_modules/@oclif/errors/lib/errors/exit.d.ts",
@@ -5778,8 +5780,6 @@
57785780
"./node_modules/keytar/keytar.d.ts",
57795781
"./src/lib/credentials.ts",
57805782
"./src/lib/analytics.ts",
5781-
"./src/commands/generate.ts",
5782-
"./node_modules/colors/index.d.ts",
57835783
"./node_modules/open/index.d.ts",
57845784
"./src/commands/init.ts",
57855785
"./node_modules/@types/range-parser/index.d.ts",
@@ -5942,6 +5942,7 @@
59425942
"./node_modules/mockttp/dist/main.d.ts",
59435943
"./node_modules/@types/tmp/index.d.ts",
59445944
"./src/commands/intercept.ts",
5945+
"./src/commands/generate/oas.ts",
59455946
"./src/commands/publish-oas.ts",
59465947
"./node_modules/@types/anymatch/index.d.ts",
59475948
"./node_modules/@types/archy/index.d.ts",

0 commit comments

Comments
 (0)