-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matthias Gatto <[email protected]>
- Loading branch information
1 parent
d2f84c5
commit 8dc5c28
Showing
5 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "json.h" | ||
|
||
#define OBJ_GET(src, name, dst) do { \ | ||
ret = json_object_object_get_ex(src, name, dst); \ | ||
if (!ret) { \ | ||
puts("null"); \ | ||
goto err; \ | ||
} \ | ||
} while (0) \ | ||
|
||
int main(int ac, char **av) | ||
{ | ||
struct json_object *j_file = json_object_from_file(av[1]); | ||
char *componant_name = av[2]; | ||
int func_ret = 1; | ||
int ret; | ||
|
||
/* if / is found, assume in path */ | ||
if (strchr(componant_name, '/')) { | ||
int ret = 0; | ||
struct json_object *paths; | ||
struct json_object *func; | ||
struct json_object *parameters; | ||
struct json_object *post_or_get; | ||
int len; | ||
|
||
OBJ_GET(j_file, "paths", &paths); | ||
OBJ_GET(paths, componant_name, &func); | ||
ret = json_object_object_get_ex(func, "post", &post_or_get); | ||
if (!ret) { | ||
OBJ_GET(func, "get", &post_or_get); | ||
} | ||
OBJ_GET(post_or_get, "parameters", ¶meters); | ||
len = json_object_array_length(parameters); | ||
for (int i = 0; i < len; ++i) { | ||
struct json_object *name; | ||
|
||
OBJ_GET(json_object_array_get_idx(parameters, i), | ||
"name", &name); | ||
printf(" %s" + !i, json_object_get_string(name)); | ||
} | ||
} else { | ||
struct json_object *compo; | ||
struct json_object *schema; | ||
struct json_object *func; | ||
struct json_object *properties; | ||
int i = 0; | ||
|
||
OBJ_GET(j_file, "components", &compo); | ||
OBJ_GET(compo, "schemas", &schema); | ||
OBJ_GET(schema, componant_name, &func); | ||
OBJ_GET(func, "properties", &properties); | ||
json_object_object_foreach(properties, k, v_) { | ||
printf(" %s" + !i++, k); | ||
} | ||
} | ||
putchar('\n'); | ||
func_ret = 0; | ||
err: | ||
json_object_put(j_file); | ||
return func_ret; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters