Skip to content

Commit

Permalink
OpenAPI: extract host (in swagger) and servers' url
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.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
segoon authored and masatake committed Jan 9, 2022
1 parent 7ebca9d commit 244a265
Show file tree
Hide file tree
Showing 3 changed files with 30 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,4 +1,5 @@
test input.yaml /^ title: test$/;" t
http://example.com input.yaml /^ - url: http:\/\/example.com$/;" s
/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,4 +1,5 @@
test input.yaml /^ title: test$/;" t
example.com input.yaml /^host: example.com$/;" s
/sample/path input.yaml /^ \/sample\/path:$/;" p
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
PolymorphicString input.yaml /^ PolymorphicString:$/;" d
Expand Down
28 changes: 28 additions & 0 deletions parsers/openapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum {
KIND_RESPONSE,
KIND_PARAMETER,
KIND_TITLE,
KIND_SERVER,
} openapiKind;

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

#define KEY_UNKNOWN KEYWORD_NONE
Expand All @@ -49,6 +51,9 @@ enum openapiKeys {
KEY_DEFINITIONS,
KEY_INFO,
KEY_TITLE,
KEY_SERVERS,
KEY_URL,
KEY_HOST,
};

static const keywordTable OpenAPIKeywordTable[] = {
Expand All @@ -60,6 +65,9 @@ static const keywordTable OpenAPIKeywordTable[] = {
{ "definitions", KEY_DEFINITIONS },
{ "info", KEY_INFO },
{ "title", KEY_TITLE },
{ "servers", KEY_SERVERS },
{ "url", KEY_URL },
{ "host", KEY_HOST },
};

struct yamlBlockTypeStack {
Expand Down Expand Up @@ -206,6 +214,16 @@ static const enum openapiKeys title3Keys[] = {
KEY_INFO,
};

static const enum openapiKeys server3Keys[] = {
KEY_URL,
KEY_UNKNOWN,
KEY_SERVERS,
};

static const enum openapiKeys host2Keys[] = {
KEY_HOST,
};

const struct tagSource tagSources[] = {
{
KIND_PATH,
Expand Down Expand Up @@ -250,6 +268,16 @@ const struct tagSource tagValueSources[] = {
title3Keys,
ARRAY_SIZE (title3Keys),
},
{
KIND_SERVER,
server3Keys,
ARRAY_SIZE (server3Keys),
},
{
KIND_SERVER,
host2Keys,
ARRAY_SIZE (host2Keys),
}
};

static void handleToken(struct sOpenAPISubparser *openapi, yaml_token_t *token,
Expand Down

0 comments on commit 244a265

Please sign in to comment.