chore: test for cli package (#773)

This commit is contained in:
Yevhen Smoliy
2022-08-01 15:20:55 +03:00
committed by GitHub
parent d047f9fce8
commit 3cff825bfd
20 changed files with 1174 additions and 34 deletions

View File

@@ -3,6 +3,8 @@ name: Build and Test
on: on:
pull_request: pull_request:
types: [opened, synchronize, reopened] types: [opened, synchronize, reopened]
paths-ignore:
- 'docs/**'
push: push:
branches: branches:
- master - master
@@ -38,6 +40,36 @@ jobs:
env: env:
CI: true CI: true
cli-package-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-${{ hashFiles('package-lock.json') }}
npm-
- name: Environments
run: |
echo
echo Using Node $(node -v), NPM $(npm -v)
echo
- name: Install dependencies
run: npm ci
env:
CI: true
- name: Prepare CLI package
run: npm run pack:prepare
- name: Install CLI Package
run: npm install -g redocly-cli.tgz
- name: Redocly version
run: redocly --version
- name: Definition test
run: redocly lint packages/core/src/benchmark/benches/rebilly.yaml --format=stylish
coverage-report: coverage-report:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

1
.gitignore vendored
View File

@@ -10,3 +10,4 @@ lib/
output/ output/
*.tar.gz *.tar.gz
*.tsbuildinfo *.tsbuildinfo
*.tgz

View File

@@ -1,3 +1,4 @@
import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { getCommandOutput, getEntrypoints, callSerializer, getParams } from './helpers'; import { getCommandOutput, getEntrypoints, callSerializer, getParams } from './helpers';
//@ts-ignore //@ts-ignore
@@ -14,12 +15,12 @@ callSerializer();
describe('webpack-bundle test', () => { describe('webpack-bundle test', () => {
test('bundle check', () => { test('bundle check', () => {
const folderPath = join(__dirname, 'webpack-bundle/bundle'); const folderPath = join(__dirname, 'webpack-bundle/bundle');
const enryPoint = getEntrypoints(folderPath); const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'bundle', [ const args = getParams('../../../dist/bundle.js', 'bundle', [
'--max-problems=1', '--max-problems=1',
'-o=/tmp/null', '-o=/tmp/null',
'--lint', '--lint',
...enryPoint, ...entryPoint,
]); ]);
const result = getCommandOutput(args, folderPath); const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js')); (<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
@@ -32,4 +33,48 @@ describe('webpack-bundle test', () => {
const result = getCommandOutput(args, folderPath); const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js')); (<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
}); });
test('bundle-workflows', () => {
const folderPath = join(__dirname, 'webpack-bundle/bundle-workflows');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'bundle', [
'--extends=redocly-registry',
`--metafile=./metafile.json`,
`-o=./bundle.yaml`,
...entryPoint,
]);
const result = getCommandOutput(args, folderPath);
const metaFile = readFileSync(`${folderPath}/metafile.json`, 'utf-8');
const bundleFile = readFileSync(`${folderPath}/bundle.yaml`, 'utf-8');
(<any>expect(metaFile)).toMatchSpecificSnapshot(join(folderPath, 'meta-snapshot.js'));
(<any>expect(bundleFile)).toMatchSpecificSnapshot(join(folderPath, 'bundle-snapshot.js'));
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'result-snapshot.js'));
});
test('lint-workflows', () => {
const folderPath = join(__dirname, 'webpack-bundle/lint-workflows');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'lint', [
'--format=json',
'--lint-config=off',
...entryPoint,
]);
const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});
test('lint-workflows-fail', () => {
const folderPath = join(__dirname, 'webpack-bundle/lint-workflows-fail');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'lint', [
'--format=json',
'--lint-config=off',
...entryPoint,
]);
const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});
}); });

View File

@@ -0,0 +1,3 @@
apis:
main:
root: ./openapi.yaml

View File

@@ -0,0 +1,15 @@
description: A pet
required:
- id
- name
properties:
id:
type: integer
format: int64
description: 'id property'
name:
type: string
description: 'name property'
tag:
type: string
description: 'tag property'

View File

@@ -0,0 +1,161 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`webpack-bundle test bundle-workflows 1`] = `
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
description: test
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: list_pets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
default: 10
maximum: 100
- name: offset
in: query
description: Offset of first element to return in results.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: create_pets
tags:
- pets
responses:
'204':
description: Null response
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{pet_id}:
get:
summary: Info for a specific pet
operationId: get_pet_by_id
tags:
- pets
parameters:
- name: pet_id
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pets:
description: A list of pets
required:
- pets
- next_url
- limit
- offset
properties:
pets:
type: array
description: object containing a list of pets
items:
$ref: '#/components/schemas/Pet'
next_url:
type: string
description: this is the url to next page
limit:
type: integer
format: int32
description: limit
offset:
type: integer
format: int32
description: offset
next_token:
type: string
description: next token
Error:
description: An error in processing a service request
required:
- code
- message
properties:
code:
type: integer
format: int32
description: code property
message:
type: string
description: message property
Pet:
description: A pet
required:
- id
- name
properties:
id:
type: integer
format: int64
description: id property
name:
type: string
description: name property
tag:
type: string
description: tag property
`;

View File

@@ -0,0 +1,156 @@
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
description: test
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: list_pets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
default: 10
maximum: 100
- name: offset
in: query
description: Offset of first element to return in results.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: create_pets
tags:
- pets
responses:
'204':
description: Null response
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{pet_id}:
get:
summary: Info for a specific pet
operationId: get_pet_by_id
tags:
- pets
parameters:
- name: pet_id
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pets:
description: A list of pets
required:
- pets
- next_url
- limit
- offset
properties:
pets:
type: array
description: object containing a list of pets
items:
$ref: '#/components/schemas/Pet'
next_url:
type: string
description: this is the url to next page
limit:
type: integer
format: int32
description: limit
offset:
type: integer
format: int32
description: offset
next_token:
type: string
description: next token
Error:
description: An error in processing a service request
required:
- code
- message
properties:
code:
type: integer
format: int32
description: code property
message:
type: string
description: message property
Pet:
description: A pet
required:
- id
- name
properties:
id:
type: integer
format: int64
description: id property
name:
type: string
description: name property
tag:
type: string
description: tag property

View File

@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`webpack-bundle test bundle-workflows 1`] = `{"fileDependencies":{},"rootType":{"properties":{"openapi":null,"info":{"properties":{"title":{"type":"string"},"version":{"type":"string"},"description":{"type":"string"},"termsOfService":{"type":"string"},"contact":{"properties":{"name":{"type":"string"},"url":{"type":"string"},"email":{"type":"string"}},"name":"Contact"},"license":{"properties":{"name":{"type":"string"},"url":{"type":"string"}},"required":["name"],"name":"License"}},"required":["title","version"],"name":"Info"},"servers":{"name":"ServerList","properties":{},"items":{"properties":{"url":{"type":"string"},"description":{"type":"string"},"variables":{"name":"ServerVariableMap","properties":{}}},"required":["url"],"name":"Server"}},"security":{"name":"SecurityRequirementList","properties":{},"items":{"properties":{},"additionalProperties":{"type":"array","items":{"type":"string"}},"name":"SecurityRequirement"}},"tags":{"name":"TagList","properties":{},"items":{"properties":{"name":{"type":"string"},"description":{"type":"string"},"externalDocs":{"properties":{"description":{"type":"string"},"url":{"type":"string"}},"required":["url"],"name":"ExternalDocs"}},"required":["name"],"name":"Tag"}},"externalDocs":{"properties":{"description":{"type":"string"},"url":{"type":"string"}},"required":["url"],"name":"ExternalDocs"},"paths":{"properties":{},"name":"PathMap"},"components":{"properties":{"parameters":{"name":"NamedParameters","properties":{}},"schemas":{"name":"NamedSchemas","properties":{}},"responses":{"name":"NamedResponses","properties":{}},"examples":{"name":"NamedExamples","properties":{}},"requestBodies":{"name":"NamedRequestBodies","properties":{}},"headers":{"name":"NamedHeaders","properties":{}},"securitySchemes":{"name":"NamedSecuritySchemes","properties":{}},"links":{"name":"NamedLinks","properties":{}},"callbacks":{"name":"NamedCallbacks","properties":{}}},"name":"Components"},"x-webhooks":{"properties":{},"name":"WebhooksMap"}},"required":["openapi","paths","info"],"name":"DefinitionRoot"},"refTypes":{},"visitorsData":{"registry-dependencies":{"links":[]}}}`;

View File

@@ -0,0 +1 @@
{"fileDependencies":{},"rootType":{"properties":{"openapi":null,"info":{"properties":{"title":{"type":"string"},"version":{"type":"string"},"description":{"type":"string"},"termsOfService":{"type":"string"},"contact":{"properties":{"name":{"type":"string"},"url":{"type":"string"},"email":{"type":"string"}},"name":"Contact"},"license":{"properties":{"name":{"type":"string"},"url":{"type":"string"}},"required":["name"],"name":"License"}},"required":["title","version"],"name":"Info"},"servers":{"name":"ServerList","properties":{},"items":{"properties":{"url":{"type":"string"},"description":{"type":"string"},"variables":{"name":"ServerVariableMap","properties":{}}},"required":["url"],"name":"Server"}},"security":{"name":"SecurityRequirementList","properties":{},"items":{"properties":{},"additionalProperties":{"type":"array","items":{"type":"string"}},"name":"SecurityRequirement"}},"tags":{"name":"TagList","properties":{},"items":{"properties":{"name":{"type":"string"},"description":{"type":"string"},"externalDocs":{"properties":{"description":{"type":"string"},"url":{"type":"string"}},"required":["url"],"name":"ExternalDocs"}},"required":["name"],"name":"Tag"}},"externalDocs":{"properties":{"description":{"type":"string"},"url":{"type":"string"}},"required":["url"],"name":"ExternalDocs"},"paths":{"properties":{},"name":"PathMap"},"components":{"properties":{"parameters":{"name":"NamedParameters","properties":{}},"schemas":{"name":"NamedSchemas","properties":{}},"responses":{"name":"NamedResponses","properties":{}},"examples":{"name":"NamedExamples","properties":{}},"requestBodies":{"name":"NamedRequestBodies","properties":{}},"headers":{"name":"NamedHeaders","properties":{}},"securitySchemes":{"name":"NamedSecuritySchemes","properties":{}},"links":{"name":"NamedLinks","properties":{}},"callbacks":{"name":"NamedCallbacks","properties":{}}},"name":"Components"},"x-webhooks":{"properties":{},"name":"WebhooksMap"}},"required":["openapi","paths","info"],"name":"DefinitionRoot"},"refTypes":{},"visitorsData":{"registry-dependencies":{"links":[]}}}

View File

@@ -0,0 +1,141 @@
openapi: '3.0.0'
info:
version: 1.0.0
title: Swagger Petstore
description: test
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: list_pets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
default: 10
maximum: 100
- name: offset
in: query
description: Offset of first element to return in results.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: create_pets
tags:
- pets
responses:
'204':
description: Null response
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{pet_id}:
get:
summary: Info for a specific pet
operationId: get_pet_by_id
tags:
- pets
parameters:
- name: pet_id
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pets:
description: A list of pets
required:
- pets
- next_url
- limit
- offset
properties:
pets:
type: array
description: 'object containing a list of pets'
items:
$ref: Pet.yaml
next_url:
type: string
description: this is the url to next page
limit:
type: integer
format: int32
description: limit
offset:
type: integer
format: int32
description: offset
next_token:
type: string
description: next token
Error:
description: An error in processing a service request
required:
- code
- message
properties:
code:
type: integer
format: int32
description: 'code property'
message:
type: string
description: 'message property'

View File

@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`webpack-bundle test bundle-workflows 1`] = `
bundling ./openapi.yaml...
📦 Created a bundle for ./openapi.yaml at bundle.yaml <test>ms.
`;

View File

@@ -0,0 +1,9 @@
apis:
main:
root: ./openapi.yaml
lint:
rules:
operation-operationId: warn
operation-summary: error
extends: []

View File

@@ -0,0 +1,155 @@
openapi: '3.0.0'
info:
version: 1.0.0
title: Swagger Petstore
description: test
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: list_pets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
default: 10
maximum: 100
- name: offset
in: query
description: Offset of first element to return in results.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: create_pets
tags:
- pets
responses:
'204':
description: Null response
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{pet_id}:
get:
tags:
- pets
parameters:
- name: pet_id
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pet:
description: A pet
required:
- id
- name
properties:
id:
type: integer
format: int64
description: 'id property'
name:
type: string
description: 'name property'
tag:
type: string
description: 'tag property'
Pets:
description: A list of pets
required:
- pets
- next_url
- limit
- offset
properties:
pets:
type: array
description: 'object containing a list of pets'
items:
$ref: '#/components/schemas/Pet'
next_url:
type: string
description: this is the url to next page
limit:
type: integer
format: int32
description: limit
offset:
type: integer
format: int32
description: offset
next_token:
type: string
description: next token
Error:
description: An error in processing a service request
required:
- code
- message
properties:
code:
type: integer
format: int32
description: 'code property'
message:
type: string
description: 'message property'

View File

@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`webpack-bundle test lint-workflows-fail 1`] = `
{
"totals": {
"errors": 1,
"warnings": 1,
"ignored": 0
},
"version": "<version>",
"problems": [
{
"ruleId": "operation-summary",
"severity": "error",
"message": "Operation object should contain \`summary\` field.",
"location": [
{
"source": {
"ref": "openapi.yaml"
},
"pointer": "#/paths/~1pets~1{pet_id}/get/summary",
"reportOnKey": true
}
],
"suggest": []
},
{
"ruleId": "operation-operationId",
"severity": "warn",
"message": "Operation object should contain \`operationId\` field.",
"location": [
{
"source": {
"ref": "openapi.yaml"
},
"pointer": "#/paths/~1pets~1{pet_id}/get/operationId",
"reportOnKey": true
}
],
"suggest": []
}
]
}
validating ./openapi.yaml...
./openapi.yaml: validated in <test>ms
❌ Validation failed with 1 error and 1 warning.
run \`openapi lint --generate-ignore-file\` to add all problems to the ignore file.
`;

View File

@@ -0,0 +1,7 @@
apis:
main:
root: ./openapi.yaml
lint:
extends:
- recommended

View File

@@ -0,0 +1,157 @@
openapi: '3.0.0'
info:
version: 1.0.0
title: Swagger Petstore
description: test
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: list_pets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
default: 10
maximum: 100
- name: offset
in: query
description: Offset of first element to return in results.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: create_pets
tags:
- pets
responses:
'204':
description: Null response
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{pet_id}:
get:
summary: Info for a specific pet
operationId: get_pet_by_id
tags:
- pets
parameters:
- name: pet_id
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
'400':
description: An error response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pet:
description: A pet
required:
- id
- name
properties:
id:
type: integer
format: int64
description: 'id property'
name:
type: string
description: 'name property'
tag:
type: string
description: 'tag property'
Pets:
description: A list of pets
required:
- pets
- next_url
- limit
- offset
properties:
pets:
type: array
description: 'object containing a list of pets'
items:
$ref: '#/components/schemas/Pet'
next_url:
type: string
description: this is the url to next page
limit:
type: integer
format: int32
description: limit
offset:
type: integer
format: int32
description: offset
next_token:
type: string
description: next token
Error:
description: An error in processing a service request
required:
- code
- message
properties:
code:
type: integer
format: int32
description: 'code property'
message:
type: string
description: 'message property'

View File

@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`webpack-bundle test lint-workflows 1`] = `
{
"totals": {
"errors": 0,
"warnings": 0,
"ignored": 0
},
"version": "<version>",
"problems": []
}
validating ./openapi.yaml...
./openapi.yaml: validated in <test>ms
Woohoo! Your OpenAPI definition is valid. 🎉
`;

View File

@@ -29,7 +29,8 @@
"benchmark": "node --expose-gc --noconcurrent_sweeping --predictable packages/core/src/benchmark/benchmark.js", "benchmark": "node --expose-gc --noconcurrent_sweeping --predictable packages/core/src/benchmark/benchmark.js",
"webpack-bundle": "webpack --config webpack.config.ts", "webpack-bundle": "webpack --config webpack.config.ts",
"upload": "node scripts/archive-and-upload-bundle.js", "upload": "node scripts/archive-and-upload-bundle.js",
"deploy-local": "npm run webpack-bundle && npm run compile && ENV=local npm run upload" "deploy-local": "npm run webpack-bundle && npm run compile && ENV=local npm run upload",
"pack:prepare": "cd packages/cli && (mv \"$(npm pack | tail -n 1)\" ../../redocly-cli.tgz)"
}, },
"workspaces": [ "workspaces": [
"packages/*" "packages/*"

View File

@@ -1,5 +1,146 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`bundle should add to meta ref from redocly registry 1`] = `
fileDependencies: {}
rootType:
properties:
openapi: null
info:
properties:
title:
type: string
version:
type: string
description:
type: string
termsOfService:
type: string
contact:
properties:
name:
type: string
url:
type: string
email:
type: string
name: Contact
license:
properties:
name:
type: string
url:
type: string
required:
- name
name: License
required:
- title
- version
name: Info
servers:
name: ServerList
properties: {}
items:
properties:
url:
type: string
description:
type: string
variables:
name: ServerVariableMap
properties: {}
required:
- url
name: Server
security:
name: SecurityRequirementList
properties: {}
items:
properties: {}
additionalProperties:
type: array
items:
type: string
name: SecurityRequirement
tags:
name: TagList
properties: {}
items:
properties:
name:
type: string
description:
type: string
externalDocs:
properties:
description:
type: string
url:
type: string
required:
- url
name: ExternalDocs
required:
- name
name: Tag
externalDocs:
properties:
description:
type: string
url:
type: string
required:
- url
name: ExternalDocs
paths:
properties: {}
name: PathMap
components:
properties:
parameters:
name: NamedParameters
properties: {}
schemas:
name: NamedSchemas
properties: {}
responses:
name: NamedResponses
properties: {}
examples:
name: NamedExamples
properties: {}
requestBodies:
name: NamedRequestBodies
properties: {}
headers:
name: NamedHeaders
properties: {}
securitySchemes:
name: NamedSecuritySchemes
properties: {}
links:
name: NamedLinks
properties: {}
callbacks:
name: NamedCallbacks
properties: {}
name: Components
x-webhooks:
properties: {}
name: WebhooksMap
required:
- openapi
- paths
- info
name: DefinitionRoot
refTypes: {}
visitorsData:
registry-dependencies:
links:
- https://api.redocly.com/registry/params
`;
exports[`bundle should bundle external refs 1`] = ` exports[`bundle should bundle external refs 1`] = `
openapi: 3.0.0 openapi: 3.0.0
paths: paths:

View File

@@ -2,11 +2,21 @@ import outdent from 'outdent';
import * as path from 'path'; import * as path from 'path';
import { bundleDocument, bundle } from '../bundle'; import { bundleDocument, bundle } from '../bundle';
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils'; import { parseYamlToDocument, yamlSerializer, makeConfig } from '../../__tests__/utils';
import { LintConfig, Config, ResolvedConfig } from '../config'; import { LintConfig, Config, ResolvedConfig } from '../config';
import { BaseResolver } from '../resolve'; import { BaseResolver } from '../resolve';
describe('bundle', () => { describe('bundle', () => {
const fetchMock = jest.fn(() =>
Promise.resolve({
ok: true,
text: () => 'External schema content',
headers: {
get: () => '',
},
})
);
expect.addSnapshotSerializer(yamlSerializer); expect.addSnapshotSerializer(yamlSerializer);
const testDocument = parseYamlToDocument( const testDocument = parseYamlToDocument(
@@ -28,7 +38,7 @@ describe('bundle', () => {
shared_a: shared_a:
name: shared-a name: shared-a
`, `,
'', ''
); );
it('change nothing with only internal refs', async () => { it('change nothing with only internal refs', async () => {
@@ -60,7 +70,7 @@ describe('bundle', () => {
}); });
expect(problems).toHaveLength(1); expect(problems).toHaveLength(1);
expect(problems[0].message).toEqual( expect(problems[0].message).toEqual(
`Two schemas are referenced with the same name but different content. Renamed param-b to param-b-2.`, `Two schemas are referenced with the same name but different content. Renamed param-b to param-b-2.`
); );
expect(res.parsed).toMatchSnapshot(); expect(res.parsed).toMatchSnapshot();
}); });
@@ -98,47 +108,25 @@ describe('bundle', () => {
}); });
it('should pull hosted schema', async () => { it('should pull hosted schema', async () => {
const fetchMock = jest.fn(
() => Promise.resolve({
ok: true,
text: () => 'External schema content',
headers: {
get: () => ''
}
})
);
const { bundle: res, problems } = await bundle({ const { bundle: res, problems } = await bundle({
config: new Config({} as ResolvedConfig), config: new Config({} as ResolvedConfig),
externalRefResolver: new BaseResolver({ externalRefResolver: new BaseResolver({
http: { http: {
customFetch: fetchMock, customFetch: fetchMock,
headers: [] headers: [],
} },
}), }),
ref: path.join(__dirname, 'fixtures/refs/hosted.yaml') ref: path.join(__dirname, 'fixtures/refs/hosted.yaml'),
}); });
expect(problems).toHaveLength(0); expect(problems).toHaveLength(0);
expect(fetchMock).toHaveBeenCalledWith( expect(fetchMock).toHaveBeenCalledWith('https://someexternal.schema', {
"https://someexternal.schema", headers: {},
{ });
headers: {}
}
);
expect(res.parsed).toMatchSnapshot(); expect(res.parsed).toMatchSnapshot();
}); });
it('should not bundle url refs if used with keepUrlRefs', async () => { it('should not bundle url refs if used with keepUrlRefs', async () => {
const fetchMock = jest.fn(() =>
Promise.resolve({
ok: true,
text: () => 'External schema content',
headers: {
get: () => '',
},
}),
);
const { bundle: res, problems } = await bundle({ const { bundle: res, problems } = await bundle({
config: new Config({} as ResolvedConfig), config: new Config({} as ResolvedConfig),
externalRefResolver: new BaseResolver({ externalRefResolver: new BaseResolver({
@@ -153,4 +141,50 @@ describe('bundle', () => {
expect(problems).toHaveLength(0); expect(problems).toHaveLength(0);
expect(res.parsed).toMatchSnapshot(); expect(res.parsed).toMatchSnapshot();
}); });
it('should add to meta ref from redocly registry', async () => {
const testDocument = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/pet:
get:
operationId: get
parameters:
- $ref: '#/components/parameters/shared_a'
- name: get_b
post:
operationId: post
parameters:
- $ref: 'https://api.redocly.com/registry/params'
components:
parameters:
shared_a:
name: shared-a
`,
''
);
const config = await makeConfig({}, { 'registry-dependencies': 'on' });
const {
bundle: result,
problems,
...meta
} = await bundleDocument({
document: testDocument,
config: config,
externalRefResolver: new BaseResolver({
http: {
customFetch: fetchMock,
headers: [],
},
}),
});
const parsedMeta = JSON.parse(JSON.stringify(meta));
expect(problems).toHaveLength(0);
expect(parsedMeta).toMatchSnapshot();
});
}); });