Skip to content

Commit

Permalink
Implement test add --auto
Browse files Browse the repository at this point in the history
  • Loading branch information
anttiviljami committed Oct 15, 2023
1 parent 43f0111 commit f93ea34
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 154 deletions.
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@types/debug": "^4.1.7",
"@types/jest": "^29.5.1",
"@types/jest-json-schema": "^6.1.2",
"@types/js-yaml": "^4.0.7",
"@types/koa": "^2.13.5",
"@types/koa-bodyparser": "^4.3.10",
"@types/koa-logger": "^3.1.2",
Expand Down Expand Up @@ -110,4 +111,4 @@
"version": "oclif-dev readme && git add README.md"
},
"types": "lib/index.d.ts"
}
}
6 changes: 3 additions & 3 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as YAML from 'js-yaml';
import { parseDefinition, resolveDefinition } from '../common/definition';
import { CONFIG_FILENAME, resolveConfigFile } from '../common/config';
import { CONFIG_FILENAME, Config, resolveConfigFile } from '../common/config';
import { createSecurityRequestConfigForScheme, getActiveSecuritySchemes, SecurityConfig } from '../common/security';

Check warning on line 9 in src/commands/auth.ts

View workflow job for this annotation

GitHub Actions / Test

'SecurityConfig' is defined but never used
import { OpenAPIV3 } from 'openapi-client-axios';

Expand Down Expand Up @@ -62,11 +62,11 @@ export class Auth extends Command {
const writeTo = path.resolve(configFile || `./${CONFIG_FILENAME}`);

// write to config file
const oldConfig = configFile ? YAML.load(fs.readFileSync(configFile)) : {};
const oldConfig: Config = configFile ? YAML.load(fs.readFileSync(configFile).toString()) : {};
const newConfig = {
...oldConfig,
definition,
security: { ...oldConfig.security } as SecurityConfig,
security: { ...oldConfig.security },
};

// choose security schemes
Expand Down
6 changes: 4 additions & 2 deletions src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ export class Call extends Command {

for (const p of operation.parameters || []) {
const param = p as OpenAPIV3.ParameterObject;
const { name, required, example } = param;
const { name, required, example, schema } = param;

if (!params[name] && required) {
const value = await maybeSimplePrompt(name, { required, default: example });
const mockedValue = schema ? mock(schema as OpenAPIV3.SchemaObject) : undefined;

const value = await maybeSimplePrompt(name, { required, default: example ?? mockedValue });
params[name] = value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from '@oclif/test';
import * as fs from 'fs';
import * as YAML from 'js-yaml';
import 'chai';
import { CONFIG_FILENAME } from '../common/config';
import { CONFIG_FILENAME, Config } from '../common/config';
import { resourcePath, testDefinition } from '../__tests__/test-utils';

const COMMAND = 'load';
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('load', () => {
.stdout()
.command([COMMAND, resourcePath('openapi.yml')])
.it(`writes the definition path to the ${CONFIG_FILENAME} file`, (_ctx) => {
const config = YAML.load(fs.readFileSync(CONFIG_FILENAME));
const config: Config = YAML.load(fs.readFileSync(CONFIG_FILENAME).toString());
expect(config.definition).to.match(new RegExp('openapi.yml'));
});
});
9 changes: 2 additions & 7 deletions src/commands/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as YAML from 'js-yaml';
import { parseDefinition } from '../common/definition';
import { CONFIG_FILENAME, resolveConfigFile } from '../common/config';
import { CONFIG_FILENAME, Config, resolveConfigFile } from '../common/config';

export class Load extends Command {
public static description = 'Set the default definition file for a workspace (writes to .openapiconfig)';
Expand Down Expand Up @@ -42,17 +42,12 @@ export class Load extends Command {
const configFile = resolveConfigFile();

// write to config file
const oldConfig = configFile ? YAML.load(fs.readFileSync(configFile)) : {};
const oldConfig: Config = configFile ? YAML.load(fs.readFileSync(configFile).toString()) : {};
const newConfig = {
...oldConfig,
definition,
};

// add server to config
if (flags.server) {
newConfig.server = flags.server[0];
}

// default to current directory
const writeTo = path.resolve(configFile || `./${CONFIG_FILENAME}`);

Expand Down
Loading

0 comments on commit f93ea34

Please sign in to comment.