@redocly/openapi-core
Advanced tools
Comparing version 1.0.0-beta.44 to 1.0.0-beta.45
@@ -395,6 +395,4 @@ import { outdent } from 'outdent'; | ||
expect(Array.from(resolvedRefs.values()).pop()!.node).toEqual( | ||
{ type: 'string' }, | ||
); | ||
expect(Array.from(resolvedRefs.values()).pop()!.node).toEqual({ type: 'string' }); | ||
}); | ||
}); |
@@ -146,3 +146,3 @@ "use strict"; | ||
} | ||
fragment VersionDetails on DefinitionVersion { | ||
@@ -149,0 +149,0 @@ id |
@@ -9,3 +9,3 @@ "use strict"; | ||
if (schema.enum && schema.type) { | ||
const typeMismatchedValues = schema.enum.filter((item) => !utils_1.matchesJsonSchemaType(item, schema.type)); | ||
const typeMismatchedValues = schema.enum.filter((item) => !utils_1.matchesJsonSchemaType(item, schema.type, schema.nullable)); | ||
for (const mismatchedValue of typeMismatchedValues) { | ||
@@ -12,0 +12,0 @@ report({ |
@@ -75,3 +75,3 @@ "use strict"; | ||
} | ||
else if (propSchema.type && !utils_1.matchesJsonSchemaType(propValue, propSchema.type)) { | ||
else if (propSchema.type && !utils_1.matchesJsonSchemaType(propValue, propSchema.type, false)) { | ||
report({ | ||
@@ -86,3 +86,3 @@ message: `Expected type \`${propSchema.type}\` but got \`${propValueType}\`.`, | ||
const item = propValue[i]; | ||
if (!utils_1.matchesJsonSchemaType(item, itemsType)) { | ||
if (!utils_1.matchesJsonSchemaType(item, itemsType, false)) { | ||
report({ | ||
@@ -89,0 +89,0 @@ message: `Expected type \`${itemsType}\` but got \`${utils_1.oasTypeOf(item)}\`.`, |
@@ -10,3 +10,3 @@ import { UserContext } from '../walk'; | ||
*/ | ||
export declare function matchesJsonSchemaType(value: unknown, type: string): boolean; | ||
export declare function matchesJsonSchemaType(value: unknown, type: string, nullable: boolean): boolean; | ||
export declare function missingRequiredField(type: string, field: string): string; | ||
@@ -13,0 +13,0 @@ export declare function fieldNonEmpty(type: string, field: string): string; |
@@ -24,3 +24,6 @@ "use strict"; | ||
*/ | ||
function matchesJsonSchemaType(value, type) { | ||
function matchesJsonSchemaType(value, type, nullable) { | ||
if (nullable && value === null) { | ||
return value === null; | ||
} | ||
switch (type) { | ||
@@ -27,0 +30,0 @@ case 'array': |
@@ -136,2 +136,3 @@ import { Referenced } from './openapi'; | ||
discriminator?: string; | ||
nullable?: boolean; | ||
allOf?: Oas2Schema[]; | ||
@@ -138,0 +139,0 @@ title?: string; |
{ | ||
"name": "@redocly/openapi-core", | ||
"version": "1.0.0-beta.44", | ||
"version": "1.0.0-beta.45", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -150,3 +150,3 @@ import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs'; | ||
} | ||
fragment VersionDetails on DefinitionVersion { | ||
@@ -153,0 +153,0 @@ id |
@@ -39,2 +39,35 @@ import { outdent } from 'outdent'; | ||
it('should not report on enum object if all items match type and enum is nullable', async () => { | ||
const document = parseYamlToDocument( | ||
outdent` | ||
openapi: 3.0.0 | ||
paths: | ||
/some: | ||
get: | ||
responses: | ||
'200': | ||
description: A paged array of pets | ||
content: | ||
application/json: | ||
schema: | ||
type: string | ||
nullable: true | ||
enum: | ||
- A | ||
- B | ||
- C | ||
- null | ||
`, | ||
'foobar.yaml', | ||
); | ||
const results = await lintDocument({ | ||
externalRefResolver: new BaseResolver(), | ||
document, | ||
config: new LintConfig({ extends: [], rules: { 'no-enum-type-mismatch': 'error' } }), | ||
}); | ||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); | ||
}); | ||
it('should report on enum object if not all items match type', async () => { | ||
@@ -41,0 +74,0 @@ const document = parseYamlToDocument( |
@@ -12,3 +12,3 @@ import { Oas3Rule, Oas2Rule } from '../../visitors'; | ||
const typeMismatchedValues = schema.enum.filter( | ||
(item) => !matchesJsonSchemaType(item, schema.type as string), | ||
(item) => !matchesJsonSchemaType(item, schema.type as string, schema.nullable as boolean), | ||
); | ||
@@ -15,0 +15,0 @@ for (const mismatchedValue of typeMismatchedValues) { |
@@ -78,3 +78,3 @@ import type { Oas3Rule, Oas2Rule } from '../../visitors'; | ||
} | ||
} else if (propSchema.type && !matchesJsonSchemaType(propValue, propSchema.type)) { | ||
} else if (propSchema.type && !matchesJsonSchemaType(propValue, propSchema.type, false)) { | ||
report({ | ||
@@ -88,3 +88,3 @@ message: `Expected type \`${propSchema.type}\` but got \`${propValueType}\`.`, | ||
const item = propValue[i]; | ||
if (!matchesJsonSchemaType(item, itemsType)) { | ||
if (!matchesJsonSchemaType(item, itemsType, false)) { | ||
report({ | ||
@@ -91,0 +91,0 @@ message: `Expected type \`${itemsType}\` but got \`${oasTypeOf(item)}\`.`, |
@@ -21,3 +21,7 @@ import levenshtein = require('js-levenshtein'); | ||
*/ | ||
export function matchesJsonSchemaType(value: unknown, type: string): boolean { | ||
export function matchesJsonSchemaType(value: unknown, type: string, nullable: boolean): boolean { | ||
if (nullable && value === null) { | ||
return value === null | ||
} | ||
switch (type) { | ||
@@ -24,0 +28,0 @@ case 'array': |
@@ -153,3 +153,3 @@ import { Referenced } from './openapi'; | ||
discriminator?: string; | ||
nullable?: boolean; | ||
allOf?: Oas2Schema[]; | ||
@@ -156,0 +156,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1883722
20039