Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add user-agent field #782

Merged
merged 5 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/commands/split/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function iteratePathItems(
const pathData = pathItems[pathName] as Oas3PathItem;

if (isRef(pathData)) continue;

for (const method of OPENAPI3_METHOD_NAMES) {
const methodData = pathData[method];
const methodDataXCode = methodData?.['x-code-samples'] || methodData?.['x-codeSamples'];
Expand Down
34 changes: 24 additions & 10 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ yargs
default: 'stylish' as OutputFormat,
},
}),
handleStats
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'stats';
handleStats(argv);
}
)
.command(
'split [entrypoint]',
Expand All @@ -54,7 +57,10 @@ yargs
},
})
.demandOption('entrypoint'),
handleSplit
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'split';
handleSplit(argv);
}
)
.command(
'join [entrypoints...]',
Expand Down Expand Up @@ -89,6 +95,7 @@ yargs
},
}),
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'join';
handleJoin(argv, version);
}
)
Expand Down Expand Up @@ -127,7 +134,10 @@ yargs
})
.implies('batch-id', 'batch-size')
.implies('batch-size', 'batch-id'),
transformPush(handlePush)
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'push';
transformPush(handlePush)(argv);
}
)
.command(
'lint [entrypoints...]',
Expand Down Expand Up @@ -167,11 +177,7 @@ yargs
},
'lint-config': {
description: 'Apply severity for linting the config file.',
choices: [
'warn',
'error',
'off',
] as ReadonlyArray<RuleSeverity>,
choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
default: 'warn' as RuleSeverity,
},
config: {
Expand All @@ -187,6 +193,7 @@ yargs
},
}),
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'lint';
handleLint(argv, version);
}
)
Expand Down Expand Up @@ -281,13 +288,17 @@ yargs
choices: regionChoices,
},
}),
handleLogin
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'login';
handleLogin(argv);
}
)
.command(
'logout',
'Clear your stored credentials for the Redocly API registry.',
(yargs) => yargs,
async () => {
process.env.REDOCLY_CLI_COMMAND = 'logout';
const client = new RedoclyClient();
client.logout();
process.stdout.write('Logged out from the Redocly account. ✋\n');
Expand Down Expand Up @@ -334,7 +345,10 @@ yargs
type: 'string',
},
}),
previewDocs
(argv) => {
process.env.REDOCLY_CLI_COMMAND = 'preview-docs';
previewDocs(argv);
}
)
.completion('completion', 'Generate completion script.')
.demandCommand(1)
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/redocly/registry-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { DEFAULT_REGION, DOMAINS } from '../config/config';
import { isNotEmptyObject } from '../utils';
const version = require('../../package.json').version;

export const currentCommand = typeof process !== 'undefined' ? process.env?.REDOCLY_CLI_COMMAND || '' : '';
tatomyr marked this conversation as resolved.
Show resolved Hide resolved

import type { AccessTokens, Region } from '../config/types';

export class RegistryApi {
Expand All @@ -23,7 +25,10 @@ export class RegistryApi {
}

private async request(path = '', options: RequestInit = {}, region?: Region) {
const headers = Object.assign({}, options.headers || {}, { 'x-redocly-cli-version': version });
const headers = Object.assign({}, options.headers || {}, {
'x-redocly-cli-version': version,
tatomyr marked this conversation as resolved.
Show resolved Hide resolved
'user-agent': `redocly-cli / ${version} ${currentCommand}`
});

if (!headers.hasOwnProperty('authorization')) {
throw new Error('Unauthorized');
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/rules/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ajv, { ValidateFunction, ErrorObject } from '@redocly/ajv';
import Ajv, { ValidateFunction, ErrorObject } from '@redocly/ajv/dist/2019';
RomanHotsiy marked this conversation as resolved.
Show resolved Hide resolved
import { Location, escapePointer } from '../ref-utils';
import { ResolveFn } from '../walk';

Expand Down
5 changes: 5 additions & 0 deletions resources/pets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ paths:
requestBody:
content:
application/json:
example:
{
"orderId": 3,
"test": 3
}
RomanHotsiy marked this conversation as resolved.
Show resolved Hide resolved
schema:
type: object
properties:
Expand Down