-
-
Notifications
You must be signed in to change notification settings - Fork 98
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: add all{components} functions #969
base: master
Are you sure you want to change the base?
Changes from all commits
02e8c8a
1ac0843
4a707e7
8d90dc4
065661f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import { SecuritySchemes } from './security-schemes'; | |
import { SecurityScheme } from './security-scheme'; | ||
import { Components } from './components'; | ||
import { Schemas } from './schemas'; | ||
import { Bindings } from './bindings'; | ||
import { Tags } from './tags'; | ||
|
||
import { extensions } from './mixins'; | ||
import { tilde } from '../../utils'; | ||
|
@@ -30,10 +32,172 @@ import type { SchemasInterface } from '../schemas'; | |
import type { OperationInterface } from '../operation'; | ||
import type { ChannelInterface } from '../channel'; | ||
import type { ServerInterface } from '../server'; | ||
import type { BindingsInterface } from 'models/bindings'; | ||
import type { ChannelParametersInterface } from 'models/channel-parameters'; | ||
import type { CorrelationIdsInterface } from 'models/correlation-ids'; | ||
import type { MessageTraitsInterface } from 'models/message-traits'; | ||
import type { OperationTraitsInterface } from 'models/operation-traits'; | ||
import type { ServerVariablesInterface } from 'models/server-variables'; | ||
import type { TagsInterface } from 'models/tags'; | ||
import type { Tag } from './tag'; | ||
import type { TagInterface } from 'models/tag'; | ||
|
||
import type { v3 } from '../../spec-types'; | ||
|
||
export class AsyncAPIDocument extends BaseModel<v3.AsyncAPIObject> implements AsyncAPIDocumentInterface { | ||
allSecuritySchemes(): SecuritySchemesInterface { | ||
return this.securitySchemes(); | ||
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 see two issues here:
cc @jonaslagoni please double 👀 just in case I'm delirious. 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 agree. it has only been added for the sake of completeness.
the problem is that when I try to access the security scheme of an specific not sure if this is a bug or I am missing something. 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. @smoya pingy pongy. |
||
} | ||
allServerVariables(): ServerVariablesInterface { | ||
const serverVariables: ServerVariablesInterface = this.components().serverVariables(); | ||
this.servers().forEach(server => { | ||
server.variables().forEach(variable => { | ||
if (!serverVariables.has(variable.id())) { | ||
serverVariables.push(variable); | ||
} | ||
}); | ||
}); | ||
|
||
return serverVariables; | ||
} | ||
allParameters(): ChannelParametersInterface { | ||
const parameters: ChannelParametersInterface = this.components().channelParameters(); | ||
this.channels().forEach(channel => { | ||
channel.parameters().forEach(parameter => { | ||
if (!parameters.includes(parameter)) { | ||
parameters.push(parameter); | ||
} | ||
}); | ||
}); | ||
return parameters; | ||
} | ||
|
||
allCorrelationIds(): CorrelationIdsInterface { | ||
const correlationIds: CorrelationIdsInterface = this.components().correlationIds(); | ||
this.allMessages().forEach(message => { | ||
const correlationId = message.correlationId(); | ||
if (correlationId) { | ||
correlationIds.push(correlationId); | ||
} | ||
}); | ||
|
||
this.allMessageTraits().forEach(trait => { | ||
const correlationId = trait.correlationId(); | ||
if (correlationId) { | ||
correlationIds.push(correlationId); | ||
} | ||
}); | ||
|
||
return correlationIds; | ||
} | ||
allTags(): TagsInterface { | ||
const tags: TagInterface[] = Object.values(this.components().json().tags || {}) || []; | ||
this.info().tags().forEach(tag => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
|
||
this.servers().forEach(server => { | ||
server.tags().forEach(tag => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
}); | ||
|
||
this.channels().forEach(channel => { | ||
(channel.json().tags || []).forEach((tag: Tag) => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
}); | ||
|
||
this.operations().forEach(operation => { | ||
operation.tags().forEach(tag => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
}); | ||
|
||
this.allOperationTraits().forEach(trait => { | ||
trait.tags().forEach(tag => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
}); | ||
|
||
this.allMessages().forEach(message => { | ||
message.tags().forEach(tag => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
}); | ||
|
||
this.allMessageTraits().forEach(trait => { | ||
trait.tags().forEach(tag => { | ||
if (!tags.includes(tag)) { | ||
tags.push(tag); | ||
} | ||
}); | ||
}); | ||
|
||
return new Tags(tags); | ||
} | ||
allOperationTraits(): OperationTraitsInterface { | ||
const traits: OperationTraitsInterface = this.components().operationTraits(); | ||
this.operations().forEach(operation => { | ||
operation.traits().forEach(trait => { | ||
if (!traits.includes(trait)) { | ||
traits.push(trait); | ||
} | ||
}); | ||
}); | ||
return traits; | ||
} | ||
allMessageTraits(): MessageTraitsInterface { | ||
const messageTraits: MessageTraitsInterface = this.components().messageTraits(); | ||
this.allMessages().forEach(message => { | ||
message.traits().forEach(trait => { | ||
if (!messageTraits.includes(trait)) { | ||
messageTraits.push(trait); | ||
} | ||
}); | ||
}); | ||
return messageTraits; | ||
} | ||
allServerBindings(): BindingsInterface { | ||
const serverBindings = Object.values(this.components().serverBindings()).flat(); | ||
this.allServers().forEach(server => server.bindings().forEach(binding => ( | ||
!serverBindings.some(b => b.json() === binding.json()) && serverBindings.push(binding) | ||
))); | ||
return new Bindings(serverBindings); | ||
} | ||
allChannelBindings(): BindingsInterface { | ||
const channelBindings = Object.values(this.components().channelBindings()).flat(); | ||
this.allChannels().forEach(channel => channel.bindings().forEach(binding => ( | ||
!channelBindings.some(b => b.json() === binding.json()) && channelBindings.push(binding) | ||
))); | ||
return new Bindings(channelBindings); | ||
} | ||
allOperationBindings(): BindingsInterface { | ||
const operationBindings = Object.values(this.components().operationBindings()).flat(); | ||
this.allOperations().forEach(operation => operation.bindings().forEach(binding => ( | ||
!operationBindings.some(b => b.json() === binding.json()) && operationBindings.push(binding) | ||
))); | ||
return new Bindings(operationBindings); | ||
} | ||
allMessageBindings(): BindingsInterface { | ||
const messageBindings = Object.values(this.components().messageBindings()).flat(); | ||
this.allMessages().forEach(message => message.bindings().forEach(binding => ( | ||
!messageBindings.some(b => b.json() === binding.json()) && messageBindings.push(binding) | ||
))); | ||
return new Bindings(messageBindings); | ||
} | ||
version(): string { | ||
return this._json.asyncapi; | ||
} | ||
|
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 missing
allReplies
https://github.com/asyncapi/parser-api/pull/111/files#diff-9eddf4dc51bf6a0125ca7fb094468ad284112270385c41cebce4f8f0a29620abR23There 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.
@smoya I'm a little confused about where to add the
allReplies
function. If I add it here, then v2 also needs to implement it. But v2 doesn't have replies. I see three possible approaches:allReplies
fromparser-api
since it can't be implemented for v2.allReplies
to v3 only.I would appreciate some insight on this.