-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
feat: allow defining schema format other than default #910
feat: allow defining schema format other than default #910
Conversation
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.
Leaving the suggestion here, as also voiced in today's spec 3.0 meeting.
Leave everything out that has to do with the new schema format that is now already known, and only focus on achieving the best structure possible, which enables us to add schemas with different schema formats in the components section.
This is to avoid clashing different discussions as it happened in today's meeting 🙂
I was thinking twice about "AsyncApi Schema object"
And the complexity will grow:
Do we really want that? |
Hi @GreenRover! Would you mind providing an update on how this is going? Are you still waiting for an answer on #910 (comment) or has been resolved after last meeting? Thank you so much! |
i still wait for response. needs to be discussed in next spec 3 meeting as it seams |
how can we get any progress in this discussion? |
Support for custom schema in header section was add. |
We should add a line somewhere mentioning there is no support for mixed schemas. |
in my proposal this is not possible by design. |
In today spec3.0 call https://youtu.be/hN6aE3Ebn08?t=1105 We came up with 3 options.
Option 1a:A separated component section. channels:
userSignUp:
address: 'users.{userId}'
messages:
userSignUp:
$ref: '#/components/messages/userSignUp'
parameters:
userId:
$ref: '#/components/parameters/userId'
components:
messages:
userSignUp:
headers:
$ref: '#components/schemas/MyHeaderSchema'
payload:
$ref: '#components/schemas/MyPayloadSchema'
schemas:
MyHeaderSchema:
// schemaFormat is not set == default: application/vnd.aai.asyncapi;version=3.0.0
schema:
$ref: '#components/asyncApiSchemas/MyPayloadSchema'
MyPayloadSchema:
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
schema:
$ref: '#components/asyncApiSchemas/MyPayloadSchema'
asyncApiSchemas: // in spec < 3.0 this was named "schema"
MyHeaderSchema:
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyPayloadSchema:
type: object
properties:
username:
type: string
email:
type: string
parameters:
userId:
description: The ID of the user.
schema:
type: string Option 1b:A separated component section. channels:
userSignUp:
address: 'users.{userId}'
messages:
userSignUp:
$ref: '#/components/messages/userSignUp'
parameters:
userId:
$ref: '#/components/parameters/userId'
components:
messages:
userSignUp:
headers:
$ref: '#components/multiFormatSchemas/MyHeaderSchema'
payload:
$ref: '#components/multiFormatSchemas/MyPayloadSchema'
userSignIn: // inline insted of using `multiFormatSchemas`
headers:
schema:
$ref: '#components/schema/MyHeaderSchema'
payload:
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
schema:
$ref: '#components/schema/MyPayloadSchema'
multiFormatSchemas:
MyHeaderSchema:
// schemaFormat is not set == default: application/vnd.aai.asyncapi;version=3.0.0
schema:
$ref: '#components/schemas/MyPayloadSchema'
MyPayloadSchema:
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
schema:
$ref: '#components/schemas/MyPayloadSchema'
schemas: // in spec < 3.0 this was named "schema"
MyHeaderSchema:
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyPayloadSchema:
type: object
properties:
username:
type: string
email:
type: string
parameters:
userId:
description: The ID of the user.
schema:
type: string Option 2a:
OR
Problem for the parser is, that $ref is only permitted to point to sub schemas with exact the same
channels:
userSignUp:
address: 'users.{userId}'
messages:
userSignUp:
$ref: '#/components/messages/userSignUp'
parameters:
userId:
$ref: '#/components/parameters/userId'
components:
messages:
userSignUp:
headers:
$ref: '#components/schemas/MyHeaderSchemaA'
payload:
$ref: '#components/schemas/MyPaloadAvroSchema'
userSignIn:
headers:
$ref: '#components/schema/MyHeaderSchemaB'
payload:
$ref: '#components/schema/MyPaloadAsyncApiSchema'
schemas: // can be of type "AsyncApi Schema object" or "Multi Format Schema Object"
MyHeaderSchemaA:
// schemaFormat is not set == default: application/vnd.aai.asyncapi;version=3.0.0
schema:
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyHeaderSchemaB:
// "schema" is missing so "AsyncApi Schema object" in version of document is assumed
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyPaloadAvroSchema:
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
schema: // refference to external schema server
$ref: 'https://schema.server.com/schemaXyz#/schema'
MyPaloadAsyncApiSchema:
schema:
type: object
properties:
username:
type: string
address:
$ref: '#components/schemas/address/schema'
address:
schema:
type: object
properties:
town:
type: string
zip:
type: string
street:
type: string
parameters:
userId:
description: The ID of the user.
schema:
type: string Option 2b:
OR
Problem for the parser is, that $ref is only permitted to point to sub schemas with exact the same
channels:
userSignUp:
address: 'users.{userId}'
messages:
userSignUp:
$ref: '#/components/messages/userSignUp'
parameters:
userId:
$ref: '#/components/parameters/userId'
components:
messages:
userSignUp:
headers:
$ref: '#components/schemas/MyHeaderSchema'
payload:
$ref: '#components/schemas/MyPaloadAvroSchema'
userSignIn:
headers:
$ref: '#components/schema/MyHeaderSchema'
payload:
$ref: '#components/schema/MyPaloadAsyncApiSchema'
schemas: // can be of type "AsyncApi Schema object" or "Multi Format Schema Object"
MyHeaderSchemaA:
// "schema" is missing so "AsyncApi Schema object" in version of document is assumed
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyPaloadAvroSchema:
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
schema: // refference to external schema server
$ref: 'https://schema.server.com/schemaXyz#/schema'
MyPaloadAsyncApiSchema:
type: object
properties:
username:
type: string
address:
$ref: '#components/schemas/address/schema'
address:
schema:
type: object
properties:
town:
type: string
zip:
type: string
street:
type: string
parameters:
userId:
description: The ID of the user.
schema:
type: string Option 3:
Problem: references channels:
userSignUp:
address: 'users.{userId}'
messages:
userSignUp:
$ref: '#/components/messages/userSignUp'
parameters:
userId:
$ref: '#/components/parameters/userId'
components:
messages:
userSignUp:
headers:
$ref: '#components/schemas/asyncapi/MyHeaderSchema'
payload:
$ref: '#components/schemas/application~1vnd.apache.avro;version=1.9.0/MyPaloadAvroSchema'
userSignIn:
headers:
$ref: '#components/schema/MyHeaderSchemaB'
payload:
$ref: '#components/schema/asyncapi/MyPaloadAsyncApiSchema'
asyncApi2.4Sample:
headers:
$ref: '#components/schema/MyHeaderSchemaB'
payload:
$ref: '#components/schemas/application~1vnd.aai.asyncapi;version=2.4.0/MyPaloadAsyncApiSchema'
schemas:
asyncapi: // well defined alias for async api in same version as defined in `info.version`.
MyHeaderSchema:
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyPaloadAsyncApiSchema:
type: object
properties:
username:
type: string
address:
$ref: '#components/schemas/asyncapi/address'
address:
type: object
properties:
town:
type: string
zip:
type: string
street:
type: string
application/vnd.aai.asyncapi;version=2.4.0:
MyPaloadAsyncApiSchema:
properties:
username:
type: string
address:
$ref: '#components/schemas/application~1vnd.aai.asyncapi;version=2.4.0/address'
address:
type: object
properties:
town:
type: string
zip:
type: string
street:
type: string
application/vnd.apache.avro;version=1.9.0:
MyPaloadAvroSchema:
$ref: 'https://schema.server.com/schemaXyz#/schema'
application/vnd.google.proto;version=3:
MyProtoType: |
syntax = "proto3";
// only a single root type is permitted
message MyProtoType {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
} |
Option 2 seems the most reasonable to me. It seems the best in terms of DX and doesn't look like a hack to me. |
I agree with @smoya here, option 2 seems like the better option.
Maybe a better clarification is to say; mixing between schema formats is NOT permitted under any circumstance. 🤔
Just to be sure, we are talking about letting Is there any reason to have schemaFormat optional? |
Is there any reason to have schemaFormat optional?
|
@GreenRover but either a user are using AsyncAPI Schema object, or they are not. If they are using the AsyncAPI Schema object it makes no sense to indent it within a If they are not using the AsyncAPI Schema object they would specify both schema and schemaFormat, right? 🤔 I just see the optional |
I.e. this is the optimal document in my eyes: schemas: // can be of type "AsyncApi Schema object" or "Multi Format Schema Object"
MyHeaderSchemaA:
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyHeaderSchemaB:
type: object
properties:
applicationInstanceId:
description: Unique identifier for a given instance of the publishing application
type: string
MyPaloadAvroSchema:
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
schema: // refference to external schema server
$ref: 'https://schema.server.com/schemaXyz#/schema'
MyPaloadAsyncApiSchema:
properties:
username:
type: string
address:
$ref: '#components/schemas/address'
address:
type: object
properties:
town:
type: string
zip:
type: string
street:
type: string |
@jonaslagoni you are right. And won the version "2b" |
I'm not fully sure what's the difference between 2a and 2b, would you mind putting an example? With that said, I think I'm more inclined to 2a but just want to make sure I fully understand it. Thanks for taking the time to lead this discussion, Heiko! 🙌 |
The examples are here: The difference:
and 2b only:
So 2b give you one way less to solace the same problem. |
2a 🚀 so basically example from Jonas -> #910 (comment) |
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.
Sorry, I'm not sure I understand what "In case that a Schema Object the schemaFormat will be assumed as..." means.
Can we rephrase the three occurrences of this to be clearer, please?
Am I right in guessing that it's saying "If this is a Schema Object, then the schemaFormat will be assumed to be..." ?
@dalelane This was phrase was modified in mean while. Better now? |
Where was it changed? I don't see any changes to the pull request. |
@dalelane Ok i found this sentence and changed it now as suggested |
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.
that was clearer - thank you
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.
LGTM 👍
Changed the PR title to meet the requirements. |
/rtm |
Hello, @GreenRover! 👋🏼 |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/rtm |
🎉 This PR is included in version 3.0.0-next-major-spec.12 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Please see issue #622