Skip to content

Commit 244a265

Browse files
segoonmasatake
authored andcommitted
OpenAPI: extract host (in swagger) and servers' url
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. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 7ebca9d commit 244a265

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
test input.yaml /^ title: test$/;" t
2+
http://example.com input.yaml /^ - url: http:\/\/example.com$/;" s
23
/sample/path input.yaml /^ \/sample\/path:$/;" p
34
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
45
NullableField input.yaml /^ NullableField:$/;" d

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
test input.yaml /^ title: test$/;" t
2+
example.com input.yaml /^host: example.com$/;" s
23
/sample/path input.yaml /^ \/sample\/path:$/;" p
34
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
45
PolymorphicString input.yaml /^ PolymorphicString:$/;" d

parsers/openapi.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef enum {
2929
KIND_RESPONSE,
3030
KIND_PARAMETER,
3131
KIND_TITLE,
32+
KIND_SERVER,
3233
} openapiKind;
3334

3435
static kindDefinition OpenAPIKinds [] = {
@@ -37,6 +38,7 @@ static kindDefinition OpenAPIKinds [] = {
3738
{ true, 'R', "response", "responses" },
3839
{ true, 'P', "parameter", "parameters" },
3940
{ true, 't', "title", "titles" },
41+
{ true, 's', "server", "servers (or hosts in swagger)" },
4042
};
4143

4244
#define KEY_UNKNOWN KEYWORD_NONE
@@ -49,6 +51,9 @@ enum openapiKeys {
4951
KEY_DEFINITIONS,
5052
KEY_INFO,
5153
KEY_TITLE,
54+
KEY_SERVERS,
55+
KEY_URL,
56+
KEY_HOST,
5257
};
5358

5459
static const keywordTable OpenAPIKeywordTable[] = {
@@ -60,6 +65,9 @@ static const keywordTable OpenAPIKeywordTable[] = {
6065
{ "definitions", KEY_DEFINITIONS },
6166
{ "info", KEY_INFO },
6267
{ "title", KEY_TITLE },
68+
{ "servers", KEY_SERVERS },
69+
{ "url", KEY_URL },
70+
{ "host", KEY_HOST },
6371
};
6472

6573
struct yamlBlockTypeStack {
@@ -206,6 +214,16 @@ static const enum openapiKeys title3Keys[] = {
206214
KEY_INFO,
207215
};
208216

217+
static const enum openapiKeys server3Keys[] = {
218+
KEY_URL,
219+
KEY_UNKNOWN,
220+
KEY_SERVERS,
221+
};
222+
223+
static const enum openapiKeys host2Keys[] = {
224+
KEY_HOST,
225+
};
226+
209227
const struct tagSource tagSources[] = {
210228
{
211229
KIND_PATH,
@@ -250,6 +268,16 @@ const struct tagSource tagValueSources[] = {
250268
title3Keys,
251269
ARRAY_SIZE (title3Keys),
252270
},
271+
{
272+
KIND_SERVER,
273+
server3Keys,
274+
ARRAY_SIZE (server3Keys),
275+
},
276+
{
277+
KIND_SERVER,
278+
host2Keys,
279+
ARRAY_SIZE (host2Keys),
280+
}
253281
};
254282

255283
static void handleToken(struct sOpenAPISubparser *openapi, yaml_token_t *token,

0 commit comments

Comments
 (0)