persona-community-5/.pnpm-store/v3/files/a7/cb9a05abf8b1eaa1b104eedd044bf5c4fde4a6e697dbbf4efbeb48fa1e130c7f9bb1bdc10fed76521ced8dfd3519d6a207b479e4714b6badba3fb63ef62311
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

229 lines
5.4 KiB
Plaintext

import { outdent } from 'outdent';
import { parseYamlToDocument, makeConfig } from '../../../../__tests__/utils';
import { bundleDocument } from '../../../bundle';
import { BaseResolver } from '../../../resolve';
describe('oas2 remove-unused-components', () => {
it('should remove unused components', async () => {
const document = parseYamlToDocument(
outdent`
swagger: '2.0'
paths:
/pets:
get:
produces:
- application/json
parameters: []
responses:
'200':
schema:
$ref: '#/definitions/Used'
operationId: listPets
summary: List all pets
definitions:
Unused:
enum:
- 1
- 2
type: integer
Used:
properties:
link:
type: string
type: object
`,
'foobar.yaml'
);
const results = await bundleDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: {} }),
removeUnusedComponents: true,
});
expect(results.bundle.parsed).toEqual({
swagger: '2.0',
definitions: {
Used: {
properties: {
link: { type: 'string' },
},
type: 'object',
},
},
paths: {
'/pets': {
get: {
produces: ['application/json'],
parameters: [],
summary: 'List all pets',
operationId: 'listPets',
responses: {
'200': {
schema: {
$ref: '#/definitions/Used',
},
},
},
},
},
},
});
});
it('should not remove components used child reference', async () => {
const document = parseYamlToDocument(
outdent`
swagger: '2.0'
paths:
/pets:
get:
produces:
- application/json
parameters: []
responses:
'200':
schema:
$ref: '#/definitions/Used'
operationId: listPets
summary: List all pets
definitions:
InnerUsed:
properties:
link:
type: string
type: object
Unused:
enum:
- 1
- 2
type: integer
Used:
properties:
link:
$ref: '#/definitions/InnerUsed/properties/link'
type: object
`,
'foobar.yaml'
);
const results = await bundleDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: {} }),
removeUnusedComponents: true,
});
expect(results.bundle.parsed).toEqual({
swagger: '2.0',
definitions: {
InnerUsed: {
properties: {
link: {
type: 'string',
},
},
type: 'object',
},
Used: {
properties: {
link: { $ref: '#/definitions/InnerUsed/properties/link' },
},
type: 'object',
},
},
paths: {
'/pets': {
get: {
produces: ['application/json'],
parameters: [],
summary: 'List all pets',
operationId: 'listPets',
responses: {
'200': {
schema: {
$ref: '#/definitions/Used',
},
},
},
},
},
},
});
});
it('should remove transitively unused components', async () => {
const document = parseYamlToDocument(
outdent`
swagger: '2.0'
paths:
/pets:
get:
produces:
- application/json
parameters: []
responses:
'200':
schema:
$ref: '#/definitions/Used'
operationId: listPets
summary: List all pets
definitions:
Unused:
enum:
- 1
- 2
type: integer
UnusedTransitive:
type: object
properties:
link:
$ref: '#/definitions/Unused'
Used:
properties:
link:
type: string
type: object
`,
'foobar.yaml'
);
const results = await bundleDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: {} }),
removeUnusedComponents: true,
});
expect(results.bundle.parsed).toEqual({
swagger: '2.0',
definitions: {
Used: {
properties: {
link: { type: 'string' },
},
type: 'object',
},
},
paths: {
'/pets': {
get: {
produces: ['application/json'],
parameters: [],
summary: 'List all pets',
operationId: 'listPets',
responses: {
'200': {
schema: {
$ref: '#/definitions/Used',
},
},
},
},
},
},
});
});
});