Skip to content

Commit 7ebca9d

Browse files
segoonmasatake
authored andcommitted
OpenAPI: extract title
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.
1 parent 11f8fe9 commit 7ebca9d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Units/parser-openapi.r/openapi.d/expected.tags

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
test input.yaml /^ title: test$/;" t
12
/sample/path input.yaml /^ \/sample\/path:$/;" p
23
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
34
NullableField input.yaml /^ NullableField:$/;" d

Units/parser-openapi.r/swagger.d/expected.tags

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
test input.yaml /^ title: test$/;" t
12
/sample/path input.yaml /^ \/sample\/path:$/;" p
23
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
34
PolymorphicString input.yaml /^ PolymorphicString:$/;" d

parsers/openapi.c

+27
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ typedef enum {
2828
KIND_PATH,
2929
KIND_RESPONSE,
3030
KIND_PARAMETER,
31+
KIND_TITLE,
3132
} openapiKind;
3233

3334
static kindDefinition OpenAPIKinds [] = {
3435
{ true, 'd', "schema", "schemas" },
3536
{ true, 'p', "path", "paths" },
3637
{ true, 'R', "response", "responses" },
3738
{ true, 'P', "parameter", "parameters" },
39+
{ true, 't', "title", "titles" },
3840
};
3941

4042
#define KEY_UNKNOWN KEYWORD_NONE
@@ -45,6 +47,8 @@ enum openapiKeys {
4547
KEY_PARAMETERS,
4648
KEY_RESPONSES,
4749
KEY_DEFINITIONS,
50+
KEY_INFO,
51+
KEY_TITLE,
4852
};
4953

5054
static const keywordTable OpenAPIKeywordTable[] = {
@@ -54,6 +58,8 @@ static const keywordTable OpenAPIKeywordTable[] = {
5458
{ "parameters", KEY_PARAMETERS },
5559
{ "responses", KEY_RESPONSES },
5660
{ "definitions", KEY_DEFINITIONS },
61+
{ "info", KEY_INFO },
62+
{ "title", KEY_TITLE },
5763
};
5864

5965
struct yamlBlockTypeStack {
@@ -195,6 +201,11 @@ static const enum openapiKeys definitions2Keys[] = {
195201
KEY_DEFINITIONS,
196202
};
197203

204+
static const enum openapiKeys title3Keys[] = {
205+
KEY_TITLE,
206+
KEY_INFO,
207+
};
208+
198209
const struct tagSource tagSources[] = {
199210
{
200211
KIND_PATH,
@@ -233,6 +244,14 @@ const struct tagSource tagSources[] = {
233244
},
234245
};
235246

247+
const struct tagSource tagValueSources[] = {
248+
{
249+
KIND_TITLE,
250+
title3Keys,
251+
ARRAY_SIZE (title3Keys),
252+
},
253+
};
254+
236255
static void handleToken(struct sOpenAPISubparser *openapi, yaml_token_t *token,
237256
const struct tagSource *tss, size_t ts_count)
238257
{
@@ -260,6 +279,12 @@ static void handleKey(struct sOpenAPISubparser *openapi,
260279
handleToken (openapi, token, tagSources, ARRAY_SIZE (tagSources));
261280
}
262281

282+
static void handleValue(struct sOpenAPISubparser *openapi,
283+
yaml_token_t *token)
284+
{
285+
handleToken (openapi, token, tagValueSources, ARRAY_SIZE (tagValueSources));
286+
}
287+
263288
static void openapiPlayStateMachine (struct sOpenAPISubparser *openapi,
264289
yaml_token_t *token)
265290
{
@@ -285,6 +310,8 @@ static void openapiPlayStateMachine (struct sOpenAPISubparser *openapi,
285310
break;
286311
case DSTAT_LAST_VALUE:
287312
TRACE_PRINT(" value: %s", (char*)token->data.scalar.value);
313+
if (openapi->type_stack)
314+
handleValue (openapi, token);
288315
break;
289316
default:
290317
break;

0 commit comments

Comments
 (0)