-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
fix: doc.allSchemas() skips now duplicates #897
Conversation
import type { SchemasInterface } from '../schemas'; | ||
import type { OperationInterface } from '../operation'; | ||
import type { ChannelInterface } from '../channel'; | ||
import type { ServerInterface } from '../server'; |
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.
Just reordering and tiding up imports
@@ -12,3 +16,24 @@ export type InferModelMetadata<T> = T extends BaseModel<infer _, infer M> ? M : | |||
export function createModel<T extends BaseModel>(Model: Constructor<T>, value: InferModelData<T>, meta: Omit<ModelMetadata, 'asyncapi'> & { asyncapi?: DetailedAsyncAPI } & InferModelMetadata<T>, parent?: BaseModel): T { | |||
return new Model(value, { ...meta, asyncapi: meta.asyncapi || parent?.meta().asyncapi }); | |||
} | |||
|
|||
export function schemasFromDocument<T extends SchemasInterface>(document: AsyncAPIDocumentInterface, SchemasModel: Constructor<T>, includeComponents: boolean): T { |
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.
Since the logic is exactly the same for both v2 and v3 models, I moved this to this common file.
@@ -213,6 +213,13 @@ describe('AsyncAPIDocument model', function() { | |||
const d = new AsyncAPIDocument(doc); | |||
expect(d.allSchemas()).toBeInstanceOf(Schemas); | |||
}); | |||
it('should return a collection of schemas (with schemas from components) without duplicates', function() { | |||
const sharedMessage = { payload: {} }; |
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.
Remember, we compare by "reference" and not by value.
Kudos, SonarCloud Quality Gate passed! |
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 👌
/rtm |
🎉 This PR is included in version 3.0.0-next-major-spec.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Fixes #896
Related issue(s)
#896