Skip to content

Commit

Permalink
chore(deps-dev): bumping out of date deps (#777)
Browse files Browse the repository at this point in the history
* chore(deps-dev): bumping out of date deps

* fix: linting problem
  • Loading branch information
erunion authored Jun 30, 2023
1 parent d679111 commit 7ca4f77
Show file tree
Hide file tree
Showing 14 changed files with 736 additions and 619 deletions.
10 changes: 1 addition & 9 deletions __tests__/lib/openapi-to-json-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ describe('general quirks', () => {
it('should repair a malformed object that is typod as an array [README-6R]', () => {
expect(
toJSONSchema({ type: 'array', properties: { type: 'string' } } as {
type: JSONSchema7TypeName;
properties: { type: JSONSchema7Definition };
type: JSONSchema7TypeName;
})
).toStrictEqual({
type: 'object',
Expand Down Expand Up @@ -1207,14 +1207,6 @@ describe('`example` / `examples` support', () => {
});

describe('quirks', () => {
it.skip('should not use an example for a similarly named property', async () => {
const oas = await import('../__datasets__/operation-examples.json').then(r => r.default).then(Oas.init);
await oas.dereference();

// const schema = oas.operation('/similarly-named-type-example', 'post').getParametersAsJSONSchema();
// console.logx(schema?.[0].schema);
});

it('should catch thrown jsonpointer errors', async () => {
const oas = new Oas({
openapi: '3.0.0',
Expand Down
1,216 changes: 670 additions & 546 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@
"oas-normalize": "^8.4.0",
"openapi-types": "^12.1.1",
"path-to-regexp": "^6.2.0",
"remove-undefined-objects": "^2.0.2"
"remove-undefined-objects": "^3.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"@readme/eslint-config": "^10.5.2",
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"@readme/eslint-config": "^10.6.1",
"@readme/oas-examples": "^5.11.1",
"@readme/openapi-parser": "^2.5.0",
"@types/jest": "^29.5.1",
"@types/json-schema-merge-allof": "^0.6.1",
"@types/memoizee": "^0.4.6",
"@types/node": "^20.2.3",
"eslint": "^8.41.0",
"@types/node": "^20.3.3",
"eslint": "^8.44.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"prettier": "@readme/eslint-config/prettier",
"commitlint": {
Expand Down
22 changes: 11 additions & 11 deletions src/analyzer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import * as OPENAPI_QUERIES from './queries/openapi';
import * as README_QUERIES from './queries/readme';

export interface OASAnalysisFeature {
present: boolean;
locations: string[];
present: boolean;
}

export interface OASAnalysisGeneral {
name: string;
found: number | string[];
name: string;
}

export interface OASAnalysis {
Expand All @@ -25,30 +25,30 @@ export interface OASAnalysis {
circularRefs: OASAnalysisFeature;
discriminators: OASAnalysisFeature;
links: OASAnalysisFeature;
style: OASAnalysisFeature;
polymorphism: OASAnalysisFeature;
serverVariables: OASAnalysisFeature;
style: OASAnalysisFeature;
webhooks: OASAnalysisFeature;
xml: OASAnalysisFeature;
};
readme: {
/**
* RAW_BODY is specific to our Manual API editor and we don't recommend anyone writing their
* own API definition should use it so this is considered deprecated.
*/
raw_body?: OASAnalysisFeature;
'x-default': OASAnalysisFeature;
'x-readme.headers': OASAnalysisFeature;
'x-readme.proxy-enabled': OASAnalysisFeature;
'x-readme.samples-languages'?: OASAnalysisFeature;
'x-readme.code-samples': OASAnalysisFeature;
'x-readme.explorer-enabled': OASAnalysisFeature;
'x-readme.headers': OASAnalysisFeature;
'x-readme.proxy-enabled': OASAnalysisFeature;

/**
* This extension is deprecated.
*/
'x-readme.samples-enabled'?: OASAnalysisFeature;

/**
* RAW_BODY is specific to our Manual API editor and we don't recommend anyone writing their
* own API definition should use it so this is considered deprecated.
*/
raw_body?: OASAnalysisFeature;
'x-readme.samples-languages'?: OASAnalysisFeature;
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/analyzer/util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { JSONPath } from 'jsonpath-plus';

interface JSONPathResult {
path: string;
value: any;
hasArrExpr?: boolean;
parent: any;
parentProperty: string;
hasArrExpr?: boolean;
path: string;
pointer: string;
value: any;
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import Operation, { Callback, Webhook } from './operation';
import utils, { supportedMethods } from './utils';

interface PathMatch {
match?: MatchResult;
operation: RMOAS.PathsObject;
url: {
method?: RMOAS.HttpMethods;
nonNormalizedPath: string;
origin: string;
path: string;
nonNormalizedPath: string;
slugs: Record<string, string>;
method?: RMOAS.HttpMethods;
};
operation: RMOAS.PathsObject;
match?: MatchResult;
}
type PathMatches = PathMatch[];

Expand Down Expand Up @@ -210,14 +210,14 @@ function filterPathMethods(pathMatches: PathMatches, targetMethod: RMOAS.HttpMet

return false;
})
.filter(Boolean) as { url: PathMatch['url']; operation: RMOAS.OperationObject }[];
.filter(Boolean) as { operation: RMOAS.OperationObject; url: PathMatch['url'] }[];
}

/**
* @param pathMatches URL and PathsObject matches to narrow down to find a target path.
* @returns An object containing matches that were discovered in the API definition.
*/
function findTargetPath(pathMatches: { url: PathMatch['url']; operation: RMOAS.PathsObject }[]) {
function findTargetPath(pathMatches: { operation: RMOAS.PathsObject; url: PathMatch['url'] }[]) {
let minCount = Object.keys(pathMatches[0].url.slugs).length;
let operation;

Expand Down Expand Up @@ -250,18 +250,18 @@ export default class Oas {
* end up returning the same data set once the initial dereference call completed.
*/
protected promises: {
resolve: any;
reject: any;
resolve: any;
}[];

/**
* Internal storage array that the library utilizes to keep track of its `dereferencing` state so
* it doesn't initiate multiple dereferencing processes.
*/
protected dereferencing: {
processing: boolean;
complete: boolean;
circularRefs: string[];
complete: boolean;
processing: boolean;
};

/**
Expand Down Expand Up @@ -604,8 +604,8 @@ export default class Oas {
}

const matches = filterPathMethods(annotatedPaths, method) as {
url: PathMatch['url'];
operation: RMOAS.PathsObject; // @fixme this should actually be an `OperationObject`.
operation: RMOAS.PathsObject;
url: PathMatch['url']; // @fixme this should actually be an `OperationObject`.
}[];
if (!matches.length) return undefined;
return findTargetPath(matches);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as RMOAS from '../rmoas.types';
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';

type authKey = null | unknown | { user: string | number; password: string | number };
type authKey = null | unknown | { password: string | number; user: string | number };

/**
* @param user User to retrieve retrieve an auth key for.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-mediatype-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import sampleFromSchema from '../samples';
import matchesMimeType from './matches-mimetype';

export interface MediaTypeExample {
description?: string;
summary?: string;
title?: string;
description?: string;
value: unknown;
}

Expand Down
4 changes: 2 additions & 2 deletions src/operation/get-callback-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type * as RMOAS from '../rmoas.types';
import getResponseExamples from './get-response-examples';

export type CallbackExamples = {
identifier: string;
example: unknown;
expression: string;
identifier: string;
method: string;
example: unknown;
}[];

/**
Expand Down
18 changes: 9 additions & 9 deletions src/operation/get-parameters-as-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-sch

export interface SchemaWrapper {
$schema?: string;
type: string;
deprecatedProps?: SchemaWrapper;
description?: string;
label?: string;
schema: SchemaObject;
description?: string;
deprecatedProps?: SchemaWrapper;
type: string;
}

/**
Expand All @@ -39,12 +39,6 @@ export interface getParametersAsJSONSchemaOptions {
*/
globalDefaults?: Record<string, unknown>;

/**
* If you wish to include discriminator mapping `$ref` components alongside your
* `discriminator` in schemas. Defaults to `true`.
*/
includeDiscriminatorMappingRefs?: boolean;

/**
* If you wish to hide properties that are marked as being `readOnly`.
*/
Expand All @@ -55,6 +49,12 @@ export interface getParametersAsJSONSchemaOptions {
*/
hideWriteOnlyProperties?: boolean;

/**
* If you wish to include discriminator mapping `$ref` components alongside your
* `discriminator` in schemas. Defaults to `true`.
*/
includeDiscriminatorMappingRefs?: boolean;

/**
* If you want the output to be two objects: body (contains `body` and `formData` JSON
* Schema) and metadata (contains `path`, `query`, `cookie`, and `header`).
Expand Down
2 changes: 1 addition & 1 deletion src/operation/get-requestbody-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type * as RMOAS from '../rmoas.types';
import getMediaTypeExamples from '../lib/get-mediatype-examples';

export type RequestBodyExamples = {
mediaType: string;
examples: any;
mediaType: string;
}[];

/**
Expand Down
10 changes: 5 additions & 5 deletions src/operation/get-response-as-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function buildHeadersSchema(
});

const headersWrapper: {
description?: string;
label: string;
schema: SchemaObject;
type: string;
label: string;
description?: string;
} = {
schema: headersSchema,
type: 'object',
Expand Down Expand Up @@ -158,10 +158,10 @@ export default function getResponseAsJSONSchema(
if (foundSchema) {
const schema = cloneObject(foundSchema);
const schemaWrapper: {
type: string | string[];
schema: SchemaObject;
label: string;
description?: string;
label: string;
schema: SchemaObject;
type: string | string[];
} = {
// If there's no `type` then the root schema is a circular `$ref` that we likely won't be
// able to render so instead of generating a JSON Schema with an `undefined` type we should
Expand Down
2 changes: 1 addition & 1 deletion src/operation/get-response-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import getMediaTypeExamples from '../lib/get-mediatype-examples';
import { isRef } from '../rmoas.types';

export type ResponseExamples = {
status: string;
mediaTypes: Record<string, RMOAS.MediaTypeObject>;
status: string;
}[];

/**
Expand Down
23 changes: 12 additions & 11 deletions src/rmoas.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export function isOAS31(check: OpenAPIV3.Document | OpenAPIV3_1.Document): check
export interface User {
[key: string]: unknown;
keys?: {
[key: string]: unknown;
name: string | number;
user?: string | number;
pass?: string | number;
[key: string]: unknown;
user?: string | number;
}[];
}

Expand Down Expand Up @@ -154,23 +154,24 @@ export type SchemaObject = (
) & {
// TODO: We should split this into one type for v3 and one type for v3.1 to ensure type accuracy.
$schema?: string;

// We add this to the schema to help out with circular refs
components?: OpenAPIV3_1.ComponentsObject;

deprecated?: boolean;
readOnly?: boolean;
writeOnly?: boolean;
example?: unknown;
examples?: unknown[];
nullable?: boolean;

// OpenAPI-specific properties
xml?: unknown;
externalDocs?: unknown;

// We add this to the schema to help out with circular refs
components?: OpenAPIV3_1.ComponentsObject;
readOnly?: boolean;
writeOnly?: boolean;

// We add this extension within our dereferencing work to preserve the origin dereferenced
// schemas.
'x-readme-ref-name'?: string;
} & {
// OpenAPI-specific properties
externalDocs?: unknown;
xml?: unknown;
};

/**
Expand Down

0 comments on commit 7ca4f77

Please sign in to comment.