From f52f0bd6bee47bc9383115a86c46e864607ae6f0 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 16 Jan 2017 08:27:34 +0000 Subject: [PATCH 1/8] fix(parameters): Serialize parameter values as string in API Elements --- src/RefractAPI.cc | 14 +------------ test/fixtures/api/action-parameters.json | 4 ++-- .../api/action-parameters.sourcemap.json | 4 ++-- test/fixtures/api/request-parameters.json | 2 +- .../api/request-parameters.sourcemap.json | 2 +- test/fixtures/api/resource-parameters.json | 20 +++++++++---------- .../api/resource-parameters.sourcemap.json | 20 +++++++++---------- 7 files changed, 27 insertions(+), 39 deletions(-) diff --git a/src/RefractAPI.cc b/src/RefractAPI.cc index 85933aa59..a36f0a5dd 100644 --- a/src/RefractAPI.cc +++ b/src/RefractAPI.cc @@ -187,19 +187,7 @@ namespace drafter { refract::IElement* ParameterToRefract(const NodeInfo& parameter, ConversionContext& context) { refract::MemberElement* element = new refract::MemberElement; - refract::IElement *value = NULL; - - // Parameter type, exampleValue, defaultValue, values - if (parameter.node->type == "boolean") { - value = ExtractParameter(parameter, context); - } - else if (parameter.node->type == "number") { - value = ExtractParameter(parameter, context); - } - else { - value = ExtractParameter(parameter, context); - } - + refract::IElement *value = ExtractParameter(parameter, context); element->set(PrimitiveToRefract(MAKE_NODE_INFO(parameter, name)), value); // Description diff --git a/test/fixtures/api/action-parameters.json b/test/fixtures/api/action-parameters.json index 6f8079a63..22b1698d5 100644 --- a/test/fixtures/api/action-parameters.json +++ b/test/fixtures/api/action-parameters.json @@ -88,7 +88,7 @@ "content": "active" }, "value": { - "element": "boolean" + "element": "string" } } }, @@ -105,7 +105,7 @@ "content": "votes" }, "value": { - "element": "number" + "element": "string" } } } diff --git a/test/fixtures/api/action-parameters.sourcemap.json b/test/fixtures/api/action-parameters.sourcemap.json index 5c9f328e0..09cfbadfc 100644 --- a/test/fixtures/api/action-parameters.sourcemap.json +++ b/test/fixtures/api/action-parameters.sourcemap.json @@ -236,7 +236,7 @@ "content": "active" }, "value": { - "element": "boolean" + "element": "string" } } }, @@ -266,7 +266,7 @@ "content": "votes" }, "value": { - "element": "number" + "element": "string" } } } diff --git a/test/fixtures/api/request-parameters.json b/test/fixtures/api/request-parameters.json index 6a74d2ffe..42bb8dfec 100644 --- a/test/fixtures/api/request-parameters.json +++ b/test/fixtures/api/request-parameters.json @@ -53,7 +53,7 @@ "content": "limit" }, "value": { - "element": "number", + "element": "string", "attributes": { "default": "20" } diff --git a/test/fixtures/api/request-parameters.sourcemap.json b/test/fixtures/api/request-parameters.sourcemap.json index 3ca5aa00f..5e7240e8f 100644 --- a/test/fixtures/api/request-parameters.sourcemap.json +++ b/test/fixtures/api/request-parameters.sourcemap.json @@ -162,7 +162,7 @@ "content": "limit" }, "value": { - "element": "number", + "element": "string", "attributes": { "default": { "element": "string", diff --git a/test/fixtures/api/resource-parameters.json b/test/fixtures/api/resource-parameters.json index c277cd523..a64200a6a 100644 --- a/test/fixtures/api/resource-parameters.json +++ b/test/fixtures/api/resource-parameters.json @@ -50,30 +50,30 @@ "samples": [ [ { - "element": "number", - "content": 23 + "element": "string", + "content": "23" } ] ], "default": [ { - "element": "number", - "content": 1 + "element": "string", + "content": "1" } ] }, "content": [ { - "element": "number", - "content": 37 + "element": "string", + "content": "37" }, { - "element": "number", - "content": 1 + "element": "string", + "content": "1" }, { - "element": "number", - "content": 23 + "element": "string", + "content": "23" } ] } diff --git a/test/fixtures/api/resource-parameters.sourcemap.json b/test/fixtures/api/resource-parameters.sourcemap.json index 829ed5cf6..5f568e6e9 100644 --- a/test/fixtures/api/resource-parameters.sourcemap.json +++ b/test/fixtures/api/resource-parameters.sourcemap.json @@ -147,7 +147,7 @@ "samples": [ [ { - "element": "number", + "element": "string", "attributes": { "sourceMap": [ { @@ -161,13 +161,13 @@ } ] }, - "content": 23 + "content": "23" } ] ], "default": [ { - "element": "number", + "element": "string", "attributes": { "sourceMap": [ { @@ -181,13 +181,13 @@ } ] }, - "content": 1 + "content": "1" } ] }, "content": [ { - "element": "number", + "element": "string", "attributes": { "sourceMap": [ { @@ -201,10 +201,10 @@ } ] }, - "content": 37 + "content": "37" }, { - "element": "number", + "element": "string", "attributes": { "sourceMap": [ { @@ -218,10 +218,10 @@ } ] }, - "content": 1 + "content": "1" }, { - "element": "number", + "element": "string", "attributes": { "sourceMap": [ { @@ -235,7 +235,7 @@ } ] }, - "content": 23 + "content": "23" } ] } From 0f26b27b62a9e66a3b372e7c68fd12b221588132 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 16 Jan 2017 08:29:52 +0000 Subject: [PATCH 2/8] fix(parameters): Provide a type label indicating the underlying type --- src/RefractAPI.cc | 4 ++ test/fixtures/api/action-parameters.json | 3 ++ .../api/action-parameters.sourcemap.json | 51 +++++++++++++++++++ test/fixtures/api/request-parameters.json | 1 + .../api/request-parameters.sourcemap.json | 17 +++++++ test/fixtures/api/resource-parameters.json | 1 + .../api/resource-parameters.sourcemap.json | 17 +++++++ test/fixtures/syntax/issue-350.json | 1 + 8 files changed, 95 insertions(+) diff --git a/src/RefractAPI.cc b/src/RefractAPI.cc index a36f0a5dd..919a8bf39 100644 --- a/src/RefractAPI.cc +++ b/src/RefractAPI.cc @@ -195,6 +195,10 @@ namespace drafter { element->meta[SerializeKey::Description] = PrimitiveToRefract(MAKE_NODE_INFO(parameter, description)); } + if (!parameter.node->type.empty()) { + element->attributes["typeLabel"] = PrimitiveToRefract(MAKE_NODE_INFO(parameter, type)); + } + // Parameter use std::string use = SerializeKey::Required; diff --git a/test/fixtures/api/action-parameters.json b/test/fixtures/api/action-parameters.json index 22b1698d5..b3ec85259 100644 --- a/test/fixtures/api/action-parameters.json +++ b/test/fixtures/api/action-parameters.json @@ -43,6 +43,7 @@ "description": "Username" }, "attributes": { + "typeLabel": "string", "typeAttributes": [ "required" ] @@ -78,6 +79,7 @@ { "element": "member", "attributes": { + "typeLabel": "boolean", "typeAttributes": [ "required" ] @@ -95,6 +97,7 @@ { "element": "member", "attributes": { + "typeLabel": "number", "typeAttributes": [ "required" ] diff --git a/test/fixtures/api/action-parameters.sourcemap.json b/test/fixtures/api/action-parameters.sourcemap.json index 09cfbadfc..5739ff642 100644 --- a/test/fixtures/api/action-parameters.sourcemap.json +++ b/test/fixtures/api/action-parameters.sourcemap.json @@ -139,6 +139,23 @@ } }, "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 117, + 40 + ] + ] + } + ] + }, + "content": "string" + }, "typeAttributes": [ "required" ] @@ -213,6 +230,23 @@ { "element": "member", "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 177, + 17 + ] + ] + } + ] + }, + "content": "boolean" + }, "typeAttributes": [ "required" ] @@ -243,6 +277,23 @@ { "element": "member", "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 200, + 15 + ] + ] + } + ] + }, + "content": "number" + }, "typeAttributes": [ "required" ] diff --git a/test/fixtures/api/request-parameters.json b/test/fixtures/api/request-parameters.json index 42bb8dfec..839d720ce 100644 --- a/test/fixtures/api/request-parameters.json +++ b/test/fixtures/api/request-parameters.json @@ -43,6 +43,7 @@ "description": "The maximum number of users to return." }, "attributes": { + "typeLabel": "number", "typeAttributes": [ "optional" ] diff --git a/test/fixtures/api/request-parameters.sourcemap.json b/test/fixtures/api/request-parameters.sourcemap.json index 5e7240e8f..4c083e720 100644 --- a/test/fixtures/api/request-parameters.sourcemap.json +++ b/test/fixtures/api/request-parameters.sourcemap.json @@ -139,6 +139,23 @@ } }, "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 95, + 66 + ] + ] + } + ] + }, + "content": "number" + }, "typeAttributes": [ "optional" ] diff --git a/test/fixtures/api/resource-parameters.json b/test/fixtures/api/resource-parameters.json index a64200a6a..18918152a 100644 --- a/test/fixtures/api/resource-parameters.json +++ b/test/fixtures/api/resource-parameters.json @@ -35,6 +35,7 @@ "description": "Database ID\n\nAdditional description" }, "attributes": { + "typeLabel": "number", "typeAttributes": [ "optional" ] diff --git a/test/fixtures/api/resource-parameters.sourcemap.json b/test/fixtures/api/resource-parameters.sourcemap.json index 5f568e6e9..96cf63706 100644 --- a/test/fixtures/api/resource-parameters.sourcemap.json +++ b/test/fixtures/api/resource-parameters.sourcemap.json @@ -119,6 +119,23 @@ } }, "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 69, + 47 + ] + ] + } + ] + }, + "content": "number" + }, "typeAttributes": [ "optional" ] diff --git a/test/fixtures/syntax/issue-350.json b/test/fixtures/syntax/issue-350.json index 689666481..5a901709c 100644 --- a/test/fixtures/syntax/issue-350.json +++ b/test/fixtures/syntax/issue-350.json @@ -32,6 +32,7 @@ { "element": "member", "attributes": { + "typeLabel": "string", "typeAttributes": [ "required" ] From 02179d9c3a7ef11e2b9fb301a8d4fd8ee449b8e9 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 16 Jan 2017 08:42:20 +0000 Subject: [PATCH 3/8] chore: Update integration test fixtures --- features/fixtures/ast.json | 6 ++++ features/fixtures/ast.sourcemap.json | 6 ++++ features/fixtures/ast.sourcemap.yaml | 6 ++++ features/fixtures/ast.yaml | 17 ++++++++++ features/fixtures/refract.json | 8 +++++ features/fixtures/refract.sourcemap.json | 40 ++++++++++++++++++++++++ features/fixtures/refract.sourcemap.yaml | 27 ++++++++++++++++ features/fixtures/refract.yaml | 23 ++++++++++++++ 8 files changed, 133 insertions(+) diff --git a/features/fixtures/ast.json b/features/fixtures/ast.json index 82d8c42e0..0e2684092 100644 --- a/features/fixtures/ast.json +++ b/features/fixtures/ast.json @@ -656,3 +656,9 @@ } ] } + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format diff --git a/features/fixtures/ast.sourcemap.json b/features/fixtures/ast.sourcemap.json index 88275375a..80da68ca8 100644 --- a/features/fixtures/ast.sourcemap.json +++ b/features/fixtures/ast.sourcemap.json @@ -1664,3 +1664,9 @@ } ] } + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format diff --git a/features/fixtures/ast.sourcemap.yaml b/features/fixtures/ast.sourcemap.yaml index dfd7f085d..d9ef08490 100644 --- a/features/fixtures/ast.sourcemap.yaml +++ b/features/fixtures/ast.sourcemap.yaml @@ -1109,3 +1109,9 @@ warnings: code: 4 message: "invalid value format for 'number' type. please check mson specification for valid format" location: [] + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format diff --git a/features/fixtures/ast.yaml b/features/fixtures/ast.yaml index 43888de97..d2fdce480 100644 --- a/features/fixtures/ast.yaml +++ b/features/fixtures/ast.yaml @@ -450,3 +450,20 @@ warnings: - index: 992 length: 45 + - + code: 4 + message: "invalid value format for 'number' type. please check mson specification for valid format" + location: + - + index: 200 + length: 102 + - + code: 4 + message: "invalid value format for 'number' type. please check mson specification for valid format" + location: [] + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format diff --git a/features/fixtures/refract.json b/features/fixtures/refract.json index f567b4763..79c0f1de9 100644 --- a/features/fixtures/refract.json +++ b/features/fixtures/refract.json @@ -65,6 +65,7 @@ "description": "" }, "attributes": { + "typeLabel": "", "typeAttributes": [ "optional" ] @@ -158,6 +159,7 @@ "description": "" }, "attributes": { + "typeLabel": "", "typeAttributes": [ "optional" ] @@ -879,3 +881,9 @@ } ] } + + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 diff --git a/features/fixtures/refract.sourcemap.json b/features/fixtures/refract.sourcemap.json index cf3fb0e00..17ca31bd3 100644 --- a/features/fixtures/refract.sourcemap.json +++ b/features/fixtures/refract.sourcemap.json @@ -184,6 +184,23 @@ } }, "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 516, + 86 + ] + ] + } + ] + }, + "content": "" + }, "typeAttributes": [ "optional" ] @@ -458,6 +475,23 @@ } }, "attributes": { + "typeLabel": { + "element": "string", + "attributes": { + "sourceMap": [ + { + "element": "sourceMap", + "content": [ + [ + 823, + 86 + ] + ] + } + ] + }, + "content": "" + }, "typeAttributes": [ "optional" ] @@ -2003,3 +2037,9 @@ } ] } + + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 diff --git a/features/fixtures/refract.sourcemap.yaml b/features/fixtures/refract.sourcemap.yaml index 0cfb08c19..6ab2ae671 100644 --- a/features/fixtures/refract.sourcemap.yaml +++ b/features/fixtures/refract.sourcemap.yaml @@ -122,6 +122,17 @@ content: - 86 content: "" attributes: + typeLabel: + element: "string" + attributes: + sourceMap: + - + element: "sourceMap" + content: + - + - 516 + - 86 + content: "" typeAttributes: - "optional" content: @@ -296,6 +307,17 @@ content: - 86 content: "" attributes: + typeLabel: + element: "string" + attributes: + sourceMap: + - + element: "sourceMap" + content: + - + - 823 + - 86 + content: "" typeAttributes: - "optional" content: @@ -1282,3 +1304,8 @@ content: - 102 content: "invalid value format for 'number' type. please check mson specification for valid format" + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 diff --git a/features/fixtures/refract.yaml b/features/fixtures/refract.yaml index 295c24523..7332a687a 100644 --- a/features/fixtures/refract.yaml +++ b/features/fixtures/refract.yaml @@ -48,6 +48,7 @@ content: meta: description: "" attributes: + typeLabel: "" typeAttributes: - "optional" content: @@ -110,6 +111,7 @@ content: meta: description: "" attributes: + typeLabel: "" typeAttributes: - "optional" content: @@ -568,3 +570,24 @@ content: - 992 - 45 content: "the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead" + - + element: "annotation" + meta: + classes: + - "warning" + attributes: + code: 4 + sourceMap: + - + element: "sourceMap" + content: + - + - 200 + - 102 + content: "invalid value format for 'number' type. please check mson specification for valid format" + + +OK. +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :685:45 +warning: (9) the 'headers' section at this level is deprecated and will be removed in a future, use respective payload header section(s) instead :992:45 +warning: (4) invalid value format for 'number' type. please check mson specification for valid format :200:102 From 12551f26d1dfc96be9e0f50ac705701219d36c8a Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 16 Jan 2017 12:43:43 +0000 Subject: [PATCH 4/8] chore: Add changelog entry for parameter string changes --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f02591891..5ceeae572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,16 @@ * Fix support for escaped MSON-style parameters. [#445](https://github.com/apiaryio/drafter/issues/445) +* Parameters values in API Elements are always serialized as API Element + strings. This ensure consistency with API Blueprint AST and to prevent + values being serialized differently. For example boolean of value `1` in API + Blueprint AST would be treated as a string and therefore be serialized as + `1`. However in API Elements it wouldn't be treated as truthy since `1` is + not equal to `true` and would be serialized as `false`. + +* Parameters in API Elements now contain a `typeLabel` which is a label + representing the type of the parameter that the user specified. + ## 3.2.2 From c38c510a47813520e61c27af12ae92f9ff9263bc Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Tue, 17 Jan 2017 13:23:56 +0000 Subject: [PATCH 5/8] refactor(parameters): Remove unnecessary templates --- src/RefractAPI.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/RefractAPI.cc b/src/RefractAPI.cc index 919a8bf39..b2390bc76 100644 --- a/src/RefractAPI.cc +++ b/src/RefractAPI.cc @@ -135,42 +135,39 @@ namespace drafter { return element; } - template refract::IElement* ParameterValuesToRefract(const NodeInfo& parameter, ConversionContext& context) { refract::ArrayElement* element = CollectionToRefract(MAKE_NODE_INFO(parameter, values), context, - LiteralToRefract, + LiteralToRefract, SerializeKey::Enum, refract::IElement::rDefault); // Add sample value if (!parameter.node->exampleValue.empty()) { refract::ArrayElement* samples = new refract::ArrayElement; - samples->push_back(CreateArrayElement(LiteralToRefract(MAKE_NODE_INFO(parameter, exampleValue), context), true)); + samples->push_back(CreateArrayElement(LiteralToRefract(MAKE_NODE_INFO(parameter, exampleValue), context), true)); element->attributes[SerializeKey::Samples] = samples; } // Add default value if (!parameter.node->defaultValue.empty()) { - element->attributes[SerializeKey::Default] = CreateArrayElement(LiteralToRefract(MAKE_NODE_INFO(parameter, defaultValue), context), true); + element->attributes[SerializeKey::Default] = CreateArrayElement(LiteralToRefract(MAKE_NODE_INFO(parameter, defaultValue), context), true); } return element; } - template refract::IElement* ExtractParameter(const NodeInfo& parameter, ConversionContext& context) { refract::IElement* element = NULL; if (parameter.node->values.empty()) { if (parameter.node->exampleValue.empty()) { - typedef typename refract::ElementTypeSelector::ElementType ElementType; - element = new ElementType; + element = new refract::StringElement; } else { - element = LiteralToRefract(MAKE_NODE_INFO(parameter, exampleValue), context); + element = LiteralToRefract(MAKE_NODE_INFO(parameter, exampleValue), context); } if (!parameter.node->defaultValue.empty()) { @@ -178,7 +175,7 @@ namespace drafter { } } else { - element = ParameterValuesToRefract(parameter, context); + element = ParameterValuesToRefract(parameter, context); } return element; @@ -187,7 +184,7 @@ namespace drafter { refract::IElement* ParameterToRefract(const NodeInfo& parameter, ConversionContext& context) { refract::MemberElement* element = new refract::MemberElement; - refract::IElement *value = ExtractParameter(parameter, context); + refract::IElement *value = ExtractParameter(parameter, context); element->set(PrimitiveToRefract(MAKE_NODE_INFO(parameter, name)), value); // Description From 3de28c0c8901dd85dd619b9773d6305a41e3634b Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Wed, 18 Jan 2017 14:52:48 +0000 Subject: [PATCH 6/8] chore(parameters): Add FIXME regarding typeLabel being extension --- src/RefractAPI.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/RefractAPI.cc b/src/RefractAPI.cc index b2390bc76..cd72eaec1 100644 --- a/src/RefractAPI.cc +++ b/src/RefractAPI.cc @@ -193,6 +193,11 @@ namespace drafter { } if (!parameter.node->type.empty()) { + // FIXME: `typeLabel` attribute is not described in API Elements + // specification. `typeLabel` is an extension for now as we should + // rethink for + // https://github.com/apiaryio/api-blueprint-rfcs/pull/3 + element->attributes["typeLabel"] = PrimitiveToRefract(MAKE_NODE_INFO(parameter, type)); } From b18ff3b854d961d9f33399cc5ddae90897ce2589 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 8 Feb 2017 01:25:46 +0530 Subject: [PATCH 7/8] fix(refract): Move typeLabel to meta.title for parameter --- features/fixtures/refract.json | 8 +++--- features/fixtures/refract.sourcemap.json | 20 +++++++------- features/fixtures/refract.sourcemap.yaml | 8 +++--- features/fixtures/refract.yaml | 4 +-- src/RefractAPI.cc | 8 ++---- test/fixtures/api/action-parameters.json | 12 ++++++--- .../api/action-parameters.sourcemap.json | 26 +++++++++++-------- test/fixtures/api/request-parameters.json | 4 +-- .../api/request-parameters.sourcemap.json | 10 +++---- test/fixtures/api/resource-parameters.json | 4 +-- .../api/resource-parameters.sourcemap.json | 10 +++---- test/fixtures/syntax/issue-350.json | 4 ++- 12 files changed, 62 insertions(+), 56 deletions(-) diff --git a/features/fixtures/refract.json b/features/fixtures/refract.json index 79c0f1de9..f4b0c613b 100644 --- a/features/fixtures/refract.json +++ b/features/fixtures/refract.json @@ -62,10 +62,10 @@ { "element": "member", "meta": { - "description": "" + "description": "", + "title": "" }, "attributes": { - "typeLabel": "", "typeAttributes": [ "optional" ] @@ -156,10 +156,10 @@ { "element": "member", "meta": { - "description": "" + "description": "", + "title": "" }, "attributes": { - "typeLabel": "", "typeAttributes": [ "optional" ] diff --git a/features/fixtures/refract.sourcemap.json b/features/fixtures/refract.sourcemap.json index 17ca31bd3..8e3a3760e 100644 --- a/features/fixtures/refract.sourcemap.json +++ b/features/fixtures/refract.sourcemap.json @@ -181,10 +181,8 @@ ] }, "content": "" - } - }, - "attributes": { - "typeLabel": { + }, + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -200,7 +198,9 @@ ] }, "content": "" - }, + } + }, + "attributes": { "typeAttributes": [ "optional" ] @@ -472,10 +472,8 @@ ] }, "content": "" - } - }, - "attributes": { - "typeLabel": { + }, + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -491,7 +489,9 @@ ] }, "content": "" - }, + } + }, + "attributes": { "typeAttributes": [ "optional" ] diff --git a/features/fixtures/refract.sourcemap.yaml b/features/fixtures/refract.sourcemap.yaml index 6ab2ae671..9f60ec4e4 100644 --- a/features/fixtures/refract.sourcemap.yaml +++ b/features/fixtures/refract.sourcemap.yaml @@ -121,8 +121,7 @@ content: - 516 - 86 content: "" - attributes: - typeLabel: + title: element: "string" attributes: sourceMap: @@ -133,6 +132,7 @@ content: - 516 - 86 content: "" + attributes: typeAttributes: - "optional" content: @@ -306,8 +306,7 @@ content: - 823 - 86 content: "" - attributes: - typeLabel: + title: element: "string" attributes: sourceMap: @@ -318,6 +317,7 @@ content: - 823 - 86 content: "" + attributes: typeAttributes: - "optional" content: diff --git a/features/fixtures/refract.yaml b/features/fixtures/refract.yaml index 7332a687a..89e248a8f 100644 --- a/features/fixtures/refract.yaml +++ b/features/fixtures/refract.yaml @@ -47,8 +47,8 @@ content: element: "member" meta: description: "" + title: "" attributes: - typeLabel: "" typeAttributes: - "optional" content: @@ -110,8 +110,8 @@ content: element: "member" meta: description: "" + title: "" attributes: - typeLabel: "" typeAttributes: - "optional" content: diff --git a/src/RefractAPI.cc b/src/RefractAPI.cc index cd72eaec1..c59a3975a 100644 --- a/src/RefractAPI.cc +++ b/src/RefractAPI.cc @@ -158,6 +158,7 @@ namespace drafter { return element; } + // NOTE: We removed type specific templates from here in https://github.com/apiaryio/drafter/pull/447 refract::IElement* ExtractParameter(const NodeInfo& parameter, ConversionContext& context) { refract::IElement* element = NULL; @@ -193,12 +194,7 @@ namespace drafter { } if (!parameter.node->type.empty()) { - // FIXME: `typeLabel` attribute is not described in API Elements - // specification. `typeLabel` is an extension for now as we should - // rethink for - // https://github.com/apiaryio/api-blueprint-rfcs/pull/3 - - element->attributes["typeLabel"] = PrimitiveToRefract(MAKE_NODE_INFO(parameter, type)); + element->meta[SerializeKey::Title] = PrimitiveToRefract(MAKE_NODE_INFO(parameter, type)); } // Parameter use diff --git a/test/fixtures/api/action-parameters.json b/test/fixtures/api/action-parameters.json index b3ec85259..2bcc173a3 100644 --- a/test/fixtures/api/action-parameters.json +++ b/test/fixtures/api/action-parameters.json @@ -40,10 +40,10 @@ { "element": "member", "meta": { - "description": "Username" + "description": "Username", + "title": "string" }, "attributes": { - "typeLabel": "string", "typeAttributes": [ "required" ] @@ -78,8 +78,10 @@ }, { "element": "member", + "meta": { + "title": "boolean" + }, "attributes": { - "typeLabel": "boolean", "typeAttributes": [ "required" ] @@ -96,8 +98,10 @@ }, { "element": "member", + "meta": { + "title": "number" + }, "attributes": { - "typeLabel": "number", "typeAttributes": [ "required" ] diff --git a/test/fixtures/api/action-parameters.sourcemap.json b/test/fixtures/api/action-parameters.sourcemap.json index 5739ff642..a52076e5a 100644 --- a/test/fixtures/api/action-parameters.sourcemap.json +++ b/test/fixtures/api/action-parameters.sourcemap.json @@ -136,10 +136,8 @@ ] }, "content": "Username" - } - }, - "attributes": { - "typeLabel": { + }, + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -155,7 +153,9 @@ ] }, "content": "string" - }, + } + }, + "attributes": { "typeAttributes": [ "required" ] @@ -229,8 +229,8 @@ }, { "element": "member", - "attributes": { - "typeLabel": { + "meta": { + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -246,7 +246,9 @@ ] }, "content": "boolean" - }, + } + }, + "attributes": { "typeAttributes": [ "required" ] @@ -276,8 +278,8 @@ }, { "element": "member", - "attributes": { - "typeLabel": { + "meta": { + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -293,7 +295,9 @@ ] }, "content": "number" - }, + } + }, + "attributes": { "typeAttributes": [ "required" ] diff --git a/test/fixtures/api/request-parameters.json b/test/fixtures/api/request-parameters.json index 839d720ce..a16007dd3 100644 --- a/test/fixtures/api/request-parameters.json +++ b/test/fixtures/api/request-parameters.json @@ -40,10 +40,10 @@ { "element": "member", "meta": { - "description": "The maximum number of users to return." + "description": "The maximum number of users to return.", + "title": "number" }, "attributes": { - "typeLabel": "number", "typeAttributes": [ "optional" ] diff --git a/test/fixtures/api/request-parameters.sourcemap.json b/test/fixtures/api/request-parameters.sourcemap.json index 4c083e720..9124d9153 100644 --- a/test/fixtures/api/request-parameters.sourcemap.json +++ b/test/fixtures/api/request-parameters.sourcemap.json @@ -136,10 +136,8 @@ ] }, "content": "The maximum number of users to return." - } - }, - "attributes": { - "typeLabel": { + }, + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -155,7 +153,9 @@ ] }, "content": "number" - }, + } + }, + "attributes": { "typeAttributes": [ "optional" ] diff --git a/test/fixtures/api/resource-parameters.json b/test/fixtures/api/resource-parameters.json index 18918152a..32fe25379 100644 --- a/test/fixtures/api/resource-parameters.json +++ b/test/fixtures/api/resource-parameters.json @@ -32,10 +32,10 @@ { "element": "member", "meta": { - "description": "Database ID\n\nAdditional description" + "description": "Database ID\n\nAdditional description", + "title": "number" }, "attributes": { - "typeLabel": "number", "typeAttributes": [ "optional" ] diff --git a/test/fixtures/api/resource-parameters.sourcemap.json b/test/fixtures/api/resource-parameters.sourcemap.json index 96cf63706..75f8ec5a1 100644 --- a/test/fixtures/api/resource-parameters.sourcemap.json +++ b/test/fixtures/api/resource-parameters.sourcemap.json @@ -116,10 +116,8 @@ ] }, "content": "Database ID\n\nAdditional description" - } - }, - "attributes": { - "typeLabel": { + }, + "title": { "element": "string", "attributes": { "sourceMap": [ @@ -135,7 +133,9 @@ ] }, "content": "number" - }, + } + }, + "attributes": { "typeAttributes": [ "optional" ] diff --git a/test/fixtures/syntax/issue-350.json b/test/fixtures/syntax/issue-350.json index 5a901709c..3bb017ebb 100644 --- a/test/fixtures/syntax/issue-350.json +++ b/test/fixtures/syntax/issue-350.json @@ -31,8 +31,10 @@ "content": [ { "element": "member", + "meta": { + "title": "string" + }, "attributes": { - "typeLabel": "string", "typeAttributes": [ "required" ] From 6b56fa90ace7c3e07db5e029a5aa90f059d4fec7 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 8 Feb 2017 21:47:26 +0530 Subject: [PATCH 8/8] chore: Release 3.2.4 --- CHANGELOG.md | 19 +++++++++---------- src/Version.h | 2 +- tools/homebrew/drafter.rb | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ceeae572..9248737ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,9 @@ # Drafter Changelog -## 3.2.3 +## 3.2.4 ### Bug Fixes -* Prevent exposing duplicate parameters in API Elements output when a - parameter is overshadowed. - -* Fix support for escaped MSON-style parameters. - [#445](https://github.com/apiaryio/drafter/issues/445) - * Parameters values in API Elements are always serialized as API Element strings. This ensure consistency with API Blueprint AST and to prevent values being serialized differently. For example boolean of value `1` in API @@ -17,9 +11,15 @@ `1`. However in API Elements it wouldn't be treated as truthy since `1` is not equal to `true` and would be serialized as `false`. -* Parameters in API Elements now contain a `typeLabel` which is a label - representing the type of the parameter that the user specified. +## 3.2.3 + +### Bug Fixes + +* Prevent exposing duplicate parameters in API Elements output when a + parameter is overshadowed. +* Fix support for escaped MSON-style parameters. + [#445](https://github.com/apiaryio/drafter/issues/445) ## 3.2.2 @@ -28,7 +28,6 @@ * Ensure that escaped property names in MSON are not treated as markdown. [snowcrash#422](https://github.com/apiaryio/snowcrash/pull/422) - ## 3.2.1 ### Bug Fixes diff --git a/src/Version.h b/src/Version.h index f7f0232b2..46ff94124 100644 --- a/src/Version.h +++ b/src/Version.h @@ -15,7 +15,7 @@ #define DRAFTER_MAJOR_VERSION 3 #define DRAFTER_MINOR_VERSION 2 -#define DRAFTER_PATCH_VERSION 3 +#define DRAFTER_PATCH_VERSION 4 #define DRAFTER_VERSION_IS_RELEASE 1 #define DRAFTER_PRE_RELEASE_VERSION 0 diff --git a/tools/homebrew/drafter.rb b/tools/homebrew/drafter.rb index 3b4b023b5..a8dbf836a 100644 --- a/tools/homebrew/drafter.rb +++ b/tools/homebrew/drafter.rb @@ -2,7 +2,7 @@ class Drafter < Formula homepage 'http://apiblueprint.org' - head 'https://github.com/apiaryio/drafter.git', :tag => 'v3.2.3' + head 'https://github.com/apiaryio/drafter.git', :tag => 'v3.2.4' def install system "./configure", "--shared"