Skip to content

Commit

Permalink
Merge branch 'next' into docs-sync-test-RM-4904
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Nov 27, 2023
2 parents d2529bb + 49fd1bd commit 2082eff
Show file tree
Hide file tree
Showing 28 changed files with 1,894 additions and 1,198 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
}
]
}
]
],

// This rule is only really applicable for OSS libraries and doesn't apply to rdme's case.
"readme/no-dual-exports": "off"
}
}
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ updates:
labels:
- dependencies
groups:
minor-developent-deps:
minor-development-deps:
dependency-type: 'development'
update-types:
- minor
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
token: ${{ secrets.RELEASE_GH_TOKEN }}

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [9.0.0-next.7](https://github.com/readmeio/rdme/compare/v9.0.0-next.6...v9.0.0-next.7) (2023-11-21)


### Features

* **openapi/convert:** support openapi in convert command ([#941](https://github.com/readmeio/rdme/issues/941)) ([a33bbeb](https://github.com/readmeio/rdme/commit/a33bbeb1155095f20b01cda18f2c32e9c001b428))

# [9.0.0-next.6](https://github.com/readmeio/rdme/compare/v9.0.0-next.5...v9.0.0-next.6) (2023-09-26)


Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!-- prettier-ignore-start -->
> [!WARNING]
> **These docs are for [the forthcoming `v9` release](https://github.com/readmeio/rdme/issues/801).** You can view the docs for the current release (`v8`) [here](https://github.com/readmeio/rdme/tree/v8#readme).
<!-- prettier-ignore-end -->
[![rdme](https://user-images.githubusercontent.com/8854718/195465739-0f0f83d5-2e18-4e6c-96ae-944e3bb6880a.png)](https://readme.com)

<p align="center">
Expand Down
9 changes: 6 additions & 3 deletions __tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Options
Related commands
$ rdme openapi:convert Convert a Swagger or Postman Collection to OpenAPI.
$ rdme openapi:convert Convert an API definition to OpenAPI and bundle any
external references.
$ rdme openapi:inspect Analyze an OpenAPI/Swagger definition for various
OpenAPI and ReadMe feature usage.
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
Expand Down Expand Up @@ -86,7 +87,8 @@ Options
Related commands
$ rdme openapi:convert Convert a Swagger or Postman Collection to OpenAPI.
$ rdme openapi:convert Convert an API definition to OpenAPI and bundle any
external references.
$ rdme openapi:inspect Analyze an OpenAPI/Swagger definition for various
OpenAPI and ReadMe feature usage.
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
Expand Down Expand Up @@ -133,7 +135,8 @@ Options
Related commands
$ rdme openapi:convert Convert a Swagger or Postman Collection to OpenAPI.
$ rdme openapi:convert Convert an API definition to OpenAPI and bundle any
external references.
$ rdme openapi:inspect Analyze an OpenAPI/Swagger definition for various
OpenAPI and ReadMe feature usage.
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
Expand Down
38 changes: 35 additions & 3 deletions __tests__/cmds/openapi/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import OpenAPIConvertCommand from '../../../src/cmds/openapi/convert.js';

const convert = new OpenAPIConvertCommand();

const successfulConversion = () => 'Your converted API definition has been saved to output.json!';
const successfulConversion = () => 'Your API definition has been converted and bundled and saved to output.json!';

describe('rdme openapi:convert', () => {
describe('converting', () => {
Expand Down Expand Up @@ -41,13 +41,45 @@ describe('rdme openapi:convert', () => {
it.each([['json'], ['yaml']])('should fail if given an OpenAPI 3.0 definition (format: %s)', async format => {
const spec = require.resolve(`@readme/oas-examples/3.0/${format}/petstore.${format}`);

const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});

let reducedSpec;
fs.writeFileSync = vi.fn((fileName, data) => {
reducedSpec = JSON.parse(data as string);
});

prompts.inject(['output.json']);

await expect(
convert.run({
spec,
}),
).rejects.toStrictEqual(
new Error("Sorry, this API definition is already an OpenAPI definition and doesn't need to be converted."),
).resolves.toBe(successfulConversion());

expect(fs.writeFileSync).toHaveBeenCalledWith('output.json', expect.any(String));
expect(reducedSpec.tags).toHaveLength(3);
expect(Object.keys(reducedSpec.paths)).toStrictEqual([
'/pet',
'/pet/findByStatus',
'/pet/findByTags',
'/pet/{petId}',
'/pet/{petId}/uploadImage',
'/store/inventory',
'/store/order',
'/store/order/{orderId}',
'/user',
'/user/createWithArray',
'/user/createWithList',
'/user/login',
'/user/logout',
'/user/{username}',
]);
expect(Object.keys(reducedSpec.paths['/pet/{petId}'])).toStrictEqual(['get', 'post', 'delete']);
expect(consoleWarnSpy).toHaveBeenCalledWith(
'⚠️ Warning! The input file is already OpenAPI, so no conversion is necessary. Any external references will be bundled.',
);

consoleWarnSpy.mockRestore();
});
});
});
28 changes: 14 additions & 14 deletions __tests__/cmds/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'node:fs';

import chalk from 'chalk';
import { rest } from 'msw';
import { http } from 'msw';
import { setupServer } from 'msw/node';
import nock from 'nock';
import prompts from 'prompts';
Expand Down Expand Up @@ -1361,23 +1361,23 @@ describe('rdme openapi', () => {

server.use(
...[
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID }));
return Response.json({ registryUUID }, { status: 201 });
}),
rest.get(spec, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(petstoreWeird));
http.get(spec, () => {
return Response.json(petstoreWeird, { status: 200 });
}),
rest.put(`${config.host}/api/v1/api-specification/${id}`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(req.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(req.headers.get('x-readme-source')).toBe('cli-gh');
expect(req.headers.get('x-readme-source-url')).toBe(spec);
expect(req.headers.get('x-readme-version')).toBe(version);
const body = await req.json();
http.put(`${config.host}/api/v1/api-specification/${id}`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(request.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(request.headers.get('x-readme-source')).toBe('cli-gh');
expect(request.headers.get('x-readme-source-url')).toBe(spec);
expect(request.headers.get('x-readme-version')).toBe(version);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down
15 changes: 7 additions & 8 deletions __tests__/helpers/get-api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ResponseTransformer } from 'msw';
import type { Headers } from 'node-fetch';

import { rest } from 'msw';
import { http } from 'msw';
import nock from 'nock';

import config from '../../src/lib/config.js';
Expand Down Expand Up @@ -76,17 +75,17 @@ export function getAPIMockMSW(
expectedReqHeaders: ReqHeaders = {},
proxy = '',
) {
return rest.get(`${proxy}${config.host}${path}`, (req, res, ctx) => {
return http.get(`${proxy}${config.host}${path}`, ({ request }) => {
try {
// @ts-expect-error once we move off node-fetch, we can make these types consistent
validateHeaders(req.headers, basicAuthUser, expectedReqHeaders);
let responseTransformer: ResponseTransformer;
validateHeaders(request.headers, basicAuthUser, expectedReqHeaders);
let httpResponse = new Response(null, { status });
if (response?.json) {
responseTransformer = ctx.json(response.json);
httpResponse = Response.json(response.json, { status });
} else if (response?.text) {
responseTransformer = ctx.text(response.text);
httpResponse = new Response(response.text, { status });
}
return res(ctx.status(status), responseTransformer);
return httpResponse;
} catch (e) {
throw new Error(`Error mocking GET request to https://dash.readme.com${path}: ${e.message}`);
}
Expand Down
75 changes: 6 additions & 69 deletions __tests__/helpers/github-workflow-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"type": "string"
},
"needs": { "$ref": "#/definitions/jobNeeds" },
"permissions": { "$ref": "#/definitions/permissions-event" },
"permissions": { "$ref": "#/definitions/permissions" },
"if": {
"$comment": "https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idif",
"description": "You can use the if conditional to prevent a job from running unless a condition is met. You can use any supported context and expression to create a conditional.\nExpressions in an if conditional do not require the ${{ }} syntax. For more information, see https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions.",
Expand Down Expand Up @@ -363,79 +363,15 @@
"runs-on": {
"$comment": "https://help.github.com/en/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on",
"description": "The type of machine to run the job on. The machine can be either a GitHub-hosted runner, or a self-hosted runner.",
"oneOf": [
"anyOf": [
{
"$comment": "https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#github-hosted-runners",
"type": "string",
"enum": [
"macos-10.15",
"macos-11",
"macos-12",
"macos-12-xl",
"macos-13",
"macos-13-xl",
"macos-latest",
"macos-latest-xl",
"self-hosted",
"ubuntu-18.04",
"ubuntu-20.04",
"ubuntu-22.04",
"ubuntu-latest",
"ubuntu-latest-4-cores",
"ubuntu-latest-8-cores",
"ubuntu-latest-16-cores",
"windows-2019",
"windows-2022",
"windows-latest",
"windows-latest-8-cores"
]
"type": "string"
},
{
"$comment": "https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#self-hosted-runners",
"type": "array",
"anyOf": [
{ "items": [{ "const": "self-hosted" }], "minItems": 1, "additionalItems": { "type": "string" } },
{
"items": [{ "const": "self-hosted" }, { "$ref": "#/definitions/machine" }],
"minItems": 2,
"additionalItems": { "type": "string" }
},
{
"items": [{ "const": "self-hosted" }, { "$ref": "#/definitions/architecture" }],
"minItems": 2,
"additionalItems": { "type": "string" }
},
{
"items": [
{ "const": "self-hosted" },
{ "$ref": "#/definitions/machine" },
{ "$ref": "#/definitions/architecture" }
],
"minItems": 3,
"additionalItems": { "type": "string" }
},
{
"items": [
{ "const": "self-hosted" },
{ "$ref": "#/definitions/architecture" },
{ "$ref": "#/definitions/machine" }
],
"minItems": 3,
"additionalItems": { "type": "string" }
},
{
"items": [{ "const": "linux" }],
"minItems": 2,
"maxItems": 2,
"additionalItems": { "type": "string" }
},
{
"items": [{ "const": "windows" }],
"minItems": 2,
"maxItems": 2,
"additionalItems": { "type": "string" }
}
]
"anyOf": [{ "items": [{ "type": "string" }], "minItems": 1 }]
},
{
"$comment": "https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-runners-in-a-group",
Expand All @@ -445,7 +381,8 @@
"labels": { "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] }
}
},
{ "$ref": "#/definitions/stringContainingExpressionSyntax" }
{ "$ref": "#/definitions/stringContainingExpressionSyntax" },
{ "$ref": "#/definitions/expressionSyntax" }
]
},
"environment": {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/__snapshots__/commands.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports[`utils > #listByCategory > should list commands by category 1`] = `
"name": "openapi",
},
{
"description": "Convert a Swagger or Postman Collection to OpenAPI.",
"description": "Convert an API definition to OpenAPI and bundle any external references.",
"hidden": false,
"name": "openapi:convert",
},
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/analyzeOas.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OASDocument } from 'oas/rmoas.types';
import type { OASDocument } from 'oas/types';

import petstore from '@readme/oas-examples/3.0/json/petstore.json' assert { type: 'json' };
import { describe, it, expect } from 'vitest';
Expand Down
2 changes: 1 addition & 1 deletion __tests__/single-threaded/openapi/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import OpenAPIConvertCommand from '../../../src/cmds/openapi/convert.js';

const convert = new OpenAPIConvertCommand();

const successfulConversion = () => 'Your converted API definition has been saved to output.json!';
const successfulConversion = () => 'Your API definition has been converted and bundled and saved to output.json!';

describe('rdme openapi:convert (single-threaded)', () => {
let testWorkingDir: string;
Expand Down
Loading

0 comments on commit 2082eff

Please sign in to comment.