-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required and Repeated fields #23
Conversation
rambleraptor
commented
Sep 8, 2024
- Add support for repeated fields on OpenAPI + proto
- Add support for required fields on proto (they're already implemented on OpenAPI)
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.
Nice! main concern is in the naming of "repeated".
example/bookstore/v1/bookstore.yaml
Outdated
@@ -8,6 +8,7 @@ resources: | |||
type: STRING | |||
number: 1 | |||
required: true | |||
repeated: true |
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 think really this is an array of strings - It'd be nice if we expressed it that way instead of "repeated" - that's really a proto colloquialism and not a term someone would use to describe this data type in any other context. I'd say it's either "Array" or "List".
Json describes things as :
{
"type": "array",
"items": {
"type": "number"
}
}
Expressing a tuple as
{
"type": "array",
"prefixItems": [
{ "type": "number" },
{ "type": "string" },
{ "enum": ["Street", "Avenue", "Boulevard"] },
{ "enum": ["NW", "NE", "SW", "SE"] }
]
}
Combining both into the "array" type feels weird to me, so I think a separation between list and tuple would make sense.
I think you would have to do something like:
type: ARRAY
element_type: STRING
WDYT?
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.
Yeah, I'm fine with this. As we move forward with defining objects inline, we'll probably have to change the logic here a bit.
I'm using a oneof to define both a primitive field and an object field. Any ideas to clean that up?
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.
Oof I see what you're getting at - having that oneof is not great.
What do you think about bool is_array
?
I know that's still "repeated" in terms of the schema, but I'd prefer to at least call the concept "is_array" instead.
The other option I can think of is to use oneof with a primitive enum, or an array type:
oneof types { // oneofs aren't even mentioned in textproto, so choose a name that won't collide with anything.
Type type;
ArrayType array;
}
Then I guess the declaration might look like:
type: bool
In the case of a primitive and
array:
item_type: bool
for an array.
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 think I'd like to find something that more comprehensively fits in with having full objects as well.
What about this? It's pretty much the same thing you're suggesting in your oneof, but I'm adding objects as well to show how that would look.
message Property {
oneof types {
Type type;
ObjectType object_type;
ArrayType array_type;
}
}
enum Type {
STRING;
DOUBLE;
....
}
message ObjectType {
oneof details {
repeated Property properties;
string message_name;
}
}
message ArrayType {
oneof array_details {
Type type;
ObjectType object_type;
}
}
I'll hold off on these changes until #22 goes in, since that might change some of the internal details. |
c24e865
to
742bcc4
Compare
@@ -73,4 +74,9 @@ message Property { | |||
|
|||
// If type is OBJECT, this is the name of the object in `messages`. | |||
string object_type = 5; | |||
|
|||
oneof array_type { | |||
string array_object_type = 6; |
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.
is this field still needed?
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.
This particular field is necessary to define arrays of objects. It'll look way cleaner with the new definition we have above.
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 think one field that may no longer be needed, but otherwise LGTM!