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

feat(openapi): a fresh coat of paint on openapi inspect #1127

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
573 changes: 355 additions & 218 deletions __tests__/commands/openapi/__snapshots__/inspect.test.ts.snap

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion __tests__/commands/openapi/inspect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable vitest/no-conditional-expect */

import assert from 'node:assert';

import { describe, it, expect, beforeAll } from 'vitest';
Expand All @@ -19,6 +18,7 @@ describe('rdme openapi inspect', () => {
'@readme/oas-examples/3.0/json/petstore.json',
'@readme/oas-examples/3.0/json/readme.json',
'@readme/oas-examples/3.0/json/readme-extensions.json',
'@readme/oas-examples/3.1/json/train-travel.json',
])('should generate a report for %s', spec => {
return expect(run([require.resolve(spec)])).resolves.toMatchSnapshot();
});
Expand All @@ -42,6 +42,10 @@ describe('rdme openapi inspect', () => {
spec: '@readme/oas-examples/3.0/json/schema-circular.json',
feature: ['additionalProperties', 'circularRefs'],
},
{
spec: '@readme/oas-examples/3.1/json/train-travel.json',
feature: ['commonParameters'],
},

// Soft error cases where we may or may not contain the features we're querying for.
{
Expand Down
45 changes: 30 additions & 15 deletions __tests__/lib/__snapshots__/analyzeOas.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
],
"present": true,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#schema-object",
"3.1": "https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties",
},
},
Expand All @@ -41,39 +41,48 @@ exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#callback-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#callback-object",
},
},
"circularRefs": {
"description": "Circular references are $ref pointers that at some point in their lineage reference themselves.",
"locations": [],
"present": false,
},
"commonParameters": {
"description": "Common parameters allow you to define parameters that are shared across multiple operations within your API.",
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#path-item-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#path-item-object",
},
},
"discriminators": {
"description": "With schemas that can be, or contain, different shapes, discriminators help you assist your users in identifying and determining the kind of shape they can supply or receive.",
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#discriminator-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#discriminator-object",
},
},
"links": {
"description": "Links allow you to define at call-time relationships to other operations within your API.",
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#link-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#link-object",
},
},
"polymorphism": {
"description": "Polymorphism (allOf, oneOf, and anyOf) allow you to describe schemas that may contain either many different shapes, or a single shape containing multiple different schemas.",
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#schema-object",
"3.1": "https://json-schema.org/understanding-json-schema/reference/combining.html",
},
},
Expand All @@ -82,25 +91,25 @@ exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#server-variable-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#server-variable-object",
},
},
"style": {
"description": "Parameter serialization (style) allows you to describe how the parameter should be sent to your API.",
"locations": [],
"present": false,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-style",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-style",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#parameter-style",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#parameter-style",
},
},
"webhooks": {
"description": "Webhooks allow you to describe out of band requests that may be initiated by your users.",
"locations": [],
"present": false,
"url": {
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#user-content-oaswebhooks",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#user-content-oaswebhooks",
},
},
"xml": {
Expand All @@ -123,8 +132,8 @@ exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
],
"present": true,
"url": {
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object",
"3.0": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#xml-object",
"3.1": "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#xml-object",
},
},
},
Expand All @@ -135,6 +144,12 @@ exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
"present": false,
"url": "https://docs.readme.com/main/docs/openapi-extensions#authentication-defaults",
},
"x-readme-ref-name": {
"description": "x-readme-ref-name is added by our tooling after dereferencing in order to preserve original reference schema names.",
"hidden": true,
"locations": [],
"present": false,
},
"x-readme.code-samples": {
"description": "The x-readme.code-samples extension allows you to custom, create static code samples on your API documentation.",
"locations": [],
Expand Down
1 change: 1 addition & 0 deletions __tests__/lib/analyzeOas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('#getSupportedFeatures', () => {
'additionalProperties',
'callbacks',
'circularRefs',
'commonParameters',
'discriminators',
'links',
'style',
Expand Down
27 changes: 9 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@
"gray-matter": "^4.0.1",
"ignore": "^6.0.2",
"mime-types": "^2.1.35",
"oas": "^25.0.0",
"oas-normalize": "^11.1.2",
"oas": "^25.2.1",
"oas-normalize": "^12.0.0",
"ora": "^8.1.1",
"pluralize": "^8.0.0",
"prompts": "^2.4.2",
"semver": "^7.5.3",
"simple-git": "^3.19.1",
Expand Down Expand Up @@ -85,7 +84,6 @@
"@types/debug": "^4.1.7",
"@types/js-yaml": "^4.0.5",
"@types/mime-types": "^2.1.1",
"@types/pluralize": "^0.0.33",
"@types/prompts": "^2.4.2",
"@types/semver": "^7.3.12",
"@types/toposort": "^2.0.7",
Expand Down
1 change: 0 additions & 1 deletion src/commands/openapi/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default class OpenAPIConvertCommand extends BaseCommand<typeof OpenAPICon
}

const { preparedSpec, specPath, specType } = await prepareOas(spec, 'openapi convert', {
convertToLatest: true,
title,
});
const parsedPreparedSpec: OASDocument = JSON.parse(preparedSpec);
Expand Down
Loading
Loading