mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
* OpenAPI: update types * improve OpenAPI 3.0 to 3.1 converter * prepare for Scalar parser for 3.0 to 3.1 converter * improve schema type utility * Fix cyclic references without custom id/title * Add scopes to auth schemes * Support Webhooks * Support generating webhooks docs * fix tests * Support operation callbacks * prepare for merge * fix conflicts * make compatible with older OpenAPI versions * fix issues
220 lines
4.0 KiB
TypeScript
220 lines
4.0 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { combineSchema } from '@/utils/combine-schema';
|
|
|
|
describe('Merge object schemas', () => {
|
|
test('Merge single object', () => {
|
|
const result = combineSchema([
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
test: {
|
|
type: 'string',
|
|
enum: ['one', 'two'],
|
|
},
|
|
},
|
|
},
|
|
]);
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
{
|
|
"properties": {
|
|
"test": {
|
|
"enum": [
|
|
"one",
|
|
"two",
|
|
],
|
|
"type": "string",
|
|
},
|
|
},
|
|
"type": [
|
|
"object",
|
|
],
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('Merge multiple objects', () => {
|
|
const result = combineSchema([
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
test: {
|
|
type: 'string',
|
|
enum: ['one', 'two'],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
hello: {
|
|
type: 'number',
|
|
},
|
|
},
|
|
},
|
|
]);
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
{
|
|
"properties": {
|
|
"hello": {
|
|
"type": "number",
|
|
},
|
|
"test": {
|
|
"enum": [
|
|
"one",
|
|
"two",
|
|
],
|
|
"type": "string",
|
|
},
|
|
},
|
|
"type": [
|
|
"object",
|
|
],
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('Merge multiple objects: required', () => {
|
|
const result = combineSchema([
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
test: {
|
|
type: 'string',
|
|
enum: ['one', 'two'],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
hello: {
|
|
type: 'number',
|
|
},
|
|
},
|
|
required: ['hello'],
|
|
},
|
|
]);
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
{
|
|
"properties": {
|
|
"hello": {
|
|
"type": "number",
|
|
},
|
|
"test": {
|
|
"enum": [
|
|
"one",
|
|
"two",
|
|
],
|
|
"type": "string",
|
|
},
|
|
},
|
|
"required": [
|
|
"hello",
|
|
],
|
|
"type": [
|
|
"object",
|
|
],
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('Merge multiple objects: additional properties', () => {
|
|
const result = combineSchema([
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
test: {
|
|
type: 'string',
|
|
enum: ['one', 'two'],
|
|
},
|
|
},
|
|
additionalProperties: true,
|
|
},
|
|
{
|
|
type: 'object',
|
|
additionalProperties: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
]);
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
{
|
|
"additionalProperties": true,
|
|
"properties": {
|
|
"test": {
|
|
"enum": [
|
|
"one",
|
|
"two",
|
|
],
|
|
"type": "string",
|
|
},
|
|
},
|
|
"type": [
|
|
"object",
|
|
],
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('Merge multiple objects: `allOf`', () => {
|
|
const result = combineSchema([
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
test: {
|
|
type: 'string',
|
|
enum: ['one', 'two'],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
allOf: [
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
hello: {
|
|
type: 'number',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
world: {
|
|
type: 'number',
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
{
|
|
"properties": {
|
|
"hello": {
|
|
"type": "number",
|
|
},
|
|
"test": {
|
|
"enum": [
|
|
"one",
|
|
"two",
|
|
],
|
|
"type": "string",
|
|
},
|
|
"world": {
|
|
"type": "number",
|
|
},
|
|
},
|
|
"type": [
|
|
"object",
|
|
],
|
|
}
|
|
`);
|
|
});
|
|
});
|