Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,565 changes: 1,638 additions & 927 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api/src/codegen/codegenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default abstract class CodeGenerator {
requiredPackages!: Record<
string,
{
dependencyType: 'production' | 'development';
dependencyType: 'development' | 'production';
reason: string;
url?: string;
version: string;
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/codegen/languages/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { docblockEscape, generateTypeName, wordWrap } from './util.js';
interface OperationTypeHousing {
operation: Operation;
types: {
params?: false | Record<'body' | 'formData' | 'metadata', string>;
params?: Record<'body' | 'formData' | 'metadata', string> | false;
responses?: Record<
string | number,
number | string,
{
description?: string;
type: string;
Expand Down Expand Up @@ -89,6 +89,7 @@ export default class TSGenerator extends CodeGenerator {
schemas: Record<
string,
// Operation-level type
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
| {
body?: unknown;
metadata?: unknown;
Expand Down Expand Up @@ -1090,7 +1091,7 @@ Generated at ${createdAt}
.reduce((prev, next) => Object.assign(prev, next));

return Object.entries(res)
.map(([paramType, schema]: [string, string | SchemaObject]) => {
.map(([paramType, schema]: [string, SchemaObject | string]) => {
let typeName;

if (typeof schema === 'string' && schema.startsWith(REF_PLACEHOLDER)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import OpenAPIParser from '@readme/openapi-parser';
import yaml from 'js-yaml';

export default class Fetcher {
uri: string | OASDocument;
uri: OASDocument | string;

/**
* @note This regex also exists in `httpsnippet-client-api`.
Expand All @@ -17,7 +17,7 @@ export default class Fetcher {
*/
static registryUUIDRegex = /^@(?<project>[a-zA-Z0-9-_]+)(\/?(?<version>.+))?#(?<uuid>[a-z0-9]+)$/;

constructor(uri: string | OASDocument) {
constructor(uri: OASDocument | string) {
if (typeof uri === 'string') {
if (Fetcher.isAPIRegistryUUID(uri)) {
// Resolve OpenAPI definition shorthand accessors from within the ReadMe API Registry.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PACKAGE_VERSION } from './packageInfo.js';
export default class Storage {
static dir: string;

static lockfile: false | Lockfile;
static lockfile: Lockfile | false;

fetcher: Fetcher;

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export default class APICore {
| false
| {
url: string;
variables?: Record<string, string | number>;
variables?: Record<string, number | string>;
} = false;

private config: ConfigOptions = {};

private userAgent!: string;

constructor(definition?: Record<string, unknown> | OASDocument, userAgent?: string) {
constructor(definition?: OASDocument | Record<string, unknown>, userAgent?: string) {
if (definition) this.spec = Oas.init(definition);
if (userAgent) this.userAgent = userAgent;
}
Expand All @@ -46,12 +46,12 @@ export default class APICore {
return this;
}

setAuth(...values: string[] | number[]) {
setAuth(...values: number[] | string[]) {
this.auth = values;
return this;
}

setServer(url: string, variables: Record<string, string | number> = {}) {
setServer(url: string, variables: Record<string, number | string> = {}) {
this.server = { url, variables };
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/getJSONSchemaDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function getJSONSchemaDefaults(jsonSchemas: SchemaWrapper[]) {
parentPointer?: string,
parentKeyword?: string,
parentSchema?: SchemaObject,
indexProperty?: string | number,
indexProperty?: number | string,
) => {
if (!pointer.startsWith('/properties/')) {
return;
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/lib/prepareParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function merge(src: unknown, target: unknown) {
*/
function processFile(
paramName: string | undefined,
file: string | ReadStream,
file: ReadStream | string,
): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> {
if (typeof file === 'string') {
// In order to support relative pathed files, we need to attempt to resolve them.
Expand Down Expand Up @@ -192,16 +192,16 @@ export default async function prepareParams(operation: Operation, body?: unknown
const params: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body?: any;
cookie?: Record<string, string | number | boolean>;
cookie?: Record<string, boolean | number | string>;
files?: Record<string, Buffer>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
formData?: any;
header?: Record<string, string | number | boolean>;
path?: Record<string, string | number | boolean>;
query?: Record<string, string | number | boolean>;
header?: Record<string, boolean | number | string>;
path?: Record<string, boolean | number | string>;
query?: Record<string, boolean | number | string>;
server?: {
selected: number;
variables: Record<string, string | number>;
variables: Record<string, number | string>;
};
} = jsonSchemaDefaults;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/prepareServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function stripTrailingSlash(url: string) {
* any server variables to be supplied to `@readme/oas-to-har`.
*
*/
export default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {
export default function prepareServer(spec: Oas, url: string, variables: Record<string, number | string> = {}) {
let serverIdx: number | undefined;
const sanitizedUrl = stripTrailingSlash(url);
(spec.api.servers || []).forEach((server, i) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/httpsnippet-client-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function stringify(obj: any, opts = {}) {
return stringifyObject(obj, { indent: ' ', ...opts });
}

function buildAuthSnippet(sdkVariable: string, authKey: string | string[]) {
function buildAuthSnippet(sdkVariable: string, authKey: string[] | string) {
// Auth key will be an array for Basic auth cases.
if (Array.isArray(authKey)) {
const auth: string[] = [];
Expand Down Expand Up @@ -195,7 +195,7 @@ const client: Client<APIOptions> = {
}
}

let metadata: Record<string, string | string[]> = {};
let metadata: Record<string, string[] | string> = {};
Object.keys(queryObj).forEach(param => {
if (authSources.query.includes(param)) {
authData.push(buildAuthSnippet(sdkVariable, queryObj[param]));
Expand Down
4 changes: 2 additions & 2 deletions packages/httpsnippet-client-api/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('httpsnippet-client-api', () => {
},
});

expect(code).toStrictEqual(`import developers from '@api/developers';
expect(code).toBe(`import developers from '@api/developers';

developers.auth('123');
developers.findPetsByStatus({status: 'available', accept: 'application/xml'})
Expand All @@ -165,7 +165,7 @@ developers.findPetsByStatus({status: 'available', accept: 'application/xml'})
},
});

expect(code).toStrictEqual(`import metroTransit from '@api/metro-transit';
expect(code).toBe(`import metroTransit from '@api/metro-transit';

metroTransit.auth('123');
metroTransit.findPetsByStatus({status: 'available', accept: 'application/xml'})
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/fetch-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const responses = {
};
},

delay: (res: string | Record<string, unknown>, delay: number) => {
delay: (res: Record<string, unknown> | string, delay: number) => {
return new Promise(resolve => {
setTimeout(() => resolve(res), delay);
});
Expand All @@ -54,7 +54,7 @@ export const responses = {
};
},

real: (res: string | Record<string, unknown>) => {
real: (res: Record<string, unknown> | string) => {
return () => res;
},

Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/vitest.matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface CustomMatchers<R = unknown> {
* expect(request.headers).to.have.header('connection', ['close', 'keep-alive']);
*
*/
toHaveHeader(header: string, expected: RegExp | (string | number)[] | string): R;
toHaveHeader(header: string, expected: (number | string)[] | RegExp | string): R;
}

declare module 'vitest' {
Expand All @@ -47,7 +47,7 @@ expect.extend({
};
},

toHaveHeader(obj: Headers, header: string, expected: RegExp | (string | number)[] | string) {
toHaveHeader(obj: Headers, header: string, expected: (number | string)[] | RegExp | string) {
// @ts-expect-error `Headers.entries()` exists despite what the types here suggest.
const headers = caseless(Object.fromEntries(Array.from(obj.entries())));

Expand Down