src/Generator/Twig/js/message.twig
{% import 'js/macros.twig' as macros %}
{% set insertion_points = schema.language('js').get('insertion-points') %}
// @link {{ compile_options.domain }}/json-schema/{{ schema.id.vendor }}/{{ schema.id.package }}/{% if schema.id.category %}{{ schema.id.category }}/{% endif %}{{ schema.id.message }}/{{ schema.id.version }}.json#
{{ imports }}
export default class {{ schema_to_class_name(schema, true) }} extends Message {
/**
* @private
*
* @returns {Schema}
*/
static defineSchema() {
{% if schema.fields|length or schema.mixins|length %}
return new Schema('{{ schema.id }}', {{ schema_to_class_name(schema, true) }},
{% if schema.fields|length %}
[
{% for field in schema.fields %}
{{ macros.draw_field(field, 8) }}
{%- endfor %}
],
{% else %}
[],
{% endif %}
{%- if schema.mixins|length %}
[
{% for mixin in schema.mixins %}
{{ schema_to_fq_class_name(mixin, true) }}Mixin.create(),
{% endfor %}
],
{% endif %}
);
{% else %}
return new Schema('{{ schema.id }}', {{ schema_to_class_name(schema, true) }});
{% endif %}
}
{% if insertion_points %}
{{ indent_string(insertion_points.methods, 2) }}
{% endif %}
}
{% for mixin in schema.mixins %}
{% if mixin.mixins|length or mixin.language('js').get('insertion-points') %}
{{ schema_to_fq_class_name(mixin, true) }}Trait({{ schema_to_class_name(schema, true) }});
{% endif %}
{% endfor %}
{%- if schema.isLatestVersion() %}
MessageResolver.register('{{ schema.id.curie }}', {{ schema_to_class_name(schema, true) }});
{% endif %}
{%- if has_other_major_rev(schema) %}
MessageResolver.register('{{ schema.id.getCurieWithMajorRev() }}', {{ schema_to_class_name(schema, true) }});
{% endif %}
Object.freeze({{ schema_to_class_name(schema, true) }});
Object.freeze({{ schema_to_class_name(schema, true) }}.prototype);