This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Support top level Reference Element when translating API Elements to JSON & JSON Schema #710
Merged
+609
−22
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,14 @@ namespace | |
so::Value renderValueSpecific(const NumberElement& element, TypeAttributes options); | ||
so::Value renderValueSpecific(const BooleanElement& element, TypeAttributes options); | ||
so::Value renderValueSpecific(const ExtendElement& element, TypeAttributes options); | ||
so::Value renderValueSpecific(const RefElement& element, TypeAttributes options); | ||
so::Value renderValue(const IElement& element, TypeAttributes options); | ||
|
||
template <typename T> | ||
void renderProperty(so::Object&, const T& element, TypeAttributes) | ||
{ | ||
LOG(error) << "invalid property element: " << element.element(); | ||
assert(false); | ||
abort(); | ||
} | ||
|
||
template <typename Element> | ||
|
@@ -117,7 +118,7 @@ namespace | |
so::Value renderValueSpecific(const T& element, TypeAttributes) | ||
{ | ||
LOG(error) << "invalid top level element: " << element.element(); | ||
assert(false); | ||
abort(); | ||
return so::Null{}; // unreachable | ||
} | ||
|
||
|
@@ -284,6 +285,12 @@ namespace | |
return renderValue(*merged, options); | ||
} | ||
|
||
so::Value renderValueSpecific(const RefElement& element, TypeAttributes options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder, could there be other cases where we would render a ref element outside an enum here? Trying to understand if there is perhaps some other test-coverage we should add for other types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should explore that. Also, minim has that |
||
{ | ||
const auto& resolved = resolve(element); | ||
return renderValue(resolved, passFlags(options)); | ||
} | ||
|
||
} // namespace | ||
|
||
namespace | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# GET / | ||
|
||
+ Response 200 (application/json) | ||
+ Attributes | ||
+ code (Post Code) | ||
|
||
# Data Structures | ||
|
||
## Post Code (enum) | ||
|
||
+ Include East Code | ||
|
||
## East Code (enum) | ||
|
||
+ EC2A | ||
+ E1 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the rationale behind changing assert to abort please, not sure I understand the reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we want to avoid continuing the program flow because we should never arrive there. Specifically, bug #709 caused a SIGSEGV by overflowing the stack through unchecked recursion - with an abort here, there would be the much nicer SIGABORT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, perhaps it would be better to avoid exiting the process though? Perhaps throwing std::exception would be better, the drafter_parse/validate function could catch and return appropriate error to caller?