fix(authz api): fix schema error
This commit is contained in:
parent
3df21a9e14
commit
c4e0eff772
|
@ -22,8 +22,7 @@
|
|||
-include_lib("emqx/include/logger.hrl").
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
|
||||
-define(EXAMPLE_USERNAME, #{type => username,
|
||||
key => user1,
|
||||
-define(EXAMPLE_USERNAME, #{username => user1,
|
||||
rules => [ #{topic => <<"test/toopic/1">>,
|
||||
permission => <<"allow">>,
|
||||
action => <<"publish">>
|
||||
|
@ -38,8 +37,7 @@
|
|||
}
|
||||
]
|
||||
}).
|
||||
-define(EXAMPLE_CLIENTID, #{type => clientid,
|
||||
key => client1,
|
||||
-define(EXAMPLE_CLIENTID, #{clientid => client1,
|
||||
rules => [ #{topic => <<"test/toopic/1">>,
|
||||
permission => <<"allow">>,
|
||||
action => <<"publish">>
|
||||
|
@ -54,8 +52,7 @@
|
|||
}
|
||||
]
|
||||
}).
|
||||
-define(EXAMPLE_ALL , #{type => all,
|
||||
rules => [ #{topic => <<"test/toopic/1">>,
|
||||
-define(EXAMPLE_ALL , #{rules => [ #{topic => <<"test/toopic/1">>,
|
||||
permission => <<"allow">>,
|
||||
action => <<"publish">>
|
||||
}
|
||||
|
@ -106,8 +103,8 @@ definitions() ->
|
|||
}
|
||||
}
|
||||
},
|
||||
Record = #{
|
||||
oneOf => [ #{type => object,
|
||||
Username = #{
|
||||
type => object,
|
||||
required => [username, rules],
|
||||
properties => #{
|
||||
username => #{
|
||||
|
@ -116,27 +113,29 @@ definitions() ->
|
|||
},
|
||||
rules => minirest:ref(<<"rules">>)
|
||||
}
|
||||
}
|
||||
, #{type => object,
|
||||
},
|
||||
Clientid = #{
|
||||
type => object,
|
||||
required => [clientid, rules],
|
||||
properties => #{
|
||||
username => #{
|
||||
clientid => #{
|
||||
type => string,
|
||||
example => <<"clientid">>
|
||||
},
|
||||
rules => minirest:ref(<<"rules">>)
|
||||
}
|
||||
}
|
||||
, #{type => object,
|
||||
},
|
||||
ALL = #{
|
||||
type => object,
|
||||
required => [rules],
|
||||
properties => #{
|
||||
rules => minirest:ref(<<"rules">>)
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
[ #{<<"rules">> => Rules}
|
||||
, #{<<"record">> => Record}
|
||||
, #{<<"username">> => Username}
|
||||
, #{<<"clientid">> => Clientid}
|
||||
, #{<<"all">> => ALL}
|
||||
].
|
||||
|
||||
purge_api() ->
|
||||
|
@ -187,7 +186,12 @@ records_api() ->
|
|||
'application/json' => #{
|
||||
schema => #{
|
||||
type => array,
|
||||
items => minirest:ref(<<"record">>)
|
||||
items => #{
|
||||
oneOf => [ minirest:ref(<<"username">>)
|
||||
, minirest:ref(<<"clientid">>)
|
||||
, minirest:ref(<<"all">>)
|
||||
]
|
||||
}
|
||||
},
|
||||
examples => #{
|
||||
username => #{
|
||||
|
@ -226,7 +230,11 @@ records_api() ->
|
|||
'application/json' => #{
|
||||
schema => #{
|
||||
type => array,
|
||||
items => minirest:ref(<<"record">>)
|
||||
items => #{
|
||||
oneOf => [ minirest:ref(<<"username">>)
|
||||
, minirest:ref(<<"clientid">>)
|
||||
]
|
||||
}
|
||||
},
|
||||
examples => #{
|
||||
username => #{
|
||||
|
@ -262,8 +270,24 @@ records_api() ->
|
|||
requestBody => #{
|
||||
content => #{
|
||||
'application/json' => #{
|
||||
schema => minirest:ref(<<"record">>),
|
||||
schema => #{
|
||||
type => array,
|
||||
items => #{
|
||||
oneOf => [ minirest:ref(<<"username">>)
|
||||
, minirest:ref(<<"clientid">>)
|
||||
, minirest:ref(<<"all">>)
|
||||
]
|
||||
}
|
||||
},
|
||||
examples => #{
|
||||
username => #{
|
||||
summary => <<"Username">>,
|
||||
value => jsx:encode(?EXAMPLE_USERNAME)
|
||||
},
|
||||
clientid => #{
|
||||
summary => <<"Clientid">>,
|
||||
value => jsx:encode(?EXAMPLE_CLIENTID)
|
||||
},
|
||||
all => #{
|
||||
summary => <<"All">>,
|
||||
value => jsx:encode(?EXAMPLE_ALL)
|
||||
|
@ -308,7 +332,11 @@ record_api() ->
|
|||
description => <<"OK">>,
|
||||
content => #{
|
||||
'application/json' => #{
|
||||
schema => minirest:ref(<<"record">>),
|
||||
schema => #{
|
||||
oneOf => [ minirest:ref(<<"username">>)
|
||||
, minirest:ref(<<"clientid">>)
|
||||
]
|
||||
},
|
||||
examples => #{
|
||||
username => #{
|
||||
summary => <<"Username">>,
|
||||
|
@ -317,10 +345,6 @@ record_api() ->
|
|||
clientid => #{
|
||||
summary => <<"Clientid">>,
|
||||
value => jsx:encode(?EXAMPLE_CLIENTID)
|
||||
},
|
||||
all => #{
|
||||
summary => <<"All">>,
|
||||
value => jsx:encode(?EXAMPLE_ALL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +377,11 @@ record_api() ->
|
|||
requestBody => #{
|
||||
content => #{
|
||||
'application/json' => #{
|
||||
schema => minirest:ref(<<"record">>),
|
||||
schema => #{
|
||||
oneOf => [ minirest:ref(<<"username">>)
|
||||
, minirest:ref(<<"clientid">>)
|
||||
]
|
||||
},
|
||||
examples => #{
|
||||
username => #{
|
||||
summary => <<"Username">>,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
definitions() ->
|
||||
Sources = #{
|
||||
oneOf => [ minirest:ref(<<"http">>)
|
||||
, minirest:ref(<<"built-in-database">>)
|
||||
, minirest:ref(<<"mongo_single">>)
|
||||
, minirest:ref(<<"mongo_rs">>)
|
||||
, minirest:ref(<<"mongo_sharded">>)
|
||||
|
@ -446,6 +447,21 @@ definitions() ->
|
|||
ssl => minirest:ref(<<"ssl">>)
|
||||
}
|
||||
},
|
||||
Mnesia = #{
|
||||
type => object,
|
||||
required => [type, enable],
|
||||
properties => #{
|
||||
type => #{
|
||||
type => string,
|
||||
enum => [<<"redis">>],
|
||||
example => <<"redis">>
|
||||
},
|
||||
enable => #{
|
||||
type => boolean,
|
||||
example => true
|
||||
}
|
||||
}
|
||||
},
|
||||
File = #{
|
||||
type => object,
|
||||
required => [type, enable, rules],
|
||||
|
@ -475,6 +491,7 @@ definitions() ->
|
|||
[ #{<<"sources">> => Sources}
|
||||
, #{<<"ssl">> => SSL}
|
||||
, #{<<"http">> => HTTP}
|
||||
, #{<<"built-in-database">> => Mnesia}
|
||||
, #{<<"mongo_single">> => MongoSingle}
|
||||
, #{<<"mongo_rs">> => MongoRs}
|
||||
, #{<<"mongo_sharded">> => MongoSharded}
|
||||
|
|
|
@ -405,7 +405,7 @@ get_raw_sources() ->
|
|||
RawSources = emqx:get_raw_config([authorization, sources]),
|
||||
Schema = #{roots => emqx_authz_schema:fields("authorization"), fields => #{}},
|
||||
Conf = #{<<"sources">> => RawSources},
|
||||
#{sources := Sources} = hocon_schema:check_plain(Schema, Conf, #{atom_key => true, no_conversion => true}),
|
||||
#{sources := Sources} = hocon_schema:check_plain(Schema, Conf, #{atom_key => true, only_fill_defaults => true}),
|
||||
Sources.
|
||||
|
||||
get_raw_source(Type) ->
|
||||
|
|
Loading…
Reference in New Issue