Skip to content

Commit

Permalink
OpenAPI: extract title
Browse files Browse the repository at this point in the history
This change is derrived from universal-ctags#3258.
The original commit is so large.
@masatake splited the commit smaller per-topic ones.
@masatake wrote this commit log.
  • Loading branch information
segoon authored and masatake committed Jan 9, 2022
1 parent 11f8fe9 commit 7ebca9d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Units/parser-openapi.r/openapi.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test input.yaml /^ title: test$/;" t
/sample/path input.yaml /^ \/sample\/path:$/;" p
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
NullableField input.yaml /^ NullableField:$/;" d
Expand Down
1 change: 1 addition & 0 deletions Units/parser-openapi.r/swagger.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test input.yaml /^ title: test$/;" t
/sample/path input.yaml /^ \/sample\/path:$/;" p
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
PolymorphicString input.yaml /^ PolymorphicString:$/;" d
Expand Down
27 changes: 27 additions & 0 deletions parsers/openapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ typedef enum {
KIND_PATH,
KIND_RESPONSE,
KIND_PARAMETER,
KIND_TITLE,
} openapiKind;

static kindDefinition OpenAPIKinds [] = {
{ true, 'd', "schema", "schemas" },
{ true, 'p', "path", "paths" },
{ true, 'R', "response", "responses" },
{ true, 'P', "parameter", "parameters" },
{ true, 't', "title", "titles" },
};

#define KEY_UNKNOWN KEYWORD_NONE
Expand All @@ -45,6 +47,8 @@ enum openapiKeys {
KEY_PARAMETERS,
KEY_RESPONSES,
KEY_DEFINITIONS,
KEY_INFO,
KEY_TITLE,
};

static const keywordTable OpenAPIKeywordTable[] = {
Expand All @@ -54,6 +58,8 @@ static const keywordTable OpenAPIKeywordTable[] = {
{ "parameters", KEY_PARAMETERS },
{ "responses", KEY_RESPONSES },
{ "definitions", KEY_DEFINITIONS },
{ "info", KEY_INFO },
{ "title", KEY_TITLE },
};

struct yamlBlockTypeStack {
Expand Down Expand Up @@ -195,6 +201,11 @@ static const enum openapiKeys definitions2Keys[] = {
KEY_DEFINITIONS,
};

static const enum openapiKeys title3Keys[] = {
KEY_TITLE,
KEY_INFO,
};

const struct tagSource tagSources[] = {
{
KIND_PATH,
Expand Down Expand Up @@ -233,6 +244,14 @@ const struct tagSource tagSources[] = {
},
};

const struct tagSource tagValueSources[] = {
{
KIND_TITLE,
title3Keys,
ARRAY_SIZE (title3Keys),
},
};

static void handleToken(struct sOpenAPISubparser *openapi, yaml_token_t *token,
const struct tagSource *tss, size_t ts_count)
{
Expand Down Expand Up @@ -260,6 +279,12 @@ static void handleKey(struct sOpenAPISubparser *openapi,
handleToken (openapi, token, tagSources, ARRAY_SIZE (tagSources));
}

static void handleValue(struct sOpenAPISubparser *openapi,
yaml_token_t *token)
{
handleToken (openapi, token, tagValueSources, ARRAY_SIZE (tagValueSources));
}

static void openapiPlayStateMachine (struct sOpenAPISubparser *openapi,
yaml_token_t *token)
{
Expand All @@ -285,6 +310,8 @@ static void openapiPlayStateMachine (struct sOpenAPISubparser *openapi,
break;
case DSTAT_LAST_VALUE:
TRACE_PRINT(" value: %s", (char*)token->data.scalar.value);
if (openapi->type_stack)
handleValue (openapi, token);
break;
default:
break;
Expand Down

0 comments on commit 7ebca9d

Please sign in to comment.