Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/apidom-ls/src/config/asyncapi/message/complete/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ const messageComplete: ApidomCompletionItem[] = [
value: 'A reference to a message',
},
},
{
label: 'oneOf',
insertText: 'oneOf',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`oneOf` key is specific to **Operation.message** fixed field. The key is allowed here to specify multiple messages. However, **a message MUST be valid only against one of the message objects.**',
},
},
{
label: 'headers',
insertText: 'headers',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const operationMessageLint: LinterMeta = {
message: '"message" must be a Message Object',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['message'],
linterParams: [['message', 'operation-message-map']],
marker: 'value',
target: 'message',
data: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Attributes, Meta } from 'minim';
import { ObjectElement, ArrayElement } from '@swagger-api/apidom-core';

class OperationMessageMap extends ObjectElement {
static primaryClass = 'operation-message-map';

constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(OperationMessageMap.primaryClass);
}

get oneOf(): ArrayElement | undefined {
return this.get('oneOf');
}

set oneOf(oneOf: ArrayElement | undefined) {
this.set('oneOf', oneOf);
}
}

export default OperationMessageMap;
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import ChannelItemServersElement from '../../elements/nces/ChannelItemsServers';
import OAuthFlowScopesElement from '../../elements/nces/OAuthFlowScopes';
import OperationTraitsElement from '../../elements/nces/OperationTraits';
import ServerSecurityElement from '../../elements/nces/ServerSecurity';
import OperationMessageMapElement from '../../elements/nces/OperationMessageMap';
import OperationMessageElement from '../../elements/nces/OperationMessage';
import MessageExamplesElement from '../../elements/nces/MessageExamples';
import MessageTraitsElement from '../../elements/nces/MessageTraits';
Expand Down Expand Up @@ -872,6 +873,11 @@ const schema = {
return new OperationTraitElement(...args);
},
},
[OperationMessageMapElement.primaryClass]: {
oneOf(...args: any[]) {
return new OperationMessageElement(...args);
},
},
[OperationMessageElement.primaryClass]: {
'<*>': function asterisk(...args: any[]) {
return new MessageElement(...args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ObjectElement, isArrayElement, BREAK } from '@swagger-api/apidom-core';
import SpecificationVisitor from '../../SpecificationVisitor';
import FallbackVisitor from '../../FallbackVisitor';
import { isReferenceLikeElement } from '../../../predicates';
import OperationMessageMapElement from '../../../../elements/nces/OperationMessageMap';
import OperationMessageElement from '../../../../elements/nces/OperationMessage';

const MessageVisitor = stampit(SpecificationVisitor, FallbackVisitor, {
Expand All @@ -13,7 +14,7 @@ const MessageVisitor = stampit(SpecificationVisitor, FallbackVisitor, {
this.element = this.toRefractedElement(['document', 'objects', 'Reference'], objectElement);
this.element.setMetaProperty('referenced-element', 'message');
} else if (isArrayElement(objectElement.get('oneOf'))) {
this.element = new ObjectElement();
this.element = new OperationMessageMapElement();
const operationMessageElement = new OperationMessageElement();

objectElement.get('oneOf').forEach((item: ObjectElement) => {
Expand All @@ -28,7 +29,7 @@ const MessageVisitor = stampit(SpecificationVisitor, FallbackVisitor, {
operationMessageElement.push(element);
});

this.element.set('oneOf', operationMessageElement);
this.element.oneOf = operationMessageElement;
} else {
this.element = this.toRefractedElement(['document', 'objects', 'Message'], objectElement);
}
Expand Down