-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
chore(blog): websocket series part 2 #225
Conversation
Deploy preview for asyncapi-website processing. Building with commit 84ebdb0 https://app.netlify.com/sites/asyncapi-website/deploys/607ea7c000ddcf0007194851 |
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.
Love the artcile. Finally a much-needed blog post about WebSockets 👏
pages/blog/websocket-part2.md
Outdated
- errorMessage | ||
- required: | ||
- channelID | ||
- channelName |
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 doesn't make properties mutually exclusive, as you say above. Only the fact that it's required or not but all the three properties can coexist in an object as per this definition.
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.
you are rights, I should have not
specified too. Will add
pages/blog/websocket-part2.md
Outdated
- channelName | ||
``` | ||
|
||
I managed to get a structure that will be nicely rendered in the UI. Even code generation will work well. The problem is that I failed with DRY rule and have most of the structure repeated, which makes the solution error-prone. |
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.
You can still extract a big part of this schema. For instance, subscription
, status
, pair
, reqid
, and event
are the same so they can be extracted.
Also, another way to do this is to use allOf
. You define a schema that contains what's common between both schemas and then define the two as "allOf" of commonPart + specificPart. Less error prone.
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.
regarding allOf
how would I specify that you have object A or B in the end. allOf
means all, right? so all of common + specific, but the specific part has two different versions.
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.
ErrorMessage = allOf(common, specific)
RegularMessage = allOf(common, specific)
FinalMessage = oneOf(ErrorMessage, RegularMessage)
Does that make sense?
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.
you are right mate, loving it, no repetition too:
subscriptionStatus:
type: object
oneOf:
- allOf:
- properties:
errorMessage:
type: string
required:
- errorMessage
- $ref: '#/components/schemas/subscriptionStatusCommon'
- allOf:
- properties:
channelID:
type: integer
description: ChannelID on successful subscription, applicable to public messages only.
channelName:
type: string
description: Channel Name on successful subscription. For payloads 'ohlc' and 'book', respective interval or depth will be added as suffix.
required:
- channelID
- channelName
- $ref: '#/components/schemas/subscriptionStatusCommon'
subscriptionStatusCommon:
type: object
required:
- event
properties:
event:
type: string
const: subscriptionStatus
reqid:
$ref: '#/components/schemas/reqid'
pair:
$ref: '#/components/schemas/pair'
status:
$ref: '#/components/schemas/status'
subscription:
required:
- name
type: object
properties:
depth:
$ref: '#/components/schemas/depth'
interval:
$ref: '#/components/schemas/interval'
maxratecount:
$ref: '#/components/schemas/maxratecount'
name:
$ref: '#/components/schemas/name'
token:
$ref: '#/components/schemas/token'
and it is supported by our playground 💪🏼
I'll update the article,
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.
Only suggestion is to create different schemas for each allOf. This is hard to read 😅
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.
Co-authored-by: Fran Méndez <fmvilas@gmail.com>
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.
Great stuff mate! 👏
Description
See also: asyncapi/spec#253