diff --git a/contrib/html/openapi.yaml b/contrib/html/openapi.yaml index a4ab246f..b2a677f8 100644 --- a/contrib/html/openapi.yaml +++ b/contrib/html/openapi.yaml @@ -123,6 +123,28 @@ paths: 500: description: Circuit or message not found. content: { } + /datatypes: + get: + summary: Get all known field data types. + responses: + 200: + description: Success. + content: + application/json;charset=utf-8: + schema: + $ref: '#/components/schemas/DataTypes' + 400: + description: Invalid request parameters. + content: { } + 403: + description: User not authorized. + content: { } + 404: + description: Circuit or message not found. + content: { } + 500: + description: General error. + content: { } /{file}: get: summary: Retrieve a particular file. @@ -289,51 +311,6 @@ components: type: integer description: the time in UTC seconds of the last update of any message. example: 1493483370 - types: - type: array - description: the known field data types (only with definition and without since). - items: - type: object - properties: - type: - type: string - description: the type name. - example: UCH - isbits: - type: boolean - description: true when the length is in bits. - isadjustable: - type: boolean - description: whether the length is adjustable. - isignored: - type: boolean - description: whether the result is ignored. - length: - type: number - minimum: -1 - maximum: 31 - description: the field length in bytes (-1 for remainder, number - of bits when isbits is true). - result: - enum: - - void - - string - - number - - date - - time - - datetime - description: the result type. - divisor: - type: number - description: the divisor for numeric types (only if applicable, positive - for divisor, negative for reciprocal i.e. 1/-divisor). - precision: - type: number - description: the precision (number of fraction digits) when divisor is >1. - required: - - type - - isbits - - length Circuit: type: object properties: @@ -497,6 +474,54 @@ components: comment: type: string description: the field comment. + DataType: + description: a known field data type. + type: object + properties: + type: + type: string + description: the type name. + example: UCH + isbits: + type: boolean + description: true when the length is in bits. + isadjustable: + type: boolean + description: whether the length is adjustable. + isignored: + type: boolean + description: whether the result is ignored. + length: + type: number + minimum: -1 + maximum: 31 + description: the field length in bytes (-1 for remainder, number + of bits when isbits is true). + result: + enum: + - void + - string + - number + - date + - time + - datetime + description: the result type. + divisor: + type: number + description: the divisor for numeric types (only if applicable, positive + for divisor, negative for reciprocal i.e. 1/-divisor). + precision: + type: number + description: the precision (number of fraction digits) when divisor is >1. + required: + - type + - isbits + - length + DataTypes: + type: array + description: the known field data types. + items: + $ref: '#/components/schemas/DataType' Data: required: - global diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 90dc8697..82c9b286 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -2000,10 +2000,6 @@ bool parseBoolQuery(const string& value) { } result_t MainLoop::executeGet(const vector& args, bool* connected, ostringstream* ostream) { - bool required = false, full = false, withWrite = false, raw = false; - bool withDefinition = false; - string newDefinition; - OutputFormat verbosity = OF_NAMES; time_t maxAge = -1; size_t argPos = 1; string uri = args[argPos++]; @@ -2018,6 +2014,10 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri circuit = uri.substr(6, pos - 6); name = uri.substr(pos + 1); } + bool required = false, full = false, withWrite = false, raw = false; + bool withDefinition = false; + string newDefinition; + OutputFormat verbosity = OF_NAMES; time_t since = 0; size_t pollPriority = 0; bool exact = false; @@ -2199,13 +2199,8 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri *ostream << ",\n \"reconnects\": " << m_reconnectCount << ",\n \"masters\": " << m_busHandler->getMasterCount() << ",\n \"messages\": " << m_messages->size() - << ",\n \"lastup\": " << static_cast(maxLastUp); - if (withDefinition && since <= 0) { - *ostream << ",\n \"types\": ["; - DataTypeList::getInstance()->dump(verbosity, true, ostream); - *ostream << "\n ]"; - } - *ostream << "\n }" + << ",\n \"lastup\": " << static_cast(maxLastUp) + << "\n }" << "\n}"; type = 6; } @@ -2213,6 +2208,16 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri return formatHttpResult(ret, type, ostream); } // request for "/data..." + if (uri == "/datatypes") { + *ostream << "["; + OutputFormat verbosity = OF_NAMES|OF_JSON|OF_ALL_ATTRS; + DataTypeList::getInstance()->dump(verbosity, true, ostream); + *ostream << "\n]"; + type = 6; + *connected = false; + return formatHttpResult(ret, type, ostream); + } + if (uri.length() < 1 || uri[0] != '/' || uri.find("//") != string::npos || uri.find("..") != string::npos) { ret = RESULT_ERR_INVALID_ARG; } else { diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 1bcb6886..697aac3a 100755 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -1125,7 +1125,7 @@ void DataTypeList::dump(OutputFormat outputFormat, bool appendDivisor, ostream* continue; } if (json) { - *output << sep << " {"; + *output << sep << " {"; } if ((dataType->getBitCount() % 8) != 0) { dataType->dump(outputFormat, dataType->getBitCount(), appendDivisor, output);