Skip to content

Commit

Permalink
Stop using required, start using OptionalSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed May 30, 2024
1 parent 83b3ecc commit 2c9bf19
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions typescript_templates/model.vm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ $unknown.type ## force a template failure with an unknown type
#end
## Gets the Schema object for a given type.
#macro ( toSchema $param )
#if ( !$param.required )
new OptionalSchema(##
#end
#if ( $param.arrayType )
new ArraySchema(##
#end
Expand Down Expand Up @@ -100,6 +103,9 @@ $unknown.type ## force a template failure with an unknown type
#if ( $param.arrayType )
)##
#end
#if ( !$param.required )
)##
#end
#end
## Check if there's a class associated with this type
#macro ( isClassType $param )
Expand Down Expand Up @@ -283,7 +289,7 @@ ${prop.refType}##
/* eslint-disable no-use-before-define */
import { ensureBigInt, ensureSafeInteger } from '../../../../utils/utils.js';
import { Encodable, Schema } from '../../../../encoding/encoding.js';
import { NamedMapSchema, ArraySchema, Uint64Schema, StringSchema, BooleanSchema, ByteArraySchema } from '../../../../encoding/schema/index.js';
import { NamedMapSchema, ArraySchema, Uint64Schema, StringSchema, BooleanSchema, ByteArraySchema, OptionalSchema } from '../../../../encoding/schema/index.js';
import { base64ToBytes } from '../../../../encoding/binarydata.js';
#if ( $propFile.indexer == "false" )
import BlockHeader, { blockHeaderFromEncodingData, blockHeaderToEncodingData, BLOCK_HEADER_SCHEMA } from '../../../../types/blockHeader.js';
Expand Down Expand Up @@ -320,7 +326,7 @@ export class $def.name implements Encodable {
## we allow circular references to be handled properly.
(this.encodingSchemaValue as NamedMapSchema).entries.push(
#foreach( $prop in $props )
{ key: '$prop.propertyName', valueSchema: #toSchema($prop), required: $prop.required, omitEmpty: true },
{ key: '$prop.propertyName', valueSchema: #toSchema($prop), omitEmpty: true },
#end
);
}
Expand Down

0 comments on commit 2c9bf19

Please sign in to comment.