|
335 | 335 | {% endmacro -%} |
336 | 336 |
|
337 | 337 | {% macro defineOneOfProperty(definitionName, prop, strictInterfaces, camelCasedPropNames) -%} |
| 338 | + {{- 'import * as t from "io-ts";' | addImport -}} |
| 339 | + |
338 | 340 | {% for schema in prop -%} |
339 | 341 | {% if schema.type == "object" %} |
340 | 342 | {% set name %}{{ definitionName }}{{ loop.index }}{% endset %} |
|
462 | 464 | {% elif definition.oneOf %} |
463 | 465 | {% set oneOfProps = definition.oneOf if definition.oneOf else definition.allOf %} |
464 | 466 |
|
465 | | - {{- 'import * as t from "io-ts";' | addImport -}} |
466 | | - |
467 | | - {% for schema in oneOfProps -%} |
468 | | - {% if schema.type == "object" %} |
469 | | - {{ defineObject(definitionName + loop.index, schema, strictInterfaces, camelCasedPropNames) }} |
470 | | - {% elif schema.$ref %} |
471 | | - {%- set realPropName = schema.$ref | splitBy("/") | last -%} |
472 | | - {{ importLocalProp(realPropName) }} |
473 | | - {% endif %} |
474 | | - {% endfor %} |
475 | | - |
476 | | - export const {{ definitionName }} = |
477 | | - t.union([ |
478 | | - {% for schema in oneOfProps -%} |
479 | | - {% if schema.type == "object" %} |
480 | | - {{ definitionName + loop.index }}, |
481 | | - {% elif schema.$ref %} |
482 | | - {{ schema.$ref | splitBy("/") | last }}, |
483 | | - {% endif %} |
484 | | - {% endfor %} |
485 | | - ], |
486 | | - "{{ definitionName }}" |
487 | | - ); |
488 | | - |
489 | | - export type {{ definitionName }} = t.TypeOf<typeof {{ definitionName }}>; |
| 467 | + {{ defineOneOfProperty(definitionName, oneOfProps, strictInterfaces, camelCasedPropNames) }} |
490 | 468 |
|
491 | 469 | {% elif definition.type == "number" %} |
492 | 470 |
|
|
0 commit comments