-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add schemaFormat + hasSchemaFormat to message
- Loading branch information
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { CorrelationId } from './correlation-id'; | ||
import { MessageExamples } from './message-examples'; | ||
import { MessageExample } from './message-example'; | ||
import { Schema } from './schema'; | ||
|
||
import { xParserMessageName } from '../../constants'; | ||
import { CoreModel } from './mixins'; | ||
|
||
import type { CorrelationIdInterface } from '../correlation-id'; | ||
import type { MessageExamplesInterface } from '../message-examples'; | ||
import type { SchemaInterface } from '../schema'; | ||
|
||
import type { v3 } from '../../spec-types'; | ||
|
||
export class MessageBase<J extends v3.MessageTraitObject = v3.MessageTraitObject> extends CoreModel<J, { id: string }> { | ||
id(): string { | ||
return this.messageId() || this._meta.id || this.extensions().get(xParserMessageName)?.value<string>() as string; | ||
} | ||
|
||
hasMessageId(): boolean { | ||
return !!this._json.messageId; | ||
} | ||
|
||
messageId(): string | undefined { | ||
return this._json.messageId; | ||
} | ||
|
||
hasCorrelationId(): boolean { | ||
return !!this._json.correlationId; | ||
} | ||
|
||
correlationId(): CorrelationIdInterface | undefined { | ||
if (!this._json.correlationId) return undefined; | ||
return this.createModel(CorrelationId, this._json.correlationId as v3.CorrelationIDObject, { pointer: this.jsonPath('correlationId') }); | ||
} | ||
|
||
hasContentType(): boolean { | ||
return !!this._json.contentType; | ||
} | ||
|
||
contentType(): string | undefined { | ||
return this._json.contentType || this._meta.asyncapi?.parsed?.defaultContentType; | ||
} | ||
|
||
hasHeaders(): boolean { | ||
return !!this._json.headers; | ||
} | ||
|
||
headers(): SchemaInterface | undefined { | ||
if (!this._json.headers) return undefined; | ||
return this.createModel(Schema, this._json.headers, { pointer: this.jsonPath('headers') }); | ||
} | ||
|
||
hasName(): boolean { | ||
return !!this._json.name; | ||
} | ||
|
||
name(): string | undefined { | ||
return this._json.name; | ||
} | ||
|
||
examples(): MessageExamplesInterface { | ||
return new MessageExamples( | ||
(this._json.examples || []).map((example: any, index: number) => { | ||
return this.createModel(MessageExample, example, { pointer: this.jsonPath(`examples/${index}`) }); | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters