Skip to content

Commit ec3099c

Browse files
eruniondarrenyongmaximilianfalco
authored
feat(oas): v30 release (#1053)
## 🐳 Context Because we are experience some pretty serious performance issues with large API definitions post-dereferencing we are adding general support for handling `$ref` pointers into `oas`, without requiring the need for a full dereference. > [!IMPORTANT] > This is a major breaking change to `oas`. Because `oas` has long assumed that the OpenAPI definition it contained was dereferenced this is a huge shift in departure so I expect there to be issues, and as such will be releasing this in v30 RCs until it's stable. ## 📚 Accompanied work * [x] #1052 * [x] #1051 * [x] #1054 * [x] #1055 ## 🧠 Breaking changes * [x] Enforced TS strict mode everywhere. Some function return types have changed as a result of this but only to enforce what these methods were already returning. #### `oas` * [x] Improved support for `$ref` pointers on the following accessors: * `.getAuth()` * `.getPaths()` * `.getWebhooks()` #### `oas/operation` * [x] `.dereference()`. This is a new alternative to `Oas.dereference()` and allows you to dereference a single operation, rather than needing to dereference the **entire** API definition. * [x] `.getCallbacks()` now always returns an array. Previously if the operation had no callbacks it would return `false`, however that existence check is better suited for `Operation.hasCallbacks()`. #### `oas/types` * [x] `isOAS30` has been removed, please use `isOpenAPI30` instead. * [x] `isOAS31` has been removed, please use `isOpenAPI31` instead. #### `oas/utils` * [ ] `findSchemaDefinition` is no longer exported. If you need to dereference a `$ref` pointer we suggest you either invoke `Oas.dereference()` to dereference your entire API definition, use the new `Operation.dereference()` feature in this release for dereferencing a single API operation, or use a library like [@apidevtools/json-schema-ref-parser](https://npm.im/@apidevtools/json-schema-ref-parser) for dereferencing. ## 🧬 QA & Testing I've written a good amount of new tests for these changes but the real Q&A will have to be done within our internal repository, and I expect this work as-is to contain issues so I'll be tagging RC's until it's fully ready for the general public. [^1]: Unless explicitly specified otherwise, `$ref` pointers that cannot be resolved, either because they are invalid or circular, will be ignored. --------- Co-authored-by: Darren Yong <contact.darrenyong@gmail.com> Co-authored-by: Maximilian Falco Widjaya <maximilianfalco@gmail.com> Co-authored-by: Darren Yong <41130056+darrenyong@users.noreply.github.com>
1 parent 636f0e2 commit ec3099c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2789
-2058
lines changed

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/oas-to-har/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export default function oasToHar(
421421

422422
let requestBody: SchemaWrapper | undefined;
423423
if (operation.hasRequestBody()) {
424-
requestBody = operation.getParametersAsJSONSchema().find(payload => {
424+
requestBody = operation.getParametersAsJSONSchema()?.find(payload => {
425425
// `formData` is used in our API Explorer for `application/x-www-form-urlencoded` endpoints
426426
// and if you have an operation with that, it will only ever have a `formData`. `body` is
427427
// used for all other payload shapes.

packages/oas/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"watch": "tsc --watch"
8888
},
8989
"dependencies": {
90+
"@apidevtools/json-schema-ref-parser": "^14.1.1",
9091
"@readme/openapi-parser": "file:../parser",
9192
"@types/json-schema": "^7.0.11",
9293
"json-schema-merge-allof": "^0.8.1",

packages/oas/src/extensions.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -221,37 +221,39 @@ export const SIMPLE_MODE = 'simple-mode';
221221
export const DISABLE_TAG_SORTING = 'disable-tag-sorting';
222222

223223
export interface Extensions {
224-
[CODE_SAMPLES]: {
225-
/**
226-
* Custom code snippet
227-
* @example "curl -X POST https://api.example.com/v2/alert"
228-
*/
229-
code: string;
230-
/**
231-
* Corresponding response example
232-
* @see {@link https://docs.readme.com/main/docs/openapi-extensions#corresponding-response-examples}
233-
*/
234-
correspondingExample?: string;
235-
/**
236-
* Library installation instructions
237-
* @example "brew install httpie"
238-
* @example "npm install node-fetch@2 --save"
239-
*/
240-
install?: string;
241-
/**
242-
* Language for syntax highlighting
243-
* @example shell
244-
*/
245-
language: string;
246-
/**
247-
* Optional title for code sample
248-
* @example "Custom cURL snippet"
249-
*/
250-
name?: string;
251-
}[];
224+
[CODE_SAMPLES]:
225+
| {
226+
/**
227+
* Custom code snippet
228+
* @example "curl -X POST https://api.example.com/v2/alert"
229+
*/
230+
code: string;
231+
/**
232+
* Corresponding response example
233+
* @see {@link https://docs.readme.com/main/docs/openapi-extensions#corresponding-response-examples}
234+
*/
235+
correspondingExample?: string;
236+
/**
237+
* Library installation instructions
238+
* @example "brew install httpie"
239+
* @example "npm install node-fetch@2 --save"
240+
*/
241+
install?: string;
242+
/**
243+
* Language for syntax highlighting
244+
* @example shell
245+
*/
246+
language: string;
247+
/**
248+
* Optional title for code sample
249+
* @example "Custom cURL snippet"
250+
*/
251+
name?: string;
252+
}[]
253+
| undefined;
252254
[DISABLE_TAG_SORTING]: boolean;
253255
[EXPLORER_ENABLED]: boolean;
254-
[HEADERS]: Record<string, number | string>[];
256+
[HEADERS]: Record<string, number | string>[] | undefined;
255257
[INTERNAL]: boolean;
256258
[METRICS_ENABLED]: boolean;
257259
[OAUTH_OPTIONS]: {
@@ -377,6 +379,10 @@ export function validateParameterOrdering(
377379
ordering: (typeof extensionDefaults)[typeof PARAMETER_ORDERING] | undefined,
378380
extension: string,
379381
): void {
382+
if (!ordering) {
383+
return;
384+
}
385+
380386
const defaultValue = extensionDefaults[PARAMETER_ORDERING];
381387
const requiredLength = defaultValue.length;
382388
const defaultsHuman = `${defaultValue.slice(0, -1).join(', ')}, and ${defaultValue.slice(-1)}`;

0 commit comments

Comments
 (0)