From 244a265124c8fab279b22bb6e3445e4249f64228 Mon Sep 17 00:00:00 2001 From: Vasily Kulikov Date: Thu, 6 Jan 2022 19:06:51 +0300 Subject: [PATCH] OpenAPI: extract host (in swagger) and servers' url This change is derrived from #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 --- .../parser-openapi.r/openapi.d/expected.tags | 1 + .../parser-openapi.r/swagger.d/expected.tags | 1 + parsers/openapi.c | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Units/parser-openapi.r/openapi.d/expected.tags b/Units/parser-openapi.r/openapi.d/expected.tags index 6be1e95ebf..050091bde5 100644 --- a/Units/parser-openapi.r/openapi.d/expected.tags +++ b/Units/parser-openapi.r/openapi.d/expected.tags @@ -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 diff --git a/Units/parser-openapi.r/swagger.d/expected.tags b/Units/parser-openapi.r/swagger.d/expected.tags index 78d364f45e..079dda48c8 100644 --- a/Units/parser-openapi.r/swagger.d/expected.tags +++ b/Units/parser-openapi.r/swagger.d/expected.tags @@ -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 diff --git a/parsers/openapi.c b/parsers/openapi.c index 60c56ed333..2e3cdc4aa0 100644 --- a/parsers/openapi.c +++ b/parsers/openapi.c @@ -29,6 +29,7 @@ typedef enum { KIND_RESPONSE, KIND_PARAMETER, KIND_TITLE, + KIND_SERVER, } openapiKind; static kindDefinition OpenAPIKinds [] = { @@ -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 @@ -49,6 +51,9 @@ enum openapiKeys { KEY_DEFINITIONS, KEY_INFO, KEY_TITLE, + KEY_SERVERS, + KEY_URL, + KEY_HOST, }; static const keywordTable OpenAPIKeywordTable[] = { @@ -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 { @@ -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, @@ -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,