File tree 8 files changed +35
-25
lines changed
test/unit/core/plugins/json-schema-5/components
8 files changed +35
-25
lines changed Original file line number Diff line number Diff line change @@ -505,18 +505,21 @@ export const makeGetExtensionKeywords = (fnAccessor) => {
505
505
return getExtensionKeywords
506
506
}
507
507
508
- export const schemaHasType = ( schema , types ) => {
508
+ export const hasSchemaType = ( schema , type ) => {
509
509
const isSchemaImmutable = Map . isMap ( schema )
510
510
511
511
if ( ! isSchemaImmutable && ! isPlainObject ( schema ) ) {
512
512
return false
513
513
}
514
514
515
- const type = isSchemaImmutable ? schema . get ( "type" ) : schema . type
515
+ const hasType = ( schemaType ) =>
516
+ type === schemaType || ( Array . isArray ( type ) && type . includes ( schemaType ) )
516
517
517
- if ( List . isList ( type ) || Array . isArray ( type ) ) {
518
- return type . some ( ( t ) => types . includes ( t ) )
518
+ const schemaType = isSchemaImmutable ? schema . get ( "type" ) : schema . type
519
+
520
+ if ( List . isList ( schemaType ) || Array . isArray ( schemaType ) ) {
521
+ return schemaType . some ( ( t ) => hasType ( t ) )
519
522
}
520
523
521
- return types . includes ( type )
524
+ return hasType ( schemaType )
522
525
}
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ import {
55
55
isBooleanJSONSchema ,
56
56
getSchemaKeywords ,
57
57
makeGetExtensionKeywords ,
58
- schemaHasType ,
58
+ hasSchemaType ,
59
59
} from "./fn"
60
60
import { JSONSchemaPathContext , JSONSchemaLevelContext } from "./context"
61
61
import {
@@ -144,7 +144,7 @@ const JSONSchema202012Plugin = ({ getSystem, fn }) => {
144
144
useLevel,
145
145
getSchemaKeywords,
146
146
getExtensionKeywords : makeGetExtensionKeywords ( fnAccessor ) ,
147
- schemaHasType ,
147
+ hasSchemaType ,
148
148
} ,
149
149
} ,
150
150
}
Original file line number Diff line number Diff line change 4
4
import { Map } from "immutable"
5
5
import isPlainObject from "lodash/isPlainObject"
6
6
7
- export const schemaHasType = ( schema , types ) => {
7
+ export const hasSchemaType = ( schema , type ) => {
8
8
const isSchemaImmutable = Map . isMap ( schema )
9
9
10
10
if ( ! isSchemaImmutable && ! isPlainObject ( schema ) ) {
11
11
return false
12
12
}
13
13
14
- const type = isSchemaImmutable ? schema . get ( "type" ) : schema . type
14
+ const schemaType = isSchemaImmutable ? schema . get ( "type" ) : schema . type
15
15
16
- return types . includes ( type )
16
+ return (
17
+ type === schemaType || ( Array . isArray ( type ) && type . includes ( schemaType ) )
18
+ )
17
19
}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import Schemes from "./components/schemes"
14
14
import SchemesContainer from "./containers/schemes"
15
15
import * as JSONSchemaComponents from "./components/json-schema-components"
16
16
import { ModelExtensions } from "./components/model-extensions"
17
- import { schemaHasType } from "./fn"
17
+ import { hasSchemaType } from "./fn"
18
18
19
19
const JSONSchema5Plugin = ( ) => ( {
20
20
components : {
@@ -33,7 +33,7 @@ const JSONSchema5Plugin = () => ({
33
33
...JSONSchemaComponents ,
34
34
} ,
35
35
fn : {
36
- schemaHasType ,
36
+ hasSchemaType ,
37
37
} ,
38
38
} )
39
39
Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ const RequestBody = ({
129
129
return null
130
130
}
131
131
132
- const isObjectContent = fn . schemaHasType ( mediaTypeValue . get ( "schema" ) , [ "object" ] )
132
+ const isObjectContent = fn . hasSchemaType ( mediaTypeValue . get ( "schema" ) , "object" )
133
133
134
134
if (
135
135
isObjectContent &&
Original file line number Diff line number Diff line change @@ -27,8 +27,7 @@ export const makeIsFileUploadIntended = (getSystem) => {
27
27
const format = isSchemaImmutable ? schema . get ( "format" ) : schema . format
28
28
29
29
return (
30
- fn . schemaHasType ( schema , [ "string" ] ) &&
31
- [ "binary" , "byte" ] . includes ( format )
30
+ fn . hasSchemaType ( schema , "string" ) && [ "binary" , "byte" ] . includes ( format )
32
31
)
33
32
}
34
33
Original file line number Diff line number Diff line change @@ -42,20 +42,26 @@ function afterLoad({ fn, getSystem }) {
42
42
43
43
// overrides behavior in OpenAPI 3.1.x, recognizes more intentions
44
44
const isFileUploadIntended = makeIsFileUploadIntended ( getSystem )
45
- const { isFileUploadIntended : isFileUploadIntendedWrap , schemaHasType } =
46
- wrapOAS31Fn (
45
+ const { isFileUploadIntended : isFileUploadIntendedWrap } = wrapOAS31Fn (
46
+ {
47
+ isFileUploadIntended,
48
+ } ,
49
+ getSystem ( )
50
+ )
51
+
52
+ this . fn . isFileUploadIntended = isFileUploadIntendedWrap
53
+ this . fn . isFileUploadIntendedOAS31 = isFileUploadIntended
54
+
55
+ if ( fn . jsonSchema202012 ) {
56
+ const { hasSchemaType } = wrapOAS31Fn (
47
57
{
48
- isFileUploadIntended,
49
- ...( fn . jsonSchema202012 && {
50
- schemaHasType : fn . jsonSchema202012 . schemaHasType ,
51
- } ) ,
58
+ hasSchemaType : fn . jsonSchema202012 . hasSchemaType ,
52
59
} ,
53
60
getSystem ( )
54
61
)
55
62
56
- this . fn . isFileUploadIntended = isFileUploadIntendedWrap
57
- this . fn . isFileUploadIntendedOAS31 = isFileUploadIntended
58
- this . fn . schemaHasType = schemaHasType
63
+ this . fn . hasSchemaType = hasSchemaType
64
+ }
59
65
}
60
66
61
67
export default afterLoad
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ const getSystemStub = () => ({
19
19
fileUploadMediaTypes : [ ] ,
20
20
} ) ,
21
21
fn : {
22
- schemaHasType : ( ) => { } ,
22
+ hasSchemaType : ( ) => { } ,
23
23
isFileUploadIntendedOAS30 : ( ) => { } ,
24
24
} ,
25
25
} )
You can’t perform that action at this time.
0 commit comments