assert.throws(
() => new AddTagToOperationIdsTransformer(null),
TypeError,
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get3({
tags: ['MyTag'],
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
tags: ['MyTag'],
operationId: 'MyTag_getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get3({
tags: ['MyTag1', 'MyTag2'],
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
tags: ['MyTag1', 'MyTag2'],
operationId: 'MyTag1_getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get3({
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get3({
tags: [],
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
tags: [],
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get3({
tags: ['MyTag'],
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
tags: ['MyTag'],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get3({
tags: ['MyTag'],
operationId: '',
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
tags: ['MyTag'],
operationId: '',
responses: {
204: {
description: 'Example response',
},
},
}),
);const transformer =
new AddTagToOperationIdsTransformer({ tagSuffix: 'Api' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(get3({
tags: ['MyTag'],
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
tags: ['MyTag'],
operationId: 'MyTagApi_getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddTagToOperationIdsTransformer().transformOpenApi(deepFreeze(get2({
tags: ['MyTag'],
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}))),
get2({
tags: ['MyTag'],
operationId: 'MyTag_getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddXMsEnumNameTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'value1',
'value2',
],
}))),
schema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-ms-enum': {
name: 'Test',
},
}),
);assert.deepStrictEqual(
new AddXMsEnumNameTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-ms-enum': {
values: [
{
name: 'Value1',
value: 'value1',
},
{
name: 'Value2',
value: 'value2',
},
],
},
}))),
schema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-ms-enum': {
name: 'Test',
values: [
{
name: 'Value1',
value: 'value1',
},
{
name: 'Value2',
value: 'value2',
},
],
},
}),
);assert.deepStrictEqual(
new AddXMsEnumNameTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
myenum: {
type: 'string',
enum: [
'value1',
'value2',
],
},
},
}))),
schema3({
type: 'object',
properties: {
myenum: {
type: 'string',
enum: [
'value1',
'value2',
],
},
},
}),
);assert.deepStrictEqual(
new AddXMsEnumNameTransformer().transformOpenApi(deepFreeze(post3({
requestBody: {
content: {
'application/json': {
schema: {
type: 'string',
enum: [
'value1',
'value2',
],
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
}))),
post3({
requestBody: {
content: {
'application/json': {
schema: {
type: 'string',
enum: [
'value1',
'value2',
],
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddXMsEnumNameTransformer().transformOpenApi(deepFreeze(
responseSchema3({
type: 'string',
enum: [
'value1',
'value2',
],
}),
)),
responseSchema3({
type: 'string',
enum: [
'value1',
'value2',
],
}),
);assert.deepStrictEqual(
new AddXMsEnumNameTransformer().transformOpenApi(deepFreeze(schema2({
type: 'string',
enum: [
'value1',
'value2',
],
}))),
schema2({
type: 'string',
enum: [
'value1',
'value2',
],
'x-ms-enum': {
name: 'Test',
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
},
}),
)),
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
}),
)),
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ value: 'my value1' },
{ value: 'my value2' },
],
},
}),
)),
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ value: 'my value1' },
{ name: 'MyValue', value: 'my value2' },
],
},
}),
)),
schema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue', value: 'my value2' },
],
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(get3({
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
},
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(get3({
parameters: [
{
name: 'myquery',
in: 'query',
content: {
'application/json': {
schema: {
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
},
},
},
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
get3({
parameters: [
{
name: 'myquery',
in: 'query',
content: {
'application/json': {
schema: {
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
},
},
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(post3({
requestBody: {
content: {
'application/json': {
schema: {
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
},
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
}))),
post3({
requestBody: {
content: {
'application/json': {
schema: {
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(
responseSchema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
},
}),
)),
responseSchema3({
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
}),
);assert.deepStrictEqual(
new AddXMsEnumValueNamesTransformer().transformOpenApi(deepFreeze(get2({
parameters: [
{
in: 'query',
name: 'myquery',
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
get2({
parameters: [
{
in: 'query',
name: 'myquery',
type: 'string',
enum: [
'my value1',
'my value2',
],
'x-ms-enum': {
name: 'StringEnum',
values: [
{ name: 'MyValue1', value: 'my value1' },
{ name: 'MyValue2', value: 'my value2' },
],
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);const transformer = new AdditionalPropertiesToObjectTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: true,
}))),
schema3({
type: 'object',
additionalProperties: {},
}),
);const transformer = new AdditionalPropertiesToObjectTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema2({
type: 'object',
additionalProperties: true,
}))),
schema2({
type: 'object',
additionalProperties: {},
}),
);const transformer = new AdditionalPropertiesToUnconstrainedTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
// Generates class with Myprop property and
// [JsonExtensionData] Map<string,string> AdditionalProperties
type: 'object',
properties: {
myprop: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
},
}))),
schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
},
},
additionalProperties: {},
}),
);const transformer = new AdditionalPropertiesToUnconstrainedTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
// Generates Map<string,string>, no JsonExtensionData
type: 'object',
additionalProperties: {
type: 'string',
},
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
}),
);const transformer = new AdditionalPropertiesToUnconstrainedTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
// Generates Map<string,string>, no JsonExtensionData
type: 'object',
properties: {},
additionalProperties: {
type: 'string',
},
}))),
schema3({
type: 'object',
properties: {},
additionalProperties: {
type: 'string',
},
}),
);assert.deepStrictEqual(
new AnyOfNullToNullableTransformer().transformOpenApi(schema3(1)),
schema3(1),
);assert.deepStrictEqual(
new AnyOfNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: 1,
}, '3.1.0'))),
schema3({
anyOf: 1,
}, '3.1.0'),
);assert.deepStrictEqual(
new AnyOfNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: [],
}, '3.1.0'))),
schema3({
anyOf: [],
}, '3.1.0'),
);assert.deepStrictEqual(
new AnyOfNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: [
{ type: 'null' },
],
}, '3.1.0'))),
schema3({
anyOf: [
{ type: 'null' },
],
}, '3.1.0'),
);assert.deepStrictEqual(
new AnyOfNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: [
{ type: 'number' },
{ type: 'null' },
],
}, '3.1.0'))),
schema3({
anyOf: [
{ type: 'number' },
],
nullable: true,
}, '3.1.0'),
);assert.deepStrictEqual(
new AnyOfNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: [
{ type: 'null' },
{ type: 'number' },
{ type: 'null' },
],
}, '3.1.0'))),
schema3({
anyOf: [
{ type: 'number' },
],
nullable: true,
}, '3.1.0'),
);assert.deepStrictEqual(
new AssertPropertiesTransformer({ schema: { excludes: [] } })
.transformOpenApi(deepFreeze(schema3({}))),
schema3({}),
);assert.deepStrictEqual(
new AssertPropertiesTransformer({ schema: { excludes: [] } })
.transformOpenApi(deepFreeze(schema3({ type: 'string' }))),
schema3({ type: 'string' }),
);assert.throws(
() => new AssertPropertiesTransformer({
schema: {
excludes: ['minimum'],
},
})
.transformOpenApi(deepFreeze(schema3({ minimum: 1 }))),
/minimum/,
);assert.throws(
() => new AssertPropertiesTransformer({
schema: {
excludes: ['minimum'],
},
})
.transformOpenApi(deepFreeze(schema3({ allOf: [{ minimum: 1 }] }))),
/minimum/,
);assert.deepStrictEqual(
new AssertPropertiesTransformer({ schema: { excludes: ['prototype'] } })
.transformOpenApi(deepFreeze(schema3({}))),
schema3({}),
);assert.deepStrictEqual(
new AssertPropertiesTransformer({ schema: { excludes: ['minimum'] } })
.transformOpenApi(deepFreeze(schema3({ minimum: undefined }))),
schema3({ minimum: undefined }),
);assert.throws(
() => new AssertPropertiesTransformer(),
TypeError,
);assert.throws(
() => new AssertPropertiesTransformer({}),
TypeError,
);assert.throws(
() => new AssertPropertiesTransformer({ schema: {} }),
TypeError,
);assert.throws(
() => new AssertPropertiesTransformer({ schema: { excludes: {} } }),
TypeError,
);assert.throws(
() => new AssertPropertiesTransformer({ schema: { excludes: [1] } }),
TypeError,
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
format: 'binary',
}))),
schema3({
type: 'file',
}),
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
format: 'file',
}))),
schema3({
type: 'file',
}),
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
}))),
schema3({
type: 'string',
}),
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(post2({
parameters: [
{
in: 'body',
name: 'myfile',
schema: {
type: 'string',
format: 'binary',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
post2({
parameters: [
{
in: 'body',
name: 'myfile',
schema: {
type: 'file',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(post2({
parameters: [
{
in: 'body',
name: 'myfile',
schema: {
type: 'string',
format: 'file',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
post2({
parameters: [
{
in: 'body',
name: 'myfile',
schema: {
type: 'file',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(post2({
parameters: [
{
in: 'formData',
name: 'myfile',
type: 'string',
format: 'binary',
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
post2({
parameters: [
{
in: 'formData',
name: 'myfile',
type: 'file',
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new BinaryStringToFileTransformer().transformOpenApi(deepFreeze(post2({
parameters: [
{
in: 'formData',
name: 'myfile',
type: 'string',
format: 'file',
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
post2({
parameters: [
{
in: 'formData',
name: 'myfile',
type: 'file',
},
],
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze(schema3({
type: 'boolean',
enum: [true, false],
}))),
schema3({
type: 'boolean',
}),
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze(schema3({
type: 'boolean',
enum: [false, true],
}))),
schema3({
type: 'boolean',
}),
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: ['true', 'false'],
}))),
schema3({
type: 'string',
enum: ['true', 'false'],
}),
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
headers: {
Example: {
schema: {
type: 'string',
enum: ['true', 'false'],
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
headers: {
Example: {
schema: {
type: 'boolean',
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'path',
schema: {
type: 'string',
enum: ['true', 'false'],
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'path',
schema: {
type: 'boolean',
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'query',
schema: {
type: 'string',
enum: ['true', 'false'],
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'query',
schema: {
type: 'boolean',
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'query',
schema: {
type: ['boolean', 'string'],
enum: ['true', 'false', true, false],
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'query',
schema: {
type: 'boolean',
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'cookie',
schema: {
type: 'string',
enum: ['true', 'false'],
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'cookie',
schema: {
type: 'boolean',
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new BoolEnumToBoolTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'cookie',
content: {
'application/json': {
schema: {
type: 'string',
enum: ['true', 'false'],
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
parameters: {
Example: {
name: 'example',
in: 'cookie',
content: {
'application/json': {
schema: {
type: 'string',
enum: ['true', 'false'],
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new ClearHtmlResponseSchemaTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
type: 'string',
format: 'binary',
},
},
},
},
},
},
},
'/html': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'text/html': {
schema: {
type: 'string',
format: 'binary',
},
},
},
},
},
},
},
},
})),
{
...openapi,
paths: {
'/': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
type: 'string',
format: 'binary',
},
},
},
},
},
},
},
'/html': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'text/html': {},
},
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClearHtmlResponseSchemaTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
type: 'string',
format: 'binary',
},
},
},
},
},
},
},
'/html': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'text/html;charset=utf-8': {
schema: {
type: 'string',
format: 'binary',
},
},
},
},
},
},
},
},
})),
{
...openapi,
paths: {
'/': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
type: 'string',
format: 'binary',
},
},
},
},
},
},
},
'/html': {
get: {
responses: {
default: {
description: 'Example response',
content: {
'text/html;charset=utf-8': {},
},
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClearHtmlResponseSchemaTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/': {
get: {
produces: ['application/json'],
responses: {
default: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
},
},
'/html': {
get: {
produces: ['text/html'],
responses: {
default: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
},
},
},
})),
{
...swagger,
paths: {
'/': {
get: {
produces: ['application/json'],
responses: {
default: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
},
},
'/html': {
get: {
produces: ['text/html'],
responses: {
default: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze(get3({
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
{
...openapi,
components: {
parameters: {
myquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/': {
get: {
parameters: [
{ $ref: '#/components/parameters/myquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
get: {
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
'/b': {
get: {
parameters: [
{
'x-ms-parameter-location': 'client',
in: 'query',
schema: {
type: 'string',
},
name: 'myquery',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {
parameters: {
myquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/a': {
get: {
parameters: [
{ $ref: '#/components/parameters/myquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
'/b': {
get: {
parameters: [
{ $ref: '#/components/parameters/myquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
myquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/a': {
get: {
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {
parameters: {
myquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/a': {
get: {
parameters: [
{ $ref: '#/components/parameters/myquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
notmyquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/a': {
get: {
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {
parameters: {
notmyquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/a': {
get: {
parameters: [
{ $ref: '#/components/parameters/notmyquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
parameters: {
notmyquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
},
},
},
paths: {
'/a': {
get: {
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {
parameters: {
notmyquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
},
},
},
paths: {
'/a': {
get: {
parameters: [
{ $ref: '#/components/parameters/notmyquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
get: {
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
'/b': {
get: {
parameters: [
{
name: 'myquery',
in: 'query',
schema: {
type: 'number',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {
parameters: {
myquery: {
name: 'myquery',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
myquery2: {
name: 'myquery',
in: 'query',
schema: {
type: 'number',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/a': {
get: {
parameters: [
{ $ref: '#/components/parameters/myquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
'/b': {
get: {
parameters: [
{ $ref: '#/components/parameters/myquery2' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze(get3({
parameters: [
{
name: 'my~query/thing',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
{
...openapi,
components: {
parameters: {
'my~query/thing': {
name: 'my~query/thing',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/': {
get: {
parameters: [
{ $ref: '#/components/parameters/my~0query~1thing' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze(get3({
parameters: [
{
name: 'my?query#thing',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
{
...openapi,
components: {
parameters: {
'my?query#thing': {
name: 'my?query#thing',
in: 'query',
schema: {
type: 'string',
},
'x-ms-parameter-location': 'client',
},
},
},
paths: {
'/': {
get: {
parameters: [
{ $ref: '#/components/parameters/my%3Fquery%23thing' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze(get2({
parameters: [
{
name: 'myquery',
in: 'query',
type: 'string',
'x-ms-parameter-location': 'client',
},
],
responses: {
204: {
description: 'Example response',
},
},
}))),
{
...swagger,
parameters: {
myquery: {
name: 'myquery',
in: 'query',
type: 'string',
'x-ms-parameter-location': 'client',
},
},
paths: {
'/': {
get: {
parameters: [
{ $ref: '#/parameters/myquery' },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ClientParamsToGlobalTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {},
'x-ms-parameterized-host': {
hostTemplate: 'example.{tld}',
parameters: [
{
name: 'tld',
in: 'path',
type: 'string',
'x-ms-parameter-location': 'client',
},
],
},
})),
{
...swagger,
parameters: {
tld: {
name: 'tld',
in: 'path',
type: 'string',
'x-ms-parameter-location': 'client',
},
},
paths: {},
'x-ms-parameterized-host': {
hostTemplate: 'example.{tld}',
parameters: [
{ $ref: '#/parameters/tld' },
],
},
},
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(schema3({
const: 1,
}, '3.1.0'))),
schema3({
enum: [1],
}, '3.1.0'),
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(schema3({
const: null,
}, '3.1.0'))),
schema3({
enum: [null],
}, '3.1.0'),
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(schema3({
const: 1,
enum: [1],
}, '3.1.0'))),
schema3({
enum: [1],
}, '3.1.0'),
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(schema3({
const: 2,
enum: [1, 2, 3],
}, '3.1.0'))),
schema3({
enum: [2],
}, '3.1.0'),
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(schema3({
const: null,
enum: [1, null],
}, '3.1.0'))),
schema3({
enum: [null],
}, '3.1.0'),
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(schema3({
const: 2,
enum: [1, 3],
}, '3.1.0'))),
schema3({
enum: [],
}, '3.1.0'),
);assert.deepStrictEqual(
new ConstToEnumTransformer().transformOpenApi(deepFreeze(
schema3(null, '3.1.0'),
)),
schema3(null, '3.1.0'),
);assert.throws(
() => new EscapeEnumValuesTransformer(),
TypeError,
);assert.throws(
() => new EscapeEnumValuesTransformer({}),
TypeError,
);assert.throws(
() => new EscapeEnumValuesTransformer({ language: 5 }),
TypeError,
);assert.throws(
() => new EscapeEnumValuesTransformer({ language: 'unrecognized' }),
RangeError,
);const transformer =
new EscapeEnumValuesTransformer({ language: 'csharp' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'go' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'java' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'nodejs' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "\\'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'php' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'python' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "\\'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'ruby' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
}))),
schema3({
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "\\'" },
{ value: '\\\\' },
{ value: '\r\n' },
],
},
}),
);const transformer =
new EscapeEnumValuesTransformer({ language: 'csharp' });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...swagger,
parameters: {
myparam: {
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '"' },
{ value: "'" },
{ value: '\\' },
{ value: '\r\n' },
],
},
},
},
paths: {},
})),
{
...swagger,
parameters: {
myparam: {
type: 'string',
enum: [
'"',
"'",
'\\',
'\r\n',
],
'x-ms-enum': {
name: 'MyEnum',
values: [
{ value: '\\"' },
{ value: "'" },
{ value: '\\\\' },
{ value: '\\r\\n' },
],
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{ exclusiveMaximum: 1 },
'3.1.0',
),
)),
schema3(
{
exclusiveMaximum: true,
maximum: 1,
},
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{ exclusiveMinimum: 1 },
'3.1.0',
),
)),
schema3(
{
exclusiveMinimum: true,
minimum: 1,
},
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{
exclusiveMaximum: 1,
maximum: 0,
},
'3.1.0',
),
)),
schema3(
{ maximum: 0 },
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{
exclusiveMinimum: 0,
minimum: 1,
},
'3.1.0',
),
)),
schema3(
{ minimum: 1 },
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{
exclusiveMaximum: 0,
maximum: 1,
},
'3.1.0',
),
)),
schema3(
{
exclusiveMaximum: true,
maximum: 0,
},
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{
exclusiveMinimum: 1,
minimum: 0,
},
'3.1.0',
),
)),
schema3(
{
exclusiveMinimum: true,
minimum: 1,
},
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{
exclusiveMaximum: 1,
maximum: 1,
},
'3.1.0',
),
)),
schema3(
{
exclusiveMaximum: true,
maximum: 1,
},
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{
exclusiveMinimum: 1,
minimum: 1,
},
'3.1.0',
),
)),
schema3(
{
exclusiveMinimum: true,
minimum: 1,
},
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{ exclusiveMaximum: 'test' },
'3.1.0',
),
)),
schema3(
{ exclusiveMaximum: 'test' },
'3.1.0',
),
);assert.deepStrictEqual(
new ExclusiveMinMaxToBoolTransformer().transformOpenApi(deepFreeze(
schema3(
{ exclusiveMinimum: 'test' },
'3.1.0',
),
)),
schema3({
exclusiveMinimum: 'test',
}, '3.1.0'),
);assert.deepStrictEqual(
new FormatToTypeTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
prop: {
type: 'string',
format,
},
},
}))),
schema3({
type: 'object',
properties: {
prop: {
type,
// format is removed if format === type
...format === type ? undefined : { format },
},
},
}),
);assert.deepStrictEqual(
new FormatToTypeTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
prop: {
type: 'string',
format,
},
},
}))),
schema3({
type: 'object',
properties: {
prop: {
type,
// format is removed if format === type
...format === type ? undefined : { format },
},
},
}),
);assert.deepStrictEqual(
new FormatToTypeTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
prop: {
type: 'string',
format,
},
},
}))),
schema3({
type: 'object',
properties: {
prop: {
type,
// format is removed if format === type
...format === type ? undefined : { format },
},
},
}),
);assert.deepStrictEqual(
new FormatToTypeTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
prop: {
type: 'string',
format,
},
},
}))),
schema3({
type: 'object',
properties: {
prop: {
type,
// format is removed if format === type
...format === type ? undefined : { format },
},
},
}),
);assert.deepStrictEqual(
new FormatToTypeTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
prop: {
type: 'string',
format,
},
},
}))),
schema3({
type: 'object',
properties: {
prop: {
type,
// format is removed if format === type
...format === type ? undefined : { format },
},
},
}),
);assert.deepStrictEqual(
new FormatToTypeTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
prop: {
type: 'string',
format,
},
},
}))),
schema3({
type: 'object',
properties: {
prop: {
type,
// format is removed if format === type
...format === type ? undefined : { format },
},
},
}),
);assert.throws(
() => new InlineNonObjectSchemaTransformer(null),
TypeError,
);assert.throws(
() => new InlineNonObjectSchemaTransformer({ resolveRef: 1 }),
TypeError,
);assert.deepStrictEqual(
new InlineNonObjectSchemaTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
Weight: {
type: 'number',
minimum: 0,
},
Example: {
type: 'object',
properties: {
weight: {
$ref: '#/components/schemas/Weight',
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
schemas: {
Weight: {
type: 'number',
minimum: 0,
},
Example: {
type: 'object',
properties: {
weight: {
type: 'number',
minimum: 0,
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new InlineNonObjectSchemaTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
Weight: {
type: 'number',
},
Example: {
type: 'object',
properties: {
weight: {
$ref: '#/components/schemas/Weight',
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
schemas: {
Weight: {
type: 'number',
},
Example: {
type: 'object',
properties: {
weight: {
$ref: '#/components/schemas/Weight',
},
},
},
},
},
paths: {},
},
);const transformer =
new InlineNonObjectSchemaTransformer({ inlineAll: true });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
Weight: {
type: 'number',
},
Example: {
type: 'object',
properties: {
weight: {
$ref: '#/components/schemas/Weight',
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
schemas: {
Weight: {
type: 'number',
},
Example: {
type: 'object',
properties: {
weight: {
type: 'number',
},
},
},
},
},
paths: {},
},
);function resolveRef($ref) {
assert.strictEqual($ref, '#/components/schemas/Weight');
return {
type: 'number',
minimum: 0,
};
}
const transformer = new InlineNonObjectSchemaTransformer({ resolveRef });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
weight: {
$ref: '#/components/schemas/Weight',
},
},
}))),
schema3({
type: 'object',
properties: {
weight: {
type: 'number',
minimum: 0,
},
},
}),
);assert.throws(
() => new ComponentManager(),
TypeError,
);assert.throws(
() => new ComponentManager(null),
TypeError,
);assert.throws(
() => new ComponentManager([]),
TypeError,
);const name = 'test';
const value = {};
const component = {};
const newName = new ComponentManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], value);const name = 'test';
const value = {};
const component = { [name]: false };
const newName = new ComponentManager(component).add(value, name);
assert.strictEqual(newName, `${name}2`);
assert.strictEqual(component[newName], value);
assert.strictEqual(component[name], false);const name = 'test';
const value = {};
const component = { [name]: undefined };
const newName = new ComponentManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], value);const name = 'test';
const value = {};
const origValue = {};
const component = { [name]: origValue };
const newName = new ComponentManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], origValue);
assert.ok(!Object.hasOwn(component, `${name}2`));const name = 'test';
const value = {};
const component = { other: value };
const newName = new ComponentManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], value);const value = {};
const component = {};
const newName = new ComponentManager(component).add(value);
assert.strictEqual(newName, 'undefined');
assert.strictEqual(component.undefined, value);const value = {};
const component = { undefined: false };
const newName = new ComponentManager(component).add(value);
assert.strictEqual(newName, 'undefined2');
assert.strictEqual(component.undefined2, value);
assert.strictEqual(component.undefined, false);const name = 'test';
const name2 = 'surprise';
const value = {};
const component = {};
const manager = new ComponentManager(component);
manager.getNames = function* (basename) {
assert.strictEqual(this, manager);
assert.strictEqual(basename, name);
yield name2;
};
const newName = manager.add(value, name);
assert.strictEqual(newName, name2);
assert.strictEqual(component[name2], value);const manager = new ComponentManager({});
// eslint-disable-next-line no-empty-function
manager.getNames = function* (basename) {};
assert.throws(
() => manager.add({}, 'name'),
/suitable name/i,
);const name = 'test';
const value = 'new';
const component = { [name]: 'orig' };
const manager = new ComponentManager(component);
manager.isMatch = function(value1, value2) {
assert.strictEqual(this, manager);
assert.strictEqual(value1, 'orig');
assert.strictEqual(value2, 'new');
return true;
};
const newName = manager.add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], 'orig');
assert.ok(!Object.hasOwn(component, `${name}2`));assert.throws(
() => new MatchingComponentManager(),
TypeError,
);assert.throws(
() => new MatchingComponentManager(null),
TypeError,
);assert.throws(
() => new MatchingComponentManager([]),
TypeError,
);const name = 'test';
const value = {};
const component = {};
const newName = new MatchingComponentManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], value);const name = 'test';
const value = {};
const origValue = {};
const component = { [name]: origValue };
const newName = new MatchingComponentManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[name], origValue);
assert.ok(!Object.hasOwn(component, `${name}2`));const name = 'test';
const value = {};
const origName = 'unrelated';
const origValue = {};
const component = { [origName]: origValue };
const newName = new MatchingComponentManager(component)
.add(value, name);
assert.strictEqual(newName, origName);
assert.strictEqual(component[newName], origValue);
assert.ok(!Object.hasOwn(component, name));const name = 'test';
const value = [];
const origName = 'unrelated';
const origValue = {};
const component = { [origName]: origValue };
class TestManager extends MatchingComponentManager {
getKey(keyVal) {
assert.ok(this instanceof TestManager);
// Called with origValue by constructor, value by #add().
assert.ok(keyVal === origValue || keyVal === value);
return 'mykey';
}
}
const newName = new TestManager(component).add(value, name);
assert.strictEqual(newName, origName);
assert.strictEqual(component[newName], origValue);
assert.ok(!Object.hasOwn(component, name));const name = 'test';
const value = [];
const origName = 'unrelated';
const origValue = {};
const component = { [origName]: origValue };
class TestManager extends MatchingComponentManager {
// eslint-disable-next-line class-methods-use-this
getKey(keyVal) {
return keyVal === origValue ? 'true'
: keyVal === value ? true
: assert.fail('unexpected keyVal');
}
}
const newName = new TestManager(component).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(component[newName], value);
assert.strictEqual(component[origName], origValue);assert.throws(
() => new MatchingParameterMatcher(),
TypeError,
);assert.throws(
() => new MatchingParameterMatcher(null),
TypeError,
);assert.throws(
() => new MatchingParameterMatcher([]),
TypeError,
);const name = 'test';
const value = {};
const parameters = {};
const newName = new MatchingParameterMatcher(parameters).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(parameters[name], value);const name = 'test';
const value = {};
const origValue = {};
const parameters = { [name]: origValue };
const newName = new MatchingParameterMatcher(parameters).add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(parameters[name], origValue);
assert.ok(!Object.hasOwn(parameters, `${name}2`));const name = 'test';
const value = {};
const origName = 'unrelated';
const origValue = {};
const parameters = { [origName]: origValue };
const newName = new MatchingParameterMatcher(parameters)
.add(value, name);
assert.strictEqual(newName, origName);
assert.strictEqual(parameters[newName], origValue);
assert.ok(!Object.hasOwn(parameters, name));const name = 'test';
const value = {
in: 'query',
};
const origName = 'unrelated';
const origValue = {
in: 'query',
'x-ms-parameter-location': 'client',
};
const parameters = { [origName]: origValue };
const newName = new MatchingParameterMatcher(parameters)
.add(value, name);
assert.strictEqual(newName, origName);
assert.strictEqual(parameters[newName], origValue);
assert.ok(!Object.hasOwn(parameters, name));const name = 'test';
const value = {
in: 'query',
'x-ms-parameter-location': 'client',
};
const origName = 'unrelated';
const origValue = {
in: 'query',
};
const parameters = { [origName]: origValue };
const newName = new MatchingParameterMatcher(parameters)
.add(value, name);
assert.strictEqual(newName, origName);
assert.strictEqual(parameters[newName], origValue);
assert.ok(!Object.hasOwn(parameters, name));const name = 'test';
const value = {
in: 'query',
};
const origName = 'unrelated';
const origValue = {
in: 'query',
'x-ms-parameter-location': 'method',
};
const parameters = { [origName]: origValue };
const newName = new MatchingParameterMatcher(parameters)
.add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(parameters[newName], value);
assert.strictEqual(parameters[origName], origValue);const name = 'test';
const value = {
in: 'query',
'x-ms-parameter-location': 'method',
};
const origName = 'unrelated';
const origValue = {
in: 'query',
};
const parameters = { [origName]: origValue };
const newName = new MatchingParameterMatcher(parameters)
.add(value, name);
assert.strictEqual(newName, name);
assert.strictEqual(parameters[newName], value);
assert.strictEqual(parameters[origName], origValue);assert.deepStrictEqual(
new MergeAllOfTransformer().transformOpenApi(deepFreeze(schema3(0))),
schema3(0),
);assert.deepStrictEqual(
new MergeAllOfTransformer().transformOpenApi(deepFreeze(schema3({
allOf: 123,
}))),
schema3({
allOf: 123,
}),
);assert.deepStrictEqual(
new MergeAllOfTransformer().transformOpenApi(deepFreeze(schema3({
allOf: [],
}))),
schema3({}),
);assert.deepStrictEqual(
new MergeAllOfTransformer().transformOpenApi(deepFreeze(schema3({
maximum: 5,
allOf: [
{ minimum: 3 },
],
}))),
schema3({
maximum: 5,
minimum: 3,
}),
);assert.deepStrictEqual(
new MergeAllOfTransformer().transformOpenApi(deepFreeze(schema3({
maximum: 5,
allOf: [
{
minimum: 3,
allOf: [
{ multipleOf: 2 },
],
},
],
}))),
schema3({
maximum: 5,
minimum: 3,
multipleOf: 2,
}),
);assert.deepStrictEqual(
new MergeAllOfTransformer({ onlySingle: true })
.transformOpenApi(deepFreeze(schema3({
maximum: 5,
allOf: [
{ minimum: 3 },
],
}))),
schema3({
maximum: 5,
minimum: 3,
}),
);assert.deepStrictEqual(
new MergeAllOfTransformer({ onlySingle: true })
.transformOpenApi(deepFreeze(schema3({
maximum: 5,
allOf: [
{ minimum: 3 },
{ multipleOf: 2 },
],
}))),
schema3({
maximum: 5,
allOf: [
{ minimum: 3 },
{ multipleOf: 2 },
],
}),
);assert.deepStrictEqual(
new MergeAnyOfTransformer().transformOpenApi(deepFreeze(schema3(0))),
schema3(0),
);assert.deepStrictEqual(
new MergeAnyOfTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: 123,
}))),
schema3({
anyOf: 123,
}),
);assert.deepStrictEqual(
new MergeAnyOfTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: [],
}))),
schema3({
anyOf: [],
}),
);assert.deepStrictEqual(
new MergeAnyOfTransformer().transformOpenApi(deepFreeze(schema3({
maximum: 5,
anyOf: [
{ minimum: 3 },
],
}))),
schema3({
maximum: 5,
minimum: 3,
}),
);assert.deepStrictEqual(
new MergeAnyOfTransformer().transformOpenApi(deepFreeze(schema3({
maximum: 5,
anyOf: [
{
minimum: 3,
anyOf: [
{ multipleOf: 2 },
],
},
],
}))),
schema3({
maximum: 5,
minimum: 3,
multipleOf: 2,
}),
);assert.throws(
() => new MergeAnyOfTransformer().transformOpenApi(deepFreeze(schema3({
anyOf: [
{ minimum: 3 },
{ multipleOf: 2 },
],
}))),
/not (?:implemented|supported)/i,
);assert.deepStrictEqual(
new MergeOneOfTransformer().transformOpenApi(deepFreeze(schema3(0))),
schema3(0),
);assert.deepStrictEqual(
new MergeOneOfTransformer().transformOpenApi(deepFreeze(schema3({
oneOf: 123,
}))),
schema3({
oneOf: 123,
}),
);assert.deepStrictEqual(
new MergeOneOfTransformer().transformOpenApi(deepFreeze(schema3({
oneOf: [],
}))),
schema3({
oneOf: [],
}),
);assert.deepStrictEqual(
new MergeOneOfTransformer().transformOpenApi(deepFreeze(schema3({
maximum: 5,
oneOf: [
{ minimum: 3 },
],
}))),
schema3({
maximum: 5,
minimum: 3,
}),
);assert.deepStrictEqual(
new MergeOneOfTransformer().transformOpenApi(deepFreeze(schema3({
maximum: 5,
oneOf: [
{
minimum: 3,
oneOf: [
{ multipleOf: 2 },
],
},
],
}))),
schema3({
maximum: 5,
minimum: 3,
multipleOf: 2,
}),
);assert.throws(
() => new MergeOneOfTransformer().transformOpenApi(deepFreeze(schema3({
oneOf: [
{ minimum: 3 },
{ multipleOf: 2 },
],
}))),
/not (?:implemented|supported)/i,
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema2({
type: 'object',
properties: {
name: {
type: 'string',
'x-nullable': true,
},
},
required: ['name'],
}))),
schema2({
type: 'object',
properties: {
name: {
type: 'string',
'x-nullable': true,
},
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
nullable: true,
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
required: ['name'],
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
additionalProperties: {
type: 'string',
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
additionalProperties: {
type: 'string',
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'null',
},
},
required: ['name'],
}, '3.1.0'))),
schema3({
type: 'object',
properties: {
name: {
type: 'null',
},
},
}, '3.1.0'),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: ['string', 'null'],
},
},
required: ['name'],
}, '3.1.0'))),
schema3({
type: 'object',
properties: {
name: {
type: ['string', 'null'],
},
},
}, '3.1.0'),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
additionalProperties: {
$ref: '#/components/schemas/MyString',
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
additionalProperties: {
$ref: '#/components/schemas/MyString',
},
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
nullable: true,
},
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
nullable: true,
},
},
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...swagger,
definitions: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/definitions/MyString',
'x-nullable': true,
},
},
required: ['name'],
},
},
})),
{
...swagger,
definitions: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/definitions/MyString',
'x-nullable': true,
},
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
allOf: [
{
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
},
],
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
allOf: [
{
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
},
],
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
required: ['name'],
}))),
schema3({
type: 'object',
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: undefined,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: undefined,
},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: null,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: null,
},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema2({
type: 'object',
properties: {
name: {
type: 'string',
'x-nullable': true,
},
},
required: ['name'],
}))),
schema2({
type: 'object',
properties: {
name: {
type: 'string',
'x-nullable': true,
},
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
nullable: true,
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
required: ['name'],
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
additionalProperties: {
type: 'string',
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
additionalProperties: {
type: 'string',
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'null',
},
},
required: ['name'],
}, '3.1.0'))),
schema3({
type: 'object',
properties: {
name: {
type: 'null',
},
},
}, '3.1.0'),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: ['string', 'null'],
},
},
required: ['name'],
}, '3.1.0'))),
schema3({
type: 'object',
properties: {
name: {
type: ['string', 'null'],
},
},
}, '3.1.0'),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
additionalProperties: {
$ref: '#/components/schemas/MyString',
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
additionalProperties: {
$ref: '#/components/schemas/MyString',
},
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
nullable: true,
},
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
nullable: true,
},
},
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...swagger,
definitions: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/definitions/MyString',
'x-nullable': true,
},
},
required: ['name'],
},
},
})),
{
...swagger,
definitions: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/definitions/MyString',
'x-nullable': true,
},
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
allOf: [
{
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
},
],
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
allOf: [
{
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
},
],
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
required: ['name'],
}))),
schema3({
type: 'object',
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: undefined,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: undefined,
},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: null,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: null,
},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema2({
type: 'object',
properties: {
name: {
type: 'string',
'x-nullable': true,
},
},
required: ['name'],
}))),
schema2({
type: 'object',
properties: {
name: {
type: 'string',
'x-nullable': true,
},
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
nullable: true,
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
required: ['name'],
}))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
additionalProperties: {
type: 'string',
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
additionalProperties: {
type: 'string',
},
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
nullable: true,
},
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'null',
},
},
required: ['name'],
}, '3.1.0'))),
schema3({
type: 'object',
properties: {
name: {
type: 'null',
},
},
}, '3.1.0'),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: ['string', 'null'],
},
},
required: ['name'],
}, '3.1.0'))),
schema3({
type: 'object',
properties: {
name: {
type: ['string', 'null'],
},
},
}, '3.1.0'),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
additionalProperties: {
$ref: '#/components/schemas/MyString',
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
additionalProperties: {
$ref: '#/components/schemas/MyString',
},
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
nullable: true,
},
},
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
nullable: true,
},
},
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...swagger,
definitions: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/definitions/MyString',
'x-nullable': true,
},
},
required: ['name'],
},
},
})),
{
...swagger,
definitions: {
MyString: {
type: 'string',
},
Test: {
type: 'object',
properties: {
name: {
$ref: '#/definitions/MyString',
'x-nullable': true,
},
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
allOf: [
{
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
},
],
required: ['name'],
},
},
},
})),
{
...openapi,
components: {
schemas: {
MyString: {
type: 'string',
},
Test: {
allOf: [
{
type: 'object',
properties: {
name: {
$ref: '#/components/schemas/MyString',
},
},
},
],
...requiredRef,
},
},
},
},
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
required: ['name'],
}))),
schema3({
type: 'object',
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: undefined,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: undefined,
},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: null,
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: null,
},
...requiredUnconstrained,
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
allOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
anyOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
required: ['name'],
}))),
schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableNotRequiredTransformer(options)
.transformOpenApi(deepFreeze(schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
required: ['name'],
}))),
schema3({
oneOf: [
{
type: 'object',
properties: {
name: {
type: 'string',
nullable: true,
},
},
},
{
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
],
}),
);assert.deepStrictEqual(
new NullableToTypeNullTransformer().transformOpenApi(deepFreeze(schema3({
type: 'number',
nullable: true,
}))),
schema3({
type: ['number', 'null'],
}),
);assert.deepStrictEqual(
new NullableToTypeNullTransformer().transformOpenApi(deepFreeze(schema3({
type: ['number', 'string'],
nullable: true,
}))),
schema3({
type: ['number', 'string', 'null'],
}),
);assert.deepStrictEqual(
new NullableToTypeNullTransformer().transformOpenApi(deepFreeze(schema3({
type: ['number', 'null'],
nullable: true,
}))),
schema3({
type: ['number', 'null'],
}),
);assert.deepStrictEqual(
new NullableToTypeNullTransformer().transformOpenApi(deepFreeze(schema3({
nullable: true,
}))),
schema3({}),
);assert.deepStrictEqual(
new NullableToTypeNullTransformer().transformOpenApi(deepFreeze(schema2({
type: 'number',
'x-nullable': true,
}))),
schema2({
type: ['number', 'null'],
}),
);assert.deepStrictEqual(
new NullableToTypeNullTransformer().transformOpenApi(deepFreeze(schema3({
type: 'number',
nullable: true,
'x-nullable': true,
}))),
schema3({
type: ['number', 'null'],
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
exclusiveMaximum: 24,
exclusiveMinimum: 0,
}, '3.1.0'))),
schema3({
exclusiveMaximum: true,
maximum: 24,
exclusiveMinimum: true,
minimum: 0,
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
type: 'null',
}, '3.1.0'))),
schema3({
enum: [null],
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
const: null,
}, '3.1.0'))),
schema3({
enum: [null],
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
type: 'null',
const: null,
}, '3.1.0'))),
schema3({
enum: [null],
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
type: ['number', 'null'],
}, '3.1.0'))),
schema3({
type: 'number',
nullable: true,
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
type: [
'array',
'boolean',
'number',
'object',
'string',
],
}, '3.1.0'))),
schema3({}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
type: [
'array',
'boolean',
'integer',
'null',
'number',
'object',
'string',
],
}, '3.1.0'))),
schema3({
nullable: true,
}),
);assert.deepStrictEqual(
new OpenApi31To30Transformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
patternProperties: {
'test.*': { type: 'string' },
},
}, '3.1.0'))),
schema3({
type: 'object',
additionalProperties: { type: 'string' },
}),
);assert.deepStrictEqual(
new PathParametersToOperationTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/': {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
head: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/': {
get: {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
head: {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new PathParametersToOperationTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/': {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
],
get: {
parameters: [
{
in: 'query',
name: 'myquery2',
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
head: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/': {
get: {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
{
in: 'query',
name: 'myquery2',
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
head: {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new PathParametersToOperationTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/': {
parameters: [
{
in: 'query',
name: 'myquery',
type: 'string',
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
head: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/': {
get: {
parameters: [
{
in: 'query',
name: 'myquery',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
head: {
parameters: [
{
in: 'query',
name: 'myquery',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);const transformer =
new PatternPropertiesToAdditionalPropertiesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
patternProperties: {},
}, '3.1.0'))),
schema3({
type: 'object',
}, '3.1.0'),
);const transformer =
new PatternPropertiesToAdditionalPropertiesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
patternProperties: {
'^value[0-9]+$': {
type: 'string',
},
},
}, '3.1.0'))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
}, '3.1.0'),
);const transformer =
new PatternPropertiesToAdditionalPropertiesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
patternProperties: {
'^string[0-9]+$': {
type: 'string',
},
'^number[0-9]+$': {
type: 'number',
},
'^bool[0-9]+$': {
type: 'boolean',
},
},
}, '3.1.0'))),
schema3({
type: 'object',
additionalProperties: {
anyOf: [
{ type: 'string' },
{ type: 'number' },
{ type: 'boolean' },
],
},
}, '3.1.0'),
);const transformer =
new PatternPropertiesToAdditionalPropertiesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
patternProperties: {
'^string[0-9]+$': {
type: 'string',
},
'^number[0-9]+$': {
type: 'number',
},
'^bool[0-9]+$': {
type: 'boolean',
},
},
additionalProperties: {
type: 'object',
},
}, '3.1.0'))),
schema3({
type: 'object',
additionalProperties: {
anyOf: [
{ type: 'string' },
{ type: 'number' },
{ type: 'boolean' },
{ type: 'object' },
],
},
}, '3.1.0'),
);const transformer =
new PatternPropertiesToAdditionalPropertiesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
patternProperties: {
'^shortName[0-9]+$': {
type: 'string',
},
'^longName[0-9]+$': {
type: 'string',
},
},
additionalProperties: {
type: 'string',
},
}, '3.1.0'))),
schema3({
type: 'object',
additionalProperties: {
type: 'string',
},
}, '3.1.0'),
);assert.deepStrictEqual(
new QueriesToXMsPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/a?foo=bar': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
'x-ms-paths': {
'/a?foo=bar': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new QueriesToXMsPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new QueriesToXMsPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?foo=bar': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {},
'x-ms-paths': {
'/a?foo=bar': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new QueriesToXMsPathsTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/a?foo=bar': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
'x-ms-paths': {
'/a?foo=bar': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.throws(
() => new ReadOnlyNotRequiredTransformer(null),
TypeError,
);assert.throws(
() => new ReadOnlyNotRequiredTransformer({ removeValidation: 1 }),
TypeError,
);assert.throws(
() => new ReadOnlyNotRequiredTransformer({ setNonNullable: 1 }),
TypeError,
);const transformer = new ReadOnlyNotRequiredTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
},
},
}),
);const transformer = new ReadOnlyNotRequiredTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
minLength: 1,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
minLength: 1,
},
},
}),
);const transformer = new ReadOnlyNotRequiredTransformer({
removeValidation: true,
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
minLength: 1,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
},
},
}),
);const transformer = new ReadOnlyNotRequiredTransformer({
setNonNullable: true,
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
},
},
required: ['name'],
}))),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
readOnly: true,
'x-nullable': false,
},
},
}),
);assert.deepStrictEqual(
new RefPathParametersTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/': {
parameters: [
{
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {
parameters: {
myquery: {
in: 'query',
name: 'myquery',
schema: {
type: 'string',
},
},
},
},
paths: {
'/': {
parameters: [
{ $ref: '#/components/parameters/myquery' },
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RefPathParametersTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/': {
parameters: [
{
in: 'query',
name: 'myquery',
type: 'string',
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
parameters: {
myquery: {
in: 'query',
name: 'myquery',
type: 'string',
},
},
paths: {
'/': {
parameters: [
{ $ref: '#/parameters/myquery' },
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);const transformer = new RemoveDefaultOnlyResponseProducesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(get2({
produces: [
'text/plain',
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
}))),
get2({
produces: [],
responses: {
default: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
}),
);const transformer = new RemoveDefaultOnlyResponseProducesTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(get2({
produces: [
'text/plain',
],
responses: {
200: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
}))),
get2({
produces: [
'text/plain',
],
responses: {
200: {
description: 'Example response',
schema: {
type: 'file',
},
},
},
}),
);assert.deepStrictEqual(
new RemovePathsWithServersTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
servers: [
{ url: 'https://example.com' },
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/b': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/b': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemovePathsWithServersTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{ url: 'https://example.com' },
],
paths: {
'/a': {
servers: [],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/b': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
servers: [
{ url: 'https://example.com' },
],
paths: {
'/b': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
openapi: '3.1.0',
paths: {
'/a?': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
openapi: '3.1.0',
paths: {
'/a': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?b={b}': {
parameters: [
{
name: 'b',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?b={b}': {
get: {
parameters: [
{
name: 'b',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
get: {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?b={c}': {
parameters: [
{
name: 'c',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?b={c}': {
parameters: [
{
name: 'c',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'number',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'number',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
openapi: '3.1.0',
paths: {
'/a?b=c': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
openapi: '3.1.0',
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
const: 'c',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?b=c': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
enum: ['c'],
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/a?b=c': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
type: 'string',
enum: ['c'],
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
openapi: '3.1.0',
paths: {
'/a?b': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
openapi: '3.1.0',
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
const: '',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
openapi: '3.1.0',
paths: {
'/a?=c': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
openapi: '3.1.0',
paths: {
'/a': {
parameters: [
{
name: '',
in: 'query',
required: true,
schema: {
const: 'c',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
openapi: '3.1.0',
paths: {
'/a?=': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
openapi: '3.1.0',
paths: {
'/a': {
parameters: [
{
name: '',
in: 'query',
required: true,
schema: {
const: '',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
openapi: '3.1.0',
paths: {
'/a?b=c': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'number',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
openapi: '3.1.0',
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'number',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a?b={c}&d={c}': {
parameters: [
{
name: 'c',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
{
name: 'd',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/{a}?b={c}': {
parameters: [
{
name: 'a',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
{
name: 'c',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/{a}': {
parameters: [
{
name: 'a',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/{a}?b={a}': {
parameters: [
{
name: 'a',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/{a}': {
parameters: [
{
name: 'a',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
delete: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/a?': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
delete: {
responses: {
204: {
description: 'Example response',
},
},
},
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
delete: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/a?b={c}': {
parameters: [
{
name: 'c',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
delete: {
responses: {
204: {
description: 'Example response',
},
},
},
get: {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveQueryFromPathsTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/a': {
parameters: [
{
name: 'd',
in: 'cookie',
schema: {
type: 'string',
},
},
],
delete: {
responses: {
204: {
description: 'Example response',
},
},
},
},
'/a?b={c}': {
parameters: [
{
name: 'c',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/a': {
delete: {
parameters: [
{
name: 'd',
in: 'cookie',
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
get: {
parameters: [
{
name: 'b',
in: 'query',
required: true,
schema: {
type: 'string',
},
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.throws(
() => new RemoveRefSiblingsTransformer(null),
TypeError,
);assert.throws(
() => new RemoveRefSiblingsTransformer({ remove: 1 }),
TypeError,
);assert.throws(
() => new RemoveRefSiblingsTransformer({ retain: 1 }),
TypeError,
);assert.throws(
() => new RemoveRefSiblingsTransformer({
remove: [],
retain: [],
}),
Error,
);const transformer = new RemoveRefSiblingsTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
}))),
schema3({
$ref: '#/components/schemas/Test',
}),
);const transformer = new RemoveRefSiblingsTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'number',
}))),
schema3({
type: 'number',
}),
);const transformer = new RemoveRefSiblingsTransformer();
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3(null))),
schema3(null),
);const transformer = new RemoveRefSiblingsTransformer({
remove: ['required'],
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
}))),
schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
}),
);const transformer = new RemoveRefSiblingsTransformer({
retain: ['required'],
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
}))),
schema3({
$ref: '#/components/schemas/Test',
required: ['name'],
}),
);const transformer = new RemoveRefSiblingsTransformer({
remove: (propName) => propName === 'required',
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
}))),
schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
}),
);const transformer = new RemoveRefSiblingsTransformer({
retain: (propName) => propName === 'required',
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
}))),
schema3({
$ref: '#/components/schemas/Test',
required: ['name'],
}),
);const transformer = new RemoveRefSiblingsTransformer({
remove: (propName) => {
assert.notStrictEqual(propName, '$ref');
return false;
},
});
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
})));const transformer = new RemoveRefSiblingsTransformer({
retain: (propName) => {
assert.notStrictEqual(propName, '$ref');
return false;
},
});
transformer.transformOpenApi(deepFreeze(schema3({
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
})));// eslint-disable-next-line unicorn/consistent-function-scoping
function retain(propName) {
return propName !== 'required';
}
const transformer = new RemoveRefSiblingsTransformer({ retain });
const origSchema = {
title: 'Test',
description: 'Test',
$ref: '#/components/schemas/Test',
required: ['name'],
};
const openapi =
transformer.transformOpenApi(deepFreeze(schema3(origSchema)));
const newSchema = openapi.components.schemas.Test;
assert.deepStrictEqual(
Object.keys(origSchema).filter(retain),
Object.keys(newSchema),
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
pathItems: {
Example: {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
pathItems: {
Example: {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
pathItems: {
Example: {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
pathItems: {
Example: {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
pathItems: {
Example: {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
pathItems: {
Example: {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
pathItems: {
Example: {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
pathItems: {
Example: {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
pathItems: {
Example: {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
pathItems: {
Example: {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
pathItems: {
Example: {
[method]: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
})),
{
...openapi,
components: {
pathItems: {
Example: {
[method]: {
responses: {
204: {
description: 'Example response',
},
},
},
post: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
paths: {},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'body',
schema: {
type: 'object',
},
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...swagger,
paths: {
'/test': {
[method]: {
parameters: [
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
post: {
parameters: [
{
name: 'test',
in: 'formData',
type: 'string',
},
{
name: 'test2',
in: 'query',
type: 'string',
},
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer().transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
delete: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
delete: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.throws(
() => new RemoveRequestBodyTransformer(1),
TypeError,
);assert.deepStrictEqual(
new RemoveRequestBodyTransformer(['delete']).transformOpenApi(deepFreeze({
...openapi,
paths: {
'/test': {
delete: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
get: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
paths: {
'/test': {
delete: {
responses: {
204: {
description: 'Example response',
},
},
},
get: {
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveResponseHeadersTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
responses: {
myresponse: {
description: 'Example response',
headers: {
'X-Foo': {
type: 'string',
pattern: '^foo',
},
},
},
},
},
paths: {
'/': {
get: {
responses: {
204: {
$ref: '#/components/responses/myresponse',
},
},
},
},
},
})),
{
...openapi,
components: {
responses: {
myresponse: {
description: 'Example response',
},
},
},
paths: {
'/': {
get: {
responses: {
204: {
$ref: '#/components/responses/myresponse',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveResponseHeadersTransformer().transformOpenApi(deepFreeze({
...openapi,
components: {
headers: {
myheader: {
type: 'string',
pattern: '^foo',
},
},
responses: {
myresponse: {
description: 'Example response',
headers: {
'X-Foo': {
$ref: '#/components/headers/myheader',
},
},
},
},
},
paths: {
'/': {
get: {
responses: {
204: {
$ref: '#/components/responses/myresponse',
},
},
},
},
},
})),
{
...openapi,
components: {
headers: {
myheader: {
type: 'string',
pattern: '^foo',
},
},
responses: {
myresponse: {
description: 'Example response',
},
},
},
paths: {
'/': {
get: {
responses: {
204: {
$ref: '#/components/responses/myresponse',
},
},
},
},
},
},
);assert.deepStrictEqual(
new RemoveResponseHeadersTransformer().transformOpenApi(deepFreeze(get3({
responses: {
204: {
description: 'Example response',
headers: {
'X-Foo': {
type: 'string',
pattern: '^foo',
},
},
},
},
}))),
get3({
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.deepStrictEqual(
new RemoveResponseHeadersTransformer().transformOpenApi(deepFreeze(get2({
responses: {
204: {
description: 'Example response',
headers: {
'X-Foo': {
type: 'string',
pattern: '^foo',
},
},
},
},
}))),
get2({
responses: {
204: {
description: 'Example response',
},
},
}),
);assert.throws(
() => new RemoveSecuritySchemeIfTransformer(),
TypeError,
);assert.throws(
() => new RemoveSecuritySchemeIfTransformer(true),
TypeError,
);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: { myScheme },
},
paths: {},
})),
{
...openapi,
components: {},
paths: {},
},
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
const otherScheme = { type: 'apiKey', name: 'test2', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: {
myScheme,
otherScheme,
},
},
paths: {},
})),
{
...openapi,
components: {
securitySchemes: {
otherScheme,
},
},
paths: {},
},
);
assert.strictEqual(predicateCallCount, 2);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: {
myScheme,
},
},
security: [
{ myScheme: [] },
],
paths: {},
})),
{
...openapi,
components: {},
paths: {},
},
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: {
myScheme,
},
},
paths: {
'/': {
get: {
operationId: 'getRoot',
security: [
{ myScheme: [] },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
components: {},
paths: {
'/': {
get: {
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
const otherScheme = { type: 'apiKey', name: 'test2', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: {
myScheme,
otherScheme,
},
},
security: [
{ myScheme: [] },
{ otherScheme: [] },
],
paths: {},
})),
{
...openapi,
components: {
securitySchemes: {
otherScheme,
},
},
security: [
{ otherScheme: [] },
],
paths: {},
},
);
assert.strictEqual(predicateCallCount, 2);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
const otherScheme = { type: 'apiKey', name: 'test2', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: {
myScheme,
otherScheme,
},
},
security: [
{
myScheme: [],
otherScheme: [],
},
],
paths: {},
})),
{
...openapi,
components: {
securitySchemes: {
otherScheme,
},
},
security: [
{ otherScheme: [] },
],
paths: {},
},
);
assert.strictEqual(predicateCallCount, 2);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...openapi,
components: {
securitySchemes: {
myScheme,
},
},
security: [
{ myScheme: [] },
{},
],
paths: {},
})),
{
...openapi,
components: {},
security: [
{},
],
paths: {},
},
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
},
paths: {},
})),
{
...swagger,
paths: {},
},
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
const otherScheme = { type: 'apiKey', name: 'test2', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
otherScheme,
},
paths: {},
})),
{
...swagger,
securityDefinitions: {
otherScheme,
},
paths: {},
},
);
assert.strictEqual(predicateCallCount, 2);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
},
security: [
{ myScheme: [] },
],
paths: {},
})),
{
...swagger,
paths: {},
},
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
},
paths: {
'/': {
get: {
operationId: 'getRoot',
security: [
{ myScheme: [] },
],
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
get2({
operationId: 'getRoot',
responses: {
204: {
description: 'Example response',
},
},
}),
);
assert.strictEqual(predicateCallCount, 1);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
const otherScheme = { type: 'apiKey', name: 'test2', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
otherScheme,
},
security: [
{ myScheme: [] },
{ otherScheme: [] },
],
paths: {},
})),
{
...swagger,
securityDefinitions: {
otherScheme,
},
security: [
{ otherScheme: [] },
],
paths: {},
},
);
assert.strictEqual(predicateCallCount, 2);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
const otherScheme = { type: 'apiKey', name: 'test2', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
otherScheme,
},
security: [
{
myScheme: [],
otherScheme: [],
},
],
paths: {},
})),
{
...swagger,
securityDefinitions: {
otherScheme,
},
security: [
{ otherScheme: [] },
],
paths: {},
},
);
assert.strictEqual(predicateCallCount, 2);const myScheme = { type: 'apiKey', name: 'test', in: 'query' };
let predicateCallCount = 0;
assert.deepStrictEqual(
new RemoveSecuritySchemeIfTransformer((securityScheme) => {
predicateCallCount += 1;
return securityScheme === myScheme;
}).transformOpenApi(deepFreeze({
...swagger,
securityDefinitions: {
myScheme,
},
security: [
{ myScheme: [] },
{},
],
paths: {},
})),
{
...swagger,
security: [
{},
],
paths: {},
},
);
assert.strictEqual(predicateCallCount, 1);assert.throws(
() => new RemoveTypeIfTransformer(),
TypeError,
);assert.throws(
() => new RemoveTypeIfTransformer({}),
TypeError,
);// eslint-disable-next-line no-use-before-define
const transformer = new RemoveTypeIfTransformer(predicate);
const type1 = ['boolean'];
const type2 = 'number';
let callCount = 0;
function predicate(type) {
callCount += 1;
assert.strictEqual(this, transformer);
assert.ok(type === type1 || type === type2);
return type === type1;
}
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
Example1: {
type: type1,
},
Example2: {
type: type2,
},
},
},
paths: {},
})),
{
...openapi,
components: {
schemas: {
Example1: {},
Example2: {
type: type2,
},
},
},
paths: {},
},
);
assert.strictEqual(callCount, 2);// eslint-disable-next-line no-use-before-define
const transformer = new RemoveTypeIfTransformer(predicate);
const type1 = ['boolean'];
const type2 = 'number';
let callCount = 0;
function predicate(type) {
callCount += 1;
assert.strictEqual(this, transformer);
assert.ok(type === type1 || type === type2);
return type === type1 ? 1 : 0;
}
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
Example1: {
type: type1,
},
Example2: {
type: type2,
},
},
},
paths: {},
})),
{
...openapi,
components: {
schemas: {
Example1: {},
Example2: {
type: type2,
},
},
},
paths: {},
},
);
assert.strictEqual(callCount, 2);assert.deepStrictEqual(
new RemoveTypeIfTransformer(assert.fail).transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
Example1: {},
Example2: {
type: undefined,
},
},
},
paths: {},
})),
{
...openapi,
components: {
schemas: {
Example1: {},
Example2: {
type: undefined,
},
},
},
paths: {},
},
);const transformer = new RemoveTypeIfTransformer(allNonNullTypes);
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: ['array', 'boolean', 'number', 'object', 'string'],
}, '3.1.0'))),
schema3({}, '3.1.0'),
);const transformer = new RemoveTypeIfTransformer(allNonNullTypes);
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: [
'array',
'boolean',
'integer',
'null',
'number',
'object',
'string',
],
}, '3.1.0'))),
schema3({}, '3.1.0'),
);const transformer = new RemoveTypeIfTransformer(allNonNullTypes);
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: 'boolean',
}, '3.1.0'))),
schema3({
type: 'boolean',
}, '3.1.0'),
);const transformer = new RemoveTypeIfTransformer(allNonNullTypes);
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: [
'boolean',
'integer',
'null',
'number',
'object',
'string',
],
}, '3.1.0'))),
schema3({
type: [
'boolean',
'integer',
'null',
'number',
'object',
'string',
],
}, '3.1.0'),
);const transformer = new RemoveTypeIfTransformer(allNonNullTypes);
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: [
'array',
'boolean',
'integer',
'null',
'number',
'object',
'string',
'array',
'number',
],
}, '3.1.0'))),
schema3({}, '3.1.0'),
);const transformer = new RemoveTypeIfTransformer(allNonNullTypes);
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(schema3({
type: [
'array',
'boolean',
'integer',
'null',
'object',
'string',
'integer',
],
}, '3.1.0'))),
schema3({
type: [
'array',
'boolean',
'integer',
'null',
'object',
'string',
'integer',
],
}, '3.1.0'),
);assert.throws(
() => new RenameComponentsTransformer(null),
TypeError,
);assert.throws(
() => new RenameComponentsTransformer(1),
TypeError,
);assert.throws(
() => new RenameComponentsTransformer({ schemas: 1 }),
TypeError,
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'ResponseType' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
ResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/ResponseType',
},
},
},
},
},
},
},
},
})),
{
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
NewResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/NewResponseType',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'ResponseType' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
ResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
prop1: 'foo',
$ref: '#/components/schemas/RequestType',
prop2: 'bar',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
prop3: 'baz',
$ref: '#/components/schemas/ResponseType',
prop4: 'quux',
},
},
},
},
},
},
},
},
})),
{
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
NewResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
prop1: 'foo',
$ref: '#/components/schemas/RequestType',
prop2: 'bar',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
prop3: 'baz',
$ref: '#/components/schemas/NewResponseType',
prop4: 'quux',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'ResponseType' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
ResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/RequestType2',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/ResponseType2',
},
},
},
},
},
},
},
},
})),
{
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
NewResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/RequestType2',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/ResponseType2',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'ResponseType' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze(post3({
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '##',
},
},
},
},
},
}))),
post3({
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '##',
},
},
},
},
},
}),
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'ResponseType' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
ResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: 'remote.json#/components/schemas/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: 'remote.json#/components/schemas/ResponseType',
},
},
},
},
},
},
},
},
})),
{
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
NewResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: 'remote.json#/components/schemas/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: 'remote.json#/components/schemas/ResponseType',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'Response~Type#2' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
'Response~Type#2': {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Response~0Type%232',
},
},
},
},
},
},
},
},
})),
{
...openapi,
components: {
schemas: {
RequestType: {
type: 'object',
},
'NewResponse~Type#2': {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/NewResponse~0Type%232',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => `New${name}2`,
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
schemas: {
ResponseType: {
type: 'object',
properties: {
request: {
type: 'object',
},
},
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref:
'#/components/schemas/ResponseType/properties/request',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/ResponseType',
},
},
},
},
},
},
},
},
})),
{
...openapi,
components: {
schemas: {
NewResponseType2: {
type: 'object',
properties: {
request: {
type: 'object',
},
},
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/NewResponseType2'
+ '/properties/request',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/NewResponseType2',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => `New${name}`,
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
'x-stuff': {
RequestType: {
type: 'object',
},
},
components: {
myschemas: {
ResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/x-stuff/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/myschemas/ResponseType',
},
},
},
},
},
},
},
},
})),
{
...openapi,
'x-stuff': {
RequestType: {
type: 'object',
},
},
components: {
myschemas: {
ResponseType: {
type: 'object',
},
},
},
paths: {
'/': {
post: {
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/x-stuff/RequestType',
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
$ref: '#/components/myschemas/ResponseType',
},
},
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => (name === 'ResponseType' ? `New${name}` : name),
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...swagger,
definitions: {
RequestType: {
type: 'object',
},
ResponseType: {
type: 'object',
},
},
paths: {
'/': {
post: {
parameters: [
{
in: 'body',
name: 'body',
schema: {
$ref: '#/definitions/RequestType',
},
},
],
responses: {
default: {
description: 'Example response',
schema: {
$ref: '#/definitions/ResponseType',
},
},
},
},
},
},
})),
{
...swagger,
definitions: {
RequestType: {
type: 'object',
},
NewResponseType: {
type: 'object',
},
},
paths: {
'/': {
post: {
parameters: [
{
in: 'body',
name: 'body',
schema: {
$ref: '#/definitions/RequestType',
},
},
],
responses: {
default: {
description: 'Example response',
schema: {
$ref: '#/definitions/NewResponseType',
},
},
},
},
},
},
},
);const transformer = new RenameComponentsTransformer({
schemas: (name) => 'renamed',
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
components: {
responses: {
myresponse: {
description: 'Example response',
},
},
},
paths: {
'/': {
get: {
responses: {
204: {
$ref: '#/components/responses/myresponse',
},
},
},
},
},
})),
{
...openapi,
components: {
responses: {
myresponse: {
description: 'Example response',
},
},
},
paths: {
'/': {
get: {
responses: {
204: {
$ref: '#/components/responses/myresponse',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ReplacedByToDescriptionTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'object',
'x-deprecated': {
'replaced-by': 'Example2',
},
}),
)),
schema3({
type: 'object',
'x-deprecated': {
description: 'Use Example2 instead.',
'replaced-by': 'Example2',
},
}),
);assert.deepStrictEqual(
new ReplacedByToDescriptionTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'object',
'x-deprecated': {
description: 'Use something else. Anything.',
'replaced-by': 'Example2',
},
}),
)),
schema3({
type: 'object',
'x-deprecated': {
description: 'Use something else. Anything.',
'replaced-by': 'Example2',
},
}),
);assert.deepStrictEqual(
new ReplacedByToDescriptionTransformer().transformOpenApi(deepFreeze(
schema3({
type: 'object',
properties: {
name: {
type: 'string',
'x-deprecated': {
'replaced-by': 'name2',
},
},
},
}),
)),
schema3({
type: 'object',
properties: {
name: {
type: 'string',
'x-deprecated': {
description: 'Use name2 instead.',
'replaced-by': 'name2',
},
},
},
}),
);assert.throws(
() => new ServerVarsToPathParamsTransformer(null),
TypeError,
);assert.throws(
() => new ServerVarsToPathParamsTransformer({ omitDefault: {} }),
TypeError,
);assert.deepStrictEqual(
new ServerVarsToPathParamsTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: 'https://example.com/{foo}',
variables: {
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
],
paths: {
'/': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
servers: [
{
url: 'https://example.com',
},
],
components: {
parameters: {
foo: {
in: 'path',
name: 'foo',
required: true,
schema: {
type: 'string',
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
},
paths: {
'/{foo}/': {
parameters: [
{ $ref: '#/components/parameters/foo' },
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);const transformer =
new ServerVarsToPathParamsTransformer({ omitDefault: ['foo'] });
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: 'https://example.com/{foo}',
variables: {
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
],
paths: {
'/': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
servers: [
{
url: 'https://example.com',
},
],
components: {
parameters: {
foo: {
in: 'path',
name: 'foo',
required: true,
schema: {
type: 'string',
enum: ['bar', 'baz'],
},
},
},
},
paths: {
'/{foo}/': {
parameters: [
{ $ref: '#/components/parameters/foo' },
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.deepStrictEqual(
new ServerVarsToPathParamsTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: 'https://example.{domain}/{foo}',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
],
paths: {
'/': {
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
})),
{
...openapi,
servers: [
{
url: 'https://example.{domain}',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
},
},
],
components: {
parameters: {
foo: {
in: 'path',
name: 'foo',
required: true,
schema: {
type: 'string',
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
},
paths: {
'/{foo}/': {
parameters: [
{ $ref: '#/components/parameters/foo' },
],
get: {
responses: {
204: {
description: 'Example response',
},
},
},
},
},
},
);assert.throws(
() => new ServerVarsToParamHostTransformer(null),
TypeError,
);assert.throws(
() => new ServerVarsToParamHostTransformer({ omitDefault: {} }),
TypeError,
);assert.throws(
() => new ServerVarsToParamHostTransformer({ parameter: 1 }),
TypeError,
);assert.throws(
() => new ServerVarsToParamHostTransformer({ xMsParameterizedHost: 1 }),
TypeError,
);assert.deepStrictEqual(
new ServerVarsToParamHostTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: 'https://example.{domain}/foo',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
},
},
],
paths: {},
})),
{
...openapi,
servers: [
{
url: 'https://example.{domain}/foo',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
},
},
],
'x-ms-parameterized-host': {
hostTemplate: 'example.{domain}',
useSchemePrefix: true,
parameters: [
{
in: 'path',
name: 'domain',
required: true,
type: 'string',
enum: ['com', 'org'],
default: 'org',
},
],
},
paths: {},
},
);assert.deepStrictEqual(
new ServerVarsToParamHostTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: 'https://example.com/{foo}',
variables: {
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
],
paths: {},
})),
{
...openapi,
servers: [
{
url: 'https://example.com/{foo}',
variables: {
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
},
},
],
paths: {},
},
);assert.deepStrictEqual(
new ServerVarsToParamHostTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: '{scheme}://example.{domain}/foo',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
scheme: {
enum: ['https', 'http'],
default: 'https',
},
},
},
],
paths: {},
})),
{
...openapi,
servers: [
{
url: '{scheme}://example.{domain}/foo',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
scheme: {
enum: ['https', 'http'],
default: 'https',
},
},
},
],
'x-ms-parameterized-host': {
hostTemplate: '{scheme}://example.{domain}',
useSchemePrefix: false,
parameters: [
{
in: 'path',
name: 'scheme',
required: true,
type: 'string',
enum: ['https', 'http'],
default: 'https',
},
{
in: 'path',
name: 'domain',
required: true,
type: 'string',
enum: ['com', 'org'],
default: 'org',
},
],
},
paths: {},
},
);assert.deepStrictEqual(
new ServerVarsToParamHostTransformer().transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: '{scheme}://example.{domain}/{foo}',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
scheme: {
enum: ['https', 'http'],
default: 'https',
},
},
},
],
paths: {},
})),
{
...openapi,
servers: [
{
url: '{scheme}://example.{domain}/{foo}',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
foo: {
enum: ['bar', 'baz'],
default: 'bar',
},
scheme: {
enum: ['https', 'http'],
default: 'https',
},
},
},
],
'x-ms-parameterized-host': {
hostTemplate: '{scheme}://example.{domain}',
useSchemePrefix: false,
parameters: [
{
in: 'path',
name: 'scheme',
required: true,
type: 'string',
enum: ['https', 'http'],
default: 'https',
},
{
in: 'path',
name: 'domain',
required: true,
type: 'string',
enum: ['com', 'org'],
default: 'org',
},
],
},
paths: {},
},
);const transformer = new ServerVarsToParamHostTransformer({
parameter: {
'x-ms-parameter-location': 'client',
},
});
assert.deepStrictEqual(
transformer.transformOpenApi(deepFreeze({
...openapi,
servers: [
{
url: 'https://example.{domain}/foo',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
},
},
],
paths: {},
})),
{
...openapi,
servers: [
{
url: 'https://example.{domain}/foo',
variables: {
domain: {
enum: ['com', 'org'],
default: 'org',
},
},
},
],
'x-ms-parameterized-host': {
hostTemplate: 'example.{domain}',
useSchemePrefix: true,
parameters: [
{
in: 'path',
name: 'domain',
required: true,
type: 'string',
enum: ['com', 'org'],
default: 'org',
'x-ms-parameter-location': 'client',
},
],
},
paths: {},
},
);assert.deepStrictEqual(
new TypeNullToEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: 'null',
}, '3.1.0'))),
schema3({
enum: [null],
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: ['null'],
}, '3.1.0'))),
schema3({
enum: [null],
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: ['null', 'number'],
}, '3.1.0'))),
schema3({
type: ['null', 'number'],
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: 'null',
enum: [null],
}, '3.1.0'))),
schema3({
enum: [null],
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
type: ['null', 'number'],
}, '3.1.0'))),
schema3({
type: 'number',
nullable: true,
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
type: ['number', 'null', 'string'],
}, '3.1.0'))),
schema3({
type: ['number', 'string'],
nullable: true,
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
type: ['null', 'number'],
nullable: true,
}, '3.1.0'))),
schema3({
type: 'number',
nullable: true,
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
type: ['number', 'string'],
}, '3.1.0'))),
schema3({
type: ['number', 'string'],
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
type: 'null',
}, '3.1.0'))),
schema3({
type: 'null',
}, '3.1.0'),
);assert.deepStrictEqual(
new TypeNullToNullableTransformer().transformOpenApi(deepFreeze(schema3({
type: ['null'],
}, '3.1.0'))),
schema3({
type: ['null'],
}, '3.1.0'),
);assert.deepStrictEqual(
new UrlencodedToStringTransformer().transformOpenApi(deepFreeze(post3({
requestBody: {
content: {
'application/x-www-form-urlencoded': {
schema: {
type: 'object',
properties: {
name: {
type: 'string',
},
hp: {
type: 'integer',
},
speed: {
type: 'number',
},
inverted: {
type: 'boolean',
},
},
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
}))),
post3({
requestBody: {
content: {
'application/x-www-form-urlencoded': {
schema: {
type: 'object',
properties: {
name: {
type: 'string',
},
hp: {
type: 'string',
},
speed: {
type: 'string',
},
inverted: {
type: 'string',
},
},
},
},
},
},
responses: {
default: {
description: 'Example response',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
}),
);assert.deepStrictEqual(
new UrlencodedToStringTransformer().transformOpenApi(deepFreeze({
...swagger,
produces: ['application/json'],
paths: {
'/': {
post: {
consumes: ['application/x-www-form-urlencoded'],
parameters: [
{
name: 'name',
in: 'formData',
type: 'string',
},
{
name: 'hp',
in: 'formData',
type: 'integer',
},
{
name: 'speed',
in: 'formData',
type: 'number',
},
{
name: 'inverted',
in: 'formData',
type: 'boolean',
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
})),
{
...swagger,
produces: ['application/json'],
paths: {
'/': {
post: {
consumes: ['application/x-www-form-urlencoded'],
parameters: [
{
name: 'name',
in: 'formData',
type: 'string',
},
{
name: 'hp',
in: 'formData',
type: 'string',
},
{
name: 'speed',
in: 'formData',
type: 'string',
},
{
name: 'inverted',
in: 'formData',
type: 'string',
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
},
);assert.deepStrictEqual(
new UrlencodedToStringTransformer().transformOpenApi(deepFreeze({
...swagger,
produces: ['application/json'],
consumes: ['application/x-www-form-urlencoded'],
paths: {
'/': {
post: {
parameters: [
{
name: 'name',
in: 'formData',
type: 'string',
},
{
name: 'hp',
in: 'formData',
type: 'integer',
},
{
name: 'speed',
in: 'formData',
type: 'number',
},
{
name: 'inverted',
in: 'formData',
type: 'boolean',
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
})),
{
...swagger,
produces: ['application/json'],
consumes: ['application/x-www-form-urlencoded'],
paths: {
'/': {
post: {
parameters: [
{
name: 'name',
in: 'formData',
type: 'string',
},
{
name: 'hp',
in: 'formData',
type: 'string',
},
{
name: 'speed',
in: 'formData',
type: 'string',
},
{
name: 'inverted',
in: 'formData',
type: 'string',
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
},
);assert.deepStrictEqual(
new UrlencodedToStringTransformer().transformOpenApi(deepFreeze({
...swagger,
produces: ['application/json'],
consumes: ['application/x-www-form-urlencoded'],
paths: {
'/': {
post: {
parameters: [
{
name: 'whatever',
in: 'body',
schema: {
type: 'object',
properties: {
name: {
type: 'string',
},
hp: {
type: 'integer',
},
speed: {
type: 'number',
},
inverted: {
type: 'boolean',
},
},
},
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
})),
{
...swagger,
produces: ['application/json'],
consumes: ['application/x-www-form-urlencoded'],
paths: {
'/': {
post: {
parameters: [
{
name: 'whatever',
in: 'body',
schema: {
type: 'object',
properties: {
name: {
type: 'string',
},
hp: {
type: 'string',
},
speed: {
type: 'string',
},
inverted: {
type: 'string',
},
},
},
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
},
);assert.deepStrictEqual(
new UrlencodedToStringTransformer().transformOpenApi(deepFreeze({
...swagger,
produces: ['application/json'],
paths: {
'/': {
post: {
consumes: [
'application/x-www-form-urlencoded',
'multipart/form-data',
],
parameters: [
{
name: 'name',
in: 'formData',
type: 'string',
},
{
name: 'hp',
in: 'formData',
type: 'integer',
},
{
name: 'speed',
in: 'formData',
type: 'number',
},
{
name: 'inverted',
in: 'formData',
type: 'boolean',
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
})),
{
...swagger,
produces: ['application/json'],
paths: {
'/': {
post: {
consumes: [
'application/x-www-form-urlencoded',
'multipart/form-data',
],
parameters: [
{
name: 'name',
in: 'formData',
type: 'string',
},
{
name: 'hp',
in: 'formData',
type: 'integer',
},
{
name: 'speed',
in: 'formData',
type: 'number',
},
{
name: 'inverted',
in: 'formData',
type: 'boolean',
},
],
responses: {
default: {
description: 'Example response',
schema: {
type: 'object',
properties: {
newSpeed: {
type: 'number',
},
},
},
},
},
},
},
},
},
);assert.deepStrictEqual(
new XEnumToXMsEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
}))),
schema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-ms-enum': {
name: 'Test',
values: [
{
value: 'value1',
description: 'Description 1',
name: 'Var1',
},
{
value: 'value2',
description: 'Description 2',
name: 'Var2',
},
],
},
}),
);assert.deepStrictEqual(
new XEnumToXMsEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
},
},
}))),
schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
},
},
}),
);assert.deepStrictEqual(
new XEnumToXMsEnumTransformer().transformOpenApi(deepFreeze(
responseSchema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
}),
)),
responseSchema3({
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
}),
);assert.deepStrictEqual(
new XEnumToXMsEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
'x-ms-enum': {
name: 'Test',
},
},
},
}))),
schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
enum: [
'value1',
'value2',
],
'x-ms-enum': {
name: 'Test',
values: [
{
value: 'value1',
description: 'Description 1',
name: 'Var1',
},
{
value: 'value2',
description: 'Description 2',
name: 'Var2',
},
],
},
},
},
}),
);assert.deepStrictEqual(
new XEnumToXMsEnumTransformer().transformOpenApi(deepFreeze(schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
'x-ms-enum': {
name: 'Test',
values: [
{
value: 'value1',
description: 'MS Description 1',
name: 'MsVar1',
},
{
value: 'value2',
description: 'MS Description 2',
name: 'MsVar2',
},
],
},
},
},
}))),
schema3({
type: 'object',
properties: {
myprop: {
type: 'string',
enum: [
'value1',
'value2',
],
'x-enum-descriptions': [
'Description 1',
'Description 2',
],
'x-enum-varnames': [
'Var1',
'Var2',
],
'x-ms-enum': {
name: 'Test',
values: [
{
value: 'value1',
description: 'MS Description 1',
name: 'MsVar1',
},
{
value: 'value2',
description: 'MS Description 2',
name: 'MsVar2',
},
],
},
},
},
}),
);