在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:apiaryio/drafter开源软件地址:https://github.com/apiaryio/drafter开源编程语言:C++ 61.8%开源软件介绍:DrafterSnowcrash parser harness API Blueprint ParserDrafter is complex builder of API Blueprint. Internally it uses Snowcrash library, reference API Blueprint parser. API Blueprint is Web API documentation language. You can find API Blueprint documentation on the API Blueprint site. Drafter also provides the user ability to select the type of the output. There are two possible values:
By default, Drafter assumes the Refract Parse Result. Both the types of Parse Results are available in two different serialization formats, YAML and JSON. YAML is the default for the CLI. Status
InstallOS X using Homebrew: $ brew install drafter AUR package for Arch Linux. Other systems refer to installation notes. UsageDrafter is both a library and a command line tool. Command line toolThe command line tool allows you to parse a blueprint and/or check the validity of a blueprint. $ cat << 'EOF' > blueprint.apib
# My API
## GET /message
+ Response 200 (text/plain)
Hello World!
EOF
$ drafter blueprint.apib
element: "parseResult"
content:
-
element: "category"
meta:
classes:
- "api"
title: "My API"
... See parse feature for the details on using the C/C++ API#include <drafter/drafter.h> The header itself is annotated with comments. C API unit tests provide more examples. Parse API Blueprint into API ElementsThe drafter_error drafter_parse_blueprint_to(
const char* source,
char** out,
const drafter_parse_options* parse_opts,
const drafter_serialize_options* serialize_opts);
); Given a pointer to a UTF-8 encoded c-string, const char* blueprint =
"# My API\n"
"## GET /message\n"
"+ Response 200 (text/plain)\n"
"\n"
" Hello World!\n"; Serialized as YAMLWithout options, the resulting API Elements is serialized as YAML. char* yamlApie = NULL;
if (DRAFTER_OK == drafter_parse_blueprint_to(blueprint, &yamlApie, NULL, NULL)) {
printf("%s\n", yamlApie);
}
free(yamlApie); Serialized as JSONTweaking drafter_serialize_options* serialize_options = drafter_init_serialize_options();
drafter_set_format(serialize_options, DRAFTER_SERIALIZE_JSON);
char* jsonApie = NULL;
if (DRAFTER_OK == drafter_parse_blueprint_to(blueprint, &jsonApie, NULL, serialize_options)) {
printf("%s\n", jsonApie);
}
free(jsonApie);
drafter_free_serialize_options(serialize_options); Validate API BlueprintAPI Blueprint can be validated via drafter_error drafter_check_blueprint(
const char* source,
drafter_result** res,
const drafter_parse_options* parse_opts); Simple validationThe return value of drafter_result* result = NULL;
if (DRAFTER_OK == drafter_check_blueprint(blueprint, result)) {
printf("Understood.\n");
}
drafter_free_result(result); Access warnings and errorsAfter running Because the result is an API Element - drafter_result* result = NULL;
drafter_check_blueprint(blueprint, result);
if(result) {
char* yamlApie = drafter_serialize(result, NULL);
printf("%s\n", yamlApie);
free(yamlApie);
}
drafter_free_result(result); Serialization of API Elements as JSON is achieved by tweaking
InstallationBuilding Drafter will require a modern C++ compiler and CMake. The following compilers are tested and known to work:
The following steps can be used to build and install Drafter:
BindingsDrafter bindings in other languages:
CLI Wrapper
ContributeFork & Pull Request If you want to create a binding for Drafter please refer to the Writing a Binding article. LicenseMIT License. See the LICENSE file. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论