feat: add new demo file and improve test

This commit is contained in:
Alex Varchuk 2021-05-27 12:44:55 +03:00
parent d525e6d289
commit 456666eaa2
12 changed files with 3087 additions and 67 deletions

View File

@ -5,7 +5,11 @@ import { resolve as urlResolve } from 'url';
import { RedocStandalone } from '../src';
import ComboBox from './ComboBox';
const DEFAULT_SPEC = 'openapi.yaml';
const NEW_VERSION_SPEC = 'openapi-3-1.yaml';
const demos = [
{ value: NEW_VERSION_SPEC, label: 'OpenApi 3.1' },
{ value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram' },
{
value: 'https://api.apis.guru/v2/specs/googleapis.com/calendar/v3/openapi.yaml',
@ -16,8 +20,6 @@ const demos = [
{ value: 'https://docs.graphhopper.com/openapi.json', label: 'GraphHopper' },
];
const DEFAULT_SPEC = 'openapi.yaml';
class DemoApp extends React.Component<
{},
{ specUrl: string; dropdownOpen: boolean; cors: boolean }
@ -45,6 +47,9 @@ class DemoApp extends React.Component<
}
handleChange = (url: string) => {
if (url === NEW_VERSION_SPEC) {
this.setState({ cors: false })
}
this.setState({
specUrl: url,
});

1249
demo/openapi-3-1.yaml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
openapi: 3.1.0
openapi: 3.0.0
servers:
- url: //petstore.swagger.io/v2
description: Default server
@ -42,7 +42,6 @@ info:
version: 1.0.0
title: Swagger Petstore
summary: My lovely API
termsOfService: 'http://swagger.io/terms/'
contact:
name: API Support
@ -54,15 +53,12 @@ info:
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
identifier: Apache 2.0
externalDocs:
description: Find out how to create Github repo for your OpenAPI spec.
url: 'https://github.com/Rebilly/generator-openapi-repo'
tags:
- name: pet
description: Everything about your Pets
- name: webhooks
description: Everything about your Webhooks
- name: store
description: Access to Petstore orders
- name: user
@ -80,7 +76,6 @@ x-tagGroups:
tags:
- pet
- store
- webhooks
- name: User Management
tags:
- user
@ -898,38 +893,6 @@ paths:
default:
description: successful operation
components:
pathItems:
webhooks:
put:
summary: Get a cat details after update
description: Get a cat details after update
operationId: updatedCat
tags:
- webhooks
requestBody:
description: Information about cat in the system
content:
multipart/form-data:
schema:
$ref: "#/components/schemas/Cat"
responses:
'200':
description: update Cat details
post:
summary: Create new cat
description: Info about new cat
operationId: createdCat
tags:
- webhooks
requestBody:
description: Information about cat in the system
content:
multipart/form-data:
schema:
$ref: "#/components/schemas/Cat"
responses:
'200':
description: create Cat details
schemas:
ApiResponse:
type: object
@ -1077,8 +1040,7 @@ components:
example: Guru
photoUrls:
description: The list of URL to a cute photos featuring pet
type: [string, integer, 'null', array]
minItems: 1
type: array
maxItems: 20
xml:
name: photoUrl
@ -1092,8 +1054,7 @@ components:
tags:
description: Tags attached to the pet
type: array
exclusiveMaximum: 100
exclusiveMinimum: 0
minItems: 1
xml:
name: tag
wrapped: true
@ -1106,7 +1067,6 @@ components:
- available
- pending
- sold
default: pending
petType:
description: Type of a pet
type: string
@ -1227,14 +1187,14 @@ components:
shipDate: '2018-10-19T16:46:45Z'
status: placed
complete: false
webhooks:
x-webhooks:
newPet:
post:
summary: New pet
description: Information about a new pet in the systems
operationId: newPet
tags:
- webhooks
- pet
requestBody:
content:
application/json:
@ -1243,7 +1203,3 @@ webhooks:
responses:
"200":
description: Return a 200 status to indicate that the data was received successfully
myWebhook:
$ref: '#/components/pathItems/webhooks'
description: Overriding description
summary: Overriding summary

View File

@ -6,7 +6,7 @@ describe('Menu', () => {
it('should have valid items count', () => {
cy.get('.menu-content')
.find('li')
.should('have.length', 37);
.should('have.length', 34);
});
it('should sync active menu items while scroll', () => {

View File

@ -16,5 +16,6 @@ describe('Standalone bundle test', () => {
}
baseCheck('OAS3 mode', 'e2e/standalone.html');
baseCheck('OAS3.1 mode', 'e2e/standalone-3-1.html');
baseCheck('OAS2 compatibility mode', 'e2e/standalone-compatibility.html');
});

8
e2e/standalone-3-1.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<body>
<redoc spec-url="../demo/openapi-3-1.yaml" native-scrollbars></redoc>
<script src="../bundles/redoc.standalone.js"></script>
</body>
</html>

12
package-lock.json generated
View File

@ -1222,9 +1222,9 @@
}
},
"@redocly/openapi-core": {
"version": "1.0.0-beta.46",
"resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.0.0-beta.46.tgz",
"integrity": "sha512-w4VG2KNLFDuZgN7fBmbzbI0GJDiPnJ0SYszj4uuSkMW35SVTvDWyTaeWjW8ggQJ3gluDnTgUvm9tjLdR2tLqUg==",
"version": "1.0.0-beta.48",
"resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.0.0-beta.48.tgz",
"integrity": "sha512-rlus9qQC4Pkzz2Ljcv+jQjFdKOYSWnsYXWN6zNik9iiiQtMmGEdszsERCbSAYw/CZ5DRCAHMeKrh8f4LBCpx1A==",
"requires": {
"@redocly/ajv": "^6.12.3",
"@types/node": "^14.11.8",
@ -1238,9 +1238,9 @@
},
"dependencies": {
"@types/node": {
"version": "14.17.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.0.tgz",
"integrity": "sha512-w8VZUN/f7SSbvVReb9SWp6cJFevxb4/nkG65yLAya//98WgocKm5PLDAtSs5CtJJJM+kHmJjO/6mmYW4MHShZA=="
"version": "14.17.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.1.tgz",
"integrity": "sha512-/tpUyFD7meeooTRwl3sYlihx2BrJE7q9XF71EguPFIySj9B7qgnRtHsHTho+0AUm4m1SvWGm6uSncrR94q6Vtw=="
}
}
},

View File

@ -134,7 +134,7 @@
"styled-components": "^4.1.1 || ^5.1.1"
},
"dependencies": {
"@redocly/openapi-core": "^1.0.0-beta.45",
"@redocly/openapi-core": "^1.0.0-beta.48",
"@redocly/react-dropdown-aria": "^2.0.11",
"@types/node": "^13.11.1",
"classnames": "^2.2.6",

View File

@ -77,7 +77,6 @@ export class SchemaModel {
this.pointer = schemaOrRef.$ref || pointer || '';
this.rawSchema = parser.deref(schemaOrRef);
this.schema = parser.mergeAllOf(this.rawSchema, this.pointer, isChild);
this.init(parser, isChild);

View File

@ -10,6 +10,12 @@ describe('#loadAndBundleSpec', () => {
expect(bundledSpec).toMatchSnapshot();
});
it('should load And Bundle Spec demo/openapi-3-1.yaml', async () => {
const spec = yaml.load(readFileSync(resolve(__dirname, '../../../demo/openapi-3-1.yaml')));
const bundledSpec = await loadAndBundleSpec(spec);
expect(bundledSpec).toMatchSnapshot();
});
it('should load And Bundle Spec demo/swagger.yaml', async () => {
const spec = yaml.load(readFileSync(resolve(__dirname, '../../../demo/swagger.yaml')));
const bundledSpec = await loadAndBundleSpec(spec);