diff --git a/package.json b/package.json index 3d50502b..73a2965f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.0.2", + "version": "0.0.3", "description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", diff --git a/src/templates/javascript/partials/validationArray.hbs b/src/templates/javascript/partials/validationArray.hbs index 17565e0b..9fe4fecf 100644 --- a/src/templates/javascript/partials/validationArray.hbs +++ b/src/templates/javascript/partials/validationArray.hbs @@ -1,7 +1,5 @@ -{{~#>validationBasics~}} {{~#if link~}} -yup.array().of({{>validation link}}) +yup.array().of({{>validation link}}){{>validationBasics}} {{~else~}} -yup.array().of({{{base}}}.schema) +yup.array().of({{{base}}}.schema){{>validationBasics}} {{~/if~}} -{{~/validationBasics~}} diff --git a/src/templates/javascript/partials/validationBasics.hbs b/src/templates/javascript/partials/validationBasics.hbs index 4bd27569..7bd5d6f6 100644 --- a/src/templates/javascript/partials/validationBasics.hbs +++ b/src/templates/javascript/partials/validationBasics.hbs @@ -1 +1 @@ -{{>@partial-block}}{{#if isNullable}}.nullable(){{/if}}{{#if isRequired}}.required(){{/if}} +{{#if isNullable}}.nullable(){{/if}}{{#if isRequired}}.required(){{/if}} diff --git a/src/templates/javascript/partials/validationEnum.hbs b/src/templates/javascript/partials/validationEnum.hbs index ab0e5893..e0b712db 100644 --- a/src/templates/javascript/partials/validationEnum.hbs +++ b/src/templates/javascript/partials/validationEnum.hbs @@ -1,15 +1,13 @@ -{{~#>validationBasics~}} {{~#equals parent name~}} yup.mixed().oneOf([ {{#each enum}} {{{../parent}}}.{{{name}}}{{>comma}} {{/each}} -]) +]){{>validationBasics}} {{~else~}} yup.mixed().oneOf([ {{#each enum}} {{{value}}}{{>comma}} {{/each}} -]) +]){{>validationBasics}} {{~/equals~}} -{{~/validationBasics~}} diff --git a/src/templates/javascript/partials/validationGeneric.hbs b/src/templates/javascript/partials/validationGeneric.hbs index 67f129c3..8d8ce9a5 100644 --- a/src/templates/javascript/partials/validationGeneric.hbs +++ b/src/templates/javascript/partials/validationGeneric.hbs @@ -1,11 +1,9 @@ -{{~#>validationBasics~}} {{~#equals type 'boolean'~}} -yup.boolean() +yup.boolean(){{>validationBasics}} {{~else equals type 'number'~}} -yup.number() +yup.number(){{>validationBasics}} {{~else equals type 'string'~}} -yup.string() +yup.string(){{>validationBasics}} {{~else~}} -yup.mixed() +yup.mixed(){{>validationBasics}} {{~/equals~}} -{{~/validationBasics~}} diff --git a/src/templates/javascript/partials/validationInterface.hbs b/src/templates/javascript/partials/validationInterface.hbs index 3650f85a..1eb58318 100644 --- a/src/templates/javascript/partials/validationInterface.hbs +++ b/src/templates/javascript/partials/validationInterface.hbs @@ -1,10 +1,10 @@ -{{~#>validationBasics~}} +( {{#if extends}} {{#each extends}} {{{this}}}.schema.concat( {{/each}} {{/if}} -{{~#if properties~}} +{{#if properties}} yup.object().shape({ {{#each properties}} {{#equals ../parent name}} @@ -14,12 +14,12 @@ yup.object().shape({ {{/equals}} {{/each}} }).noUnknown() -{{~else~}} +{{else}} yup.object() -{{~/if~}} +{{/if}} {{#if extends}} {{#each extends}} ) {{/each}} {{/if}} -{{~/validationBasics~}} +){{>validationBasics}} diff --git a/src/templates/javascript/partials/validationReference.hbs b/src/templates/javascript/partials/validationReference.hbs index 2db6d704..9ad7d945 100644 --- a/src/templates/javascript/partials/validationReference.hbs +++ b/src/templates/javascript/partials/validationReference.hbs @@ -1,3 +1 @@ -{{~#>validationBasics~}} -{{{base}}}.schema -{{~/validationBasics~}} +{{{base}}}.schema{{>validationBasics}} diff --git a/src/templates/typescript/partials/exportGeneric.hbs b/src/templates/typescript/partials/exportGeneric.hbs index 3db13fe8..22df6b95 100644 --- a/src/templates/typescript/partials/exportGeneric.hbs +++ b/src/templates/typescript/partials/exportGeneric.hbs @@ -9,11 +9,11 @@ export namespace {{{name}}} { export const schema = {{>validation}}; - export async function validate(value: any): Promise<{{#>isNullable}}{{{name}}}{{/isNullable}}> { + export async function validate(value: any): Promise<{{{name}}}{{>isNullable}}> { return schema.validate(value, { strict: true }); } - export function validateSync(value: any): {{#>isNullable}}{{{name}}}{{/isNullable}} { + export function validateSync(value: any): {{{name}}}{{>isNullable}} { return schema.validateSync(value, { strict: true }); } } diff --git a/src/templates/typescript/partials/isNullable.hbs b/src/templates/typescript/partials/isNullable.hbs index d646a78d..7ef73e3d 100644 --- a/src/templates/typescript/partials/isNullable.hbs +++ b/src/templates/typescript/partials/isNullable.hbs @@ -1 +1 @@ -{{>@partial-block}}{{#if isNullable}} | null{{/if}} +{{#if isNullable}} | null{{/if}} diff --git a/src/templates/typescript/partials/typeArray.hbs b/src/templates/typescript/partials/typeArray.hbs index 9ce12ac3..042200cb 100644 --- a/src/templates/typescript/partials/typeArray.hbs +++ b/src/templates/typescript/partials/typeArray.hbs @@ -1,7 +1,5 @@ -{{~#>isNullable~}} {{~#if link~}} -Array<{{>type link}}> +Array<{{>type link}}>{{>isNullable}} {{~else~}} -Array<{{{type}}}> +Array<{{{type}}}>{{>isNullable}} {{~/if~}} -{{~/isNullable~}} diff --git a/src/templates/typescript/partials/typeDictionary.hbs b/src/templates/typescript/partials/typeDictionary.hbs index d834cb86..fce52e43 100644 --- a/src/templates/typescript/partials/typeDictionary.hbs +++ b/src/templates/typescript/partials/typeDictionary.hbs @@ -1,7 +1,5 @@ -{{~#>isNullable~}} {{~#if link~}} -Dictionary<{{>type link}}> +Dictionary<{{>type link}}>{{>isNullable}} {{~else~}} -Dictionary<{{{type}}}> +Dictionary<{{{type}}}>{{>isNullable}} {{~/if~}} -{{~/isNullable~}} diff --git a/src/templates/typescript/partials/typeEnum.hbs b/src/templates/typescript/partials/typeEnum.hbs index 14831619..5cc39eba 100644 --- a/src/templates/typescript/partials/typeEnum.hbs +++ b/src/templates/typescript/partials/typeEnum.hbs @@ -1,11 +1,9 @@ -{{~#>isNullable~}} {{~#if parent~}} -{{{parent}}}.{{{name}}} +{{{parent}}}.{{{name}}}{{>isNullable}} {{~else~}} ( {{~#each enum~}} {{{value}}}{{#unless @last}} | {{/unless}} {{~/each~}} -) +){{>isNullable}} {{~/if~}} -{{~/isNullable~}} diff --git a/src/templates/typescript/partials/typeGeneric.hbs b/src/templates/typescript/partials/typeGeneric.hbs index cadc8ddf..b98a9301 100644 --- a/src/templates/typescript/partials/typeGeneric.hbs +++ b/src/templates/typescript/partials/typeGeneric.hbs @@ -1,3 +1 @@ -{{~#>isNullable~}} -{{{base}}} -{{~/isNullable~}} +{{{base}}}{{>isNullable}} diff --git a/src/templates/typescript/partials/typeInterface.hbs b/src/templates/typescript/partials/typeInterface.hbs index e3d49b66..80348ffe 100644 --- a/src/templates/typescript/partials/typeInterface.hbs +++ b/src/templates/typescript/partials/typeInterface.hbs @@ -1,4 +1,3 @@ -{{~#>isNullable~}} {{~#if properties~}} { {{#each properties}} @@ -9,8 +8,7 @@ {{/if}} {{>isReadOnly}}{{{name}}}{{>isRequired}}: {{>type}}{{>comma}} {{/each}} -} +}{{>isNullable}} {{~else~}} any {{~/if~}} -{{~/isNullable~}} diff --git a/src/templates/typescript/partials/typeReference.hbs b/src/templates/typescript/partials/typeReference.hbs index cadc8ddf..b98a9301 100644 --- a/src/templates/typescript/partials/typeReference.hbs +++ b/src/templates/typescript/partials/typeReference.hbs @@ -1,3 +1 @@ -{{~#>isNullable~}} -{{{base}}} -{{~/isNullable~}} +{{{base}}}{{>isNullable}} diff --git a/src/templates/typescript/partials/validationArray.hbs b/src/templates/typescript/partials/validationArray.hbs index 435af8ab..45b32d06 100644 --- a/src/templates/typescript/partials/validationArray.hbs +++ b/src/templates/typescript/partials/validationArray.hbs @@ -1,7 +1,6 @@ -{{~#>validationBasics~}} {{~#if link~}} yup.array<{{>type link}}>().of({{>validation link}}) {{~else~}} -yup.array<{{#>isNullable}}{{{type}}}{{/isNullable}}>().of({{{base}}}.schema) +yup.array<{{{type}}}{{>isNullable}}>().of({{{base}}}.schema) {{~/if~}} -{{~/validationBasics~}} +{{>validationBasics}} diff --git a/src/templates/typescript/partials/validationBasics.hbs b/src/templates/typescript/partials/validationBasics.hbs index 4bd27569..7bd5d6f6 100644 --- a/src/templates/typescript/partials/validationBasics.hbs +++ b/src/templates/typescript/partials/validationBasics.hbs @@ -1 +1 @@ -{{>@partial-block}}{{#if isNullable}}.nullable(){{/if}}{{#if isRequired}}.required(){{/if}} +{{#if isNullable}}.nullable(){{/if}}{{#if isRequired}}.required(){{/if}} diff --git a/src/templates/typescript/partials/validationDictionary.hbs b/src/templates/typescript/partials/validationDictionary.hbs index 99762bb4..48df90de 100644 --- a/src/templates/typescript/partials/validationDictionary.hbs +++ b/src/templates/typescript/partials/validationDictionary.hbs @@ -8,8 +8,8 @@ yup.lazytype link}}>>(value => { ).noUnknown(); }) {{~else~}} -yup.lazyisNullable}}{{{type}}}{{/isNullable}}>>(value => { - return yup.objectisNullable}}{{{type}}}{{/isNullable}}>>().shape( +yup.lazyisNullable}}>>(value => { + return yup.objectisNullable}}>>().shape( Object.keys(value).reduce((object, key) => ({ ...object, [key]: {{{base}}}.schema diff --git a/src/templates/typescript/partials/validationEnum.hbs b/src/templates/typescript/partials/validationEnum.hbs index ac67ec64..59c9ecd4 100644 --- a/src/templates/typescript/partials/validationEnum.hbs +++ b/src/templates/typescript/partials/validationEnum.hbs @@ -1,15 +1,14 @@ -{{~#>validationBasics~}} {{~#equals parent name~}} yup.mixed<{{{name}}}>().oneOf([ {{#each enum}} {{{../parent}}}.{{{name}}}{{>comma}} {{/each}} -]) +]){{>validationBasics}} {{~else~}} -yup.mixed<{{#>isNullable}}{{{type}}}{{/isNullable}}>().oneOf([ +yup.mixed<{{{type}}}{{>isNullable}}>().oneOf([ {{#each enum}} {{{value}}}{{>comma}} {{/each}} -]) +]){{>validationBasics}} {{~/equals~}} -{{~/validationBasics~}} + diff --git a/src/templates/typescript/partials/validationGeneric.hbs b/src/templates/typescript/partials/validationGeneric.hbs index bbe3d6d5..860b8288 100644 --- a/src/templates/typescript/partials/validationGeneric.hbs +++ b/src/templates/typescript/partials/validationGeneric.hbs @@ -1,11 +1,9 @@ -{{~#>validationBasics~}} {{~#equals type 'boolean'~}} -yup.boolean() +yup.boolean(){{>validationBasics}} {{~else equals type 'number'~}} -yup.number() +yup.number(){{>validationBasics}} {{~else equals type 'string'~}} -yup.string() +yup.string(){{>validationBasics}} {{~else~}} -yup.mixed<{{#>isNullable}}{{{type}}}{{/isNullable}}>() +yup.mixed<{{{type}}}{{>isNullable}}>(){{>validationBasics}} {{~/equals~}} -{{~/validationBasics~}} diff --git a/src/templates/typescript/partials/validationInterface.hbs b/src/templates/typescript/partials/validationInterface.hbs index 5745498c..2eb769af 100644 --- a/src/templates/typescript/partials/validationInterface.hbs +++ b/src/templates/typescript/partials/validationInterface.hbs @@ -1,11 +1,11 @@ -{{~#>validationBasics~}} +( {{#if extends}} {{#each extends}} {{{this}}}.schema.concat( {{/each}} {{/if}} -{{~#if properties~}} -yup.object{{#unless isProperty}}{{#if name}}<{{{name}}}>{{/if}}{{/unless}}().shape({ +{{#if properties}} +yup.object().shape({ {{#each properties}} {{#equals ../parent name}} {{{name}}}: {{>validation parent=name}}{{>comma}} @@ -14,12 +14,12 @@ yup.object{{#unless isProperty}}{{#if name}}<{{{name}}}>{{/if}}{{/unless}}().sha {{/equals}} {{/each}} }).noUnknown() -{{~else~}} +{{else}} yup.object() -{{~/if~}} +{{/if}} {{#if extends}} {{#each extends}} ) {{/each}} {{/if}} -{{~/validationBasics~}} +){{>validationBasics}} diff --git a/src/templates/typescript/partials/validationReference.hbs b/src/templates/typescript/partials/validationReference.hbs index 2db6d704..9ad7d945 100644 --- a/src/templates/typescript/partials/validationReference.hbs +++ b/src/templates/typescript/partials/validationReference.hbs @@ -1,3 +1 @@ -{{~#>validationBasics~}} -{{{base}}}.schema -{{~/validationBasics~}} +{{{base}}}.schema{{>validationBasics}} diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 57dfe6f7..8be30d9f 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -500,10 +500,12 @@ import * as yup from 'yup'; export let ArrayWithProperties; (function (ArrayWithProperties) { - ArrayWithProperties.schema = yup.array().of(yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown()); + ArrayWithProperties.schema = yup.array().of(( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + )); ArrayWithProperties.validate = async function(value) { return ArrayWithProperties.schema.validate(value, { strict: true }); @@ -663,10 +665,12 @@ export let DictionaryWithProperties; return yup.object().shape( Object.keys(value).reduce((object, key) => ({ ...object, - [key]: yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown() + [key]: ( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + ) }), {}) ).noUnknown(); }); @@ -866,9 +870,11 @@ import * as yup from 'yup'; export let ModelLink; (function (ModelLink) { - ModelLink.schema = yup.object().shape({ - id: yup.string() - }).noUnknown(); + ModelLink.schema = ( + yup.object().shape({ + id: yup.string() + }).noUnknown() + ); ModelLink.validate = async function(value) { return ModelLink.schema.validate(value, { strict: true }); @@ -895,22 +901,24 @@ import * as yup from 'yup'; export let ModelThatExtends; (function (ModelThatExtends) { - ModelThatExtends.schema = ModelWithString.schema.concat( - yup.object().shape({ - propExtendsA: yup.string(), - propExtendsB: ModelWithString.schema - }).noUnknown()) - ; + ModelThatExtends.schema = ( + ModelWithString.schema.concat( + yup.object().shape({ + propExtendsA: yup.string(), + propExtendsB: ModelWithString.schema + }).noUnknown() + ) + ); - ModelThatExtends.validate = async function(value) { - return ModelThatExtends.schema.validate(value, { strict: true }); - }; + ModelThatExtends.validate = async function(value) { + return ModelThatExtends.schema.validate(value, { strict: true }); + }; - ModelThatExtends.validateSync = function(value) { - return ModelThatExtends.schema.validateSync(value, { strict: true }); - }; + ModelThatExtends.validateSync = function(value) { + return ModelThatExtends.schema.validateSync(value, { strict: true }); + }; - })(ModelThatExtends || (ModelThatExtends = {}));" +})(ModelThatExtends || (ModelThatExtends = {}));" `; exports[`generation v2 javascript file(./test/result/v2/javascript/models/ModelThatExtendsExtends.js): ./test/result/v2/javascript/models/ModelThatExtendsExtends.js 1`] = ` @@ -928,24 +936,26 @@ import * as yup from 'yup'; export let ModelThatExtendsExtends; (function (ModelThatExtendsExtends) { - ModelThatExtendsExtends.schema = ModelWithString.schema.concat( - ModelThatExtends.schema.concat( - yup.object().shape({ - propExtendsC: yup.string(), - propExtendsD: ModelWithString.schema - }).noUnknown()) + ModelThatExtendsExtends.schema = ( + ModelWithString.schema.concat( + ModelThatExtends.schema.concat( + yup.object().shape({ + propExtendsC: yup.string(), + propExtendsD: ModelWithString.schema + }).noUnknown() + ) ) - ; + ); - ModelThatExtendsExtends.validate = async function(value) { - return ModelThatExtendsExtends.schema.validate(value, { strict: true }); - }; + ModelThatExtendsExtends.validate = async function(value) { + return ModelThatExtendsExtends.schema.validate(value, { strict: true }); + }; - ModelThatExtendsExtends.validateSync = function(value) { - return ModelThatExtendsExtends.schema.validateSync(value, { strict: true }); - }; + ModelThatExtendsExtends.validateSync = function(value) { + return ModelThatExtendsExtends.schema.validateSync(value, { strict: true }); + }; - })(ModelThatExtendsExtends || (ModelThatExtendsExtends = {}));" +})(ModelThatExtendsExtends || (ModelThatExtendsExtends = {}));" `; exports[`generation v2 javascript file(./test/result/v2/javascript/models/ModelWithArray.js): ./test/result/v2/javascript/models/ModelWithArray.js 1`] = ` @@ -962,11 +972,13 @@ import * as yup from 'yup'; export let ModelWithArray; (function (ModelWithArray) { - ModelWithArray.schema = yup.object().shape({ - prop: yup.array().of(ModelWithString.schema), - propWithFile: yup.array().of(yup.mixed()), - propWithNumber: yup.array().of(yup.number()) - }).noUnknown(); + ModelWithArray.schema = ( + yup.object().shape({ + prop: yup.array().of(ModelWithString.schema), + propWithFile: yup.array().of(yup.mixed()), + propWithNumber: yup.array().of(yup.number()) + }).noUnknown() + ); ModelWithArray.validate = async function(value) { return ModelWithArray.schema.validate(value, { strict: true }); @@ -992,9 +1004,11 @@ import * as yup from 'yup'; export let ModelWithBoolean; (function (ModelWithBoolean) { - ModelWithBoolean.schema = yup.object().shape({ - prop: yup.boolean() - }).noUnknown(); + ModelWithBoolean.schema = ( + yup.object().shape({ + prop: yup.boolean() + }).noUnknown() + ); ModelWithBoolean.validate = async function(value) { return ModelWithBoolean.schema.validate(value, { strict: true }); @@ -1020,9 +1034,11 @@ import * as yup from 'yup'; export let ModelWithCircularReference; (function (ModelWithCircularReference) { - ModelWithCircularReference.schema = yup.object().shape({ - prop: ModelWithCircularReference.schema - }).noUnknown(); + ModelWithCircularReference.schema = ( + yup.object().shape({ + prop: ModelWithCircularReference.schema + }).noUnknown() + ); ModelWithCircularReference.validate = async function(value) { return ModelWithCircularReference.schema.validate(value, { strict: true }); @@ -1049,16 +1065,18 @@ import * as yup from 'yup'; export let ModelWithDictionary; (function (ModelWithDictionary) { - ModelWithDictionary.schema = yup.object().shape({ - prop: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.string() - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + ModelWithDictionary.schema = ( + yup.object().shape({ + prop: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.string() + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); ModelWithDictionary.validate = async function(value) { return ModelWithDictionary.schema.validate(value, { strict: true }); @@ -1085,11 +1103,13 @@ import * as yup from 'yup'; export let ModelWithDuplicateImports; (function (ModelWithDuplicateImports) { - ModelWithDuplicateImports.schema = yup.object().shape({ - propA: ModelWithString.schema, - propB: ModelWithString.schema, - propC: ModelWithString.schema - }).noUnknown(); + ModelWithDuplicateImports.schema = ( + yup.object().shape({ + propA: ModelWithString.schema, + propB: ModelWithString.schema, + propC: ModelWithString.schema + }).noUnknown() + ); ModelWithDuplicateImports.validate = async function(value) { return ModelWithDuplicateImports.schema.validate(value, { strict: true }); @@ -1116,9 +1136,11 @@ import * as yup from 'yup'; export let ModelWithDuplicateProperties; (function (ModelWithDuplicateProperties) { - ModelWithDuplicateProperties.schema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + ModelWithDuplicateProperties.schema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); ModelWithDuplicateProperties.validate = async function(value) { return ModelWithDuplicateProperties.schema.validate(value, { strict: true }); @@ -1153,13 +1175,15 @@ export let ModelWithEnum; ERROR: 'Error' }; - ModelWithEnum.schema = yup.object().shape({ - test: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }).noUnknown(); + ModelWithEnum.schema = ( + yup.object().shape({ + test: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }).noUnknown() + ); ModelWithEnum.validate = async function(value) { return ModelWithEnum.schema.validate(value, { strict: true }); @@ -1194,13 +1218,15 @@ export let ModelWithEnumFromDescription; ERROR: 3 }; - ModelWithEnumFromDescription.schema = yup.object().shape({ - test: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }).noUnknown(); + ModelWithEnumFromDescription.schema = ( + yup.object().shape({ + test: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }).noUnknown() + ); ModelWithEnumFromDescription.validate = async function(value) { return ModelWithEnumFromDescription.schema.validate(value, { strict: true }); @@ -1226,9 +1252,11 @@ import * as yup from 'yup'; export let ModelWithInteger; (function (ModelWithInteger) { - ModelWithInteger.schema = yup.object().shape({ - prop: yup.number() - }).noUnknown(); + ModelWithInteger.schema = ( + yup.object().shape({ + prop: yup.number() + }).noUnknown() + ); ModelWithInteger.validate = async function(value) { return ModelWithInteger.schema.validate(value, { strict: true }); @@ -1256,9 +1284,11 @@ import * as yup from 'yup'; export let ModelWithLink; (function (ModelWithLink) { - ModelWithLink.schema = yup.object().shape({ - prop: ModelLink.schema - }).noUnknown(); + ModelWithLink.schema = ( + yup.object().shape({ + prop: ModelLink.schema + }).noUnknown() + ); ModelWithLink.validate = async function(value) { return ModelWithLink.schema.validate(value, { strict: true }); @@ -1285,42 +1315,44 @@ import * as yup from 'yup'; export let ModelWithNestedEnums; (function (ModelWithNestedEnums) { - ModelWithNestedEnums.schema = yup.object().shape({ - arrayWithDescription: yup.array().of(yup.mixed().oneOf([ - 1, - 2, - 3 - ])), - arrayWithEnum: yup.array().of(yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ])), - dictionaryWithEnum: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }), {}) - ).noUnknown(); - }), - dictionaryWithEnumFromDescription: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + ModelWithNestedEnums.schema = ( + yup.object().shape({ + arrayWithDescription: yup.array().of(yup.mixed().oneOf([ + 1, + 2, + 3 + ])), + arrayWithEnum: yup.array().of(yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ])), + dictionaryWithEnum: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }), {}) + ).noUnknown(); + }), + dictionaryWithEnumFromDescription: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); ModelWithNestedEnums.validate = async function(value) { return ModelWithNestedEnums.schema.validate(value, { strict: true }); @@ -1346,13 +1378,19 @@ import * as yup from 'yup'; export let ModelWithNestedProperties; (function (ModelWithNestedProperties) { - ModelWithNestedProperties.schema = yup.object().shape({ - first: yup.object().shape({ - second: yup.object().shape({ - third: yup.string().required() - }).noUnknown().required() - }).noUnknown().required() - }).noUnknown(); + ModelWithNestedProperties.schema = ( + yup.object().shape({ + first: ( + yup.object().shape({ + second: ( + yup.object().shape({ + third: yup.string().required() + }).noUnknown() + ).required() + }).noUnknown() + ).required() + }).noUnknown() + ); ModelWithNestedProperties.validate = async function(value) { return ModelWithNestedProperties.schema.validate(value, { strict: true }); @@ -1379,14 +1417,16 @@ import * as yup from 'yup'; export let ModelWithProperties; (function (ModelWithProperties) { - ModelWithProperties.schema = yup.object().shape({ - boolean: yup.boolean(), - number: yup.number(), - reference: ModelWithString.schema, - required: yup.string().required(), - requiredAndReadOnly: yup.string().required(), - string: yup.string() - }).noUnknown(); + ModelWithProperties.schema = ( + yup.object().shape({ + boolean: yup.boolean(), + number: yup.number(), + reference: ModelWithString.schema, + required: yup.string().required(), + requiredAndReadOnly: yup.string().required(), + string: yup.string() + }).noUnknown() + ); ModelWithProperties.validate = async function(value) { return ModelWithProperties.schema.validate(value, { strict: true }); @@ -1413,9 +1453,11 @@ import * as yup from 'yup'; export let ModelWithReference; (function (ModelWithReference) { - ModelWithReference.schema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + ModelWithReference.schema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); ModelWithReference.validate = async function(value) { return ModelWithReference.schema.validate(value, { strict: true }); @@ -1441,9 +1483,11 @@ import * as yup from 'yup'; export let ModelWithString; (function (ModelWithString) { - ModelWithString.schema = yup.object().shape({ - prop: yup.string() - }).noUnknown(); + ModelWithString.schema = ( + yup.object().shape({ + prop: yup.string() + }).noUnknown() + ); ModelWithString.validate = async function(value) { return ModelWithString.schema.validate(value, { strict: true }); @@ -2547,10 +2591,12 @@ export namespace ArrayWithProperties { export const schema = yup.array<{ foo?: string, bar?: string - }>().of(yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown()); + }>().of(( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + )); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -2736,10 +2782,12 @@ export namespace DictionaryWithProperties { }>>().shape( Object.keys(value).reduce((object, key) => ({ ...object, - [key]: yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown() + [key]: ( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + ) }), {}) ).noUnknown(); }); @@ -2947,9 +2995,11 @@ export interface ModelLink { export namespace ModelLink { - export const schema: yup.ObjectSchema = yup.object().shape({ - id: yup.string() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + id: yup.string() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -2980,21 +3030,23 @@ export interface ModelThatExtends extends ModelWithString { export namespace ModelThatExtends { - export const schema: yup.ObjectSchema = ModelWithString.schema.concat( - yup.object().shape({ - propExtendsA: yup.string(), - propExtendsB: ModelWithString.schema - }).noUnknown()) - ; + export const schema: yup.ObjectSchema = ( + ModelWithString.schema.concat( + yup.object().shape({ + propExtendsA: yup.string(), + propExtendsB: ModelWithString.schema + }).noUnknown() + ) + ); - export async function validate(value: any): Promise { - return schema.validate(value, { strict: true }); - } + export async function validate(value: any): Promise { + return schema.validate(value, { strict: true }); + } - export function validateSync(value: any): ModelThatExtends { - return schema.validateSync(value, { strict: true }); - } - }" + export function validateSync(value: any): ModelThatExtends { + return schema.validateSync(value, { strict: true }); + } +}" `; exports[`generation v2 typescript file(./test/result/v2/typescript/models/ModelThatExtendsExtends.ts): ./test/result/v2/typescript/models/ModelThatExtendsExtends.ts 1`] = ` @@ -3017,23 +3069,25 @@ export interface ModelThatExtendsExtends extends ModelWithString, ModelThatExten export namespace ModelThatExtendsExtends { - export const schema: yup.ObjectSchema = ModelWithString.schema.concat( - ModelThatExtends.schema.concat( - yup.object().shape({ - propExtendsC: yup.string(), - propExtendsD: ModelWithString.schema - }).noUnknown()) + export const schema: yup.ObjectSchema = ( + ModelWithString.schema.concat( + ModelThatExtends.schema.concat( + yup.object().shape({ + propExtendsC: yup.string(), + propExtendsD: ModelWithString.schema + }).noUnknown() + ) ) - ; + ); - export async function validate(value: any): Promise { - return schema.validate(value, { strict: true }); - } + export async function validate(value: any): Promise { + return schema.validate(value, { strict: true }); + } - export function validateSync(value: any): ModelThatExtendsExtends { - return schema.validateSync(value, { strict: true }); - } - }" + export function validateSync(value: any): ModelThatExtendsExtends { + return schema.validateSync(value, { strict: true }); + } +}" `; exports[`generation v2 typescript file(./test/result/v2/typescript/models/ModelWithArray.ts): ./test/result/v2/typescript/models/ModelWithArray.ts 1`] = ` @@ -3056,11 +3110,13 @@ export interface ModelWithArray { export namespace ModelWithArray { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.array().of(ModelWithString.schema), - propWithFile: yup.array().of(yup.mixed()), - propWithNumber: yup.array().of(yup.number()) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.array().of(ModelWithString.schema), + propWithFile: yup.array().of(yup.mixed()), + propWithNumber: yup.array().of(yup.number()) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3092,9 +3148,11 @@ export interface ModelWithBoolean { export namespace ModelWithBoolean { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.boolean() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.boolean() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3123,9 +3181,11 @@ export interface ModelWithCircularReference { export namespace ModelWithCircularReference { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelWithCircularReference.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelWithCircularReference.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3155,16 +3215,18 @@ export interface ModelWithDictionary { export namespace ModelWithDictionary { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.string() - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.string() + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3196,11 +3258,13 @@ export interface ModelWithDuplicateImports { export namespace ModelWithDuplicateImports { - export const schema: yup.ObjectSchema = yup.object().shape({ - propA: ModelWithString.schema, - propB: ModelWithString.schema, - propC: ModelWithString.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + propA: ModelWithString.schema, + propB: ModelWithString.schema, + propC: ModelWithString.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3230,9 +3294,11 @@ export interface ModelWithDuplicateProperties { export namespace ModelWithDuplicateProperties { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3273,13 +3339,15 @@ export namespace ModelWithEnum { ERROR = 'Error' } - export const schema: yup.ObjectSchema = yup.object().shape({ - test: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + test: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3320,13 +3388,15 @@ export namespace ModelWithEnumFromDescription { ERROR = 3 } - export const schema: yup.ObjectSchema = yup.object().shape({ - test: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + test: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3358,9 +3428,11 @@ export interface ModelWithInteger { export namespace ModelWithInteger { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.number() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.number() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3391,9 +3463,11 @@ export interface ModelWithLink { export namespace ModelWithLink { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelLink.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelLink.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3426,42 +3500,44 @@ export interface ModelWithNestedEnums { export namespace ModelWithNestedEnums { - export const schema: yup.ObjectSchema = yup.object().shape({ - arrayWithDescription: yup.array<(1 | 2 | 3)>().of(yup.mixed().oneOf([ - 1, - 2, - 3 - ])), - arrayWithEnum: yup.array<('Success' | 'Warning' | 'Error')>().of(yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ])), - dictionaryWithEnum: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }), {}) - ).noUnknown(); - }), - dictionaryWithEnumFromDescription: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + arrayWithDescription: yup.array<(1 | 2 | 3)>().of(yup.mixed().oneOf([ + 1, + 2, + 3 + ])), + arrayWithEnum: yup.array<('Success' | 'Warning' | 'Error')>().of(yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ])), + dictionaryWithEnum: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }), {}) + ).noUnknown(); + }), + dictionaryWithEnumFromDescription: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3494,13 +3570,19 @@ export interface ModelWithNestedProperties { export namespace ModelWithNestedProperties { - export const schema: yup.ObjectSchema = yup.object().shape({ - first: yup.object().shape({ - second: yup.object().shape({ - third: yup.string().required() - }).noUnknown().required() - }).noUnknown().required() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + first: ( + yup.object().shape({ + second: ( + yup.object().shape({ + third: yup.string().required() + }).noUnknown() + ).required() + }).noUnknown() + ).required() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3535,14 +3617,16 @@ export interface ModelWithProperties { export namespace ModelWithProperties { - export const schema: yup.ObjectSchema = yup.object().shape({ - boolean: yup.boolean(), - number: yup.number(), - reference: ModelWithString.schema, - required: yup.string().required(), - requiredAndReadOnly: yup.string().required(), - string: yup.string() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + boolean: yup.boolean(), + number: yup.number(), + reference: ModelWithString.schema, + required: yup.string().required(), + requiredAndReadOnly: yup.string().required(), + string: yup.string() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3572,9 +3656,11 @@ export interface ModelWithReference { export namespace ModelWithReference { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -3606,9 +3692,11 @@ export interface ModelWithString { export namespace ModelWithString { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.string() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.string() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -4673,10 +4761,12 @@ import * as yup from 'yup'; export let ArrayWithProperties; (function (ArrayWithProperties) { - ArrayWithProperties.schema = yup.array().of(yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown()); + ArrayWithProperties.schema = yup.array().of(( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + )); ArrayWithProperties.validate = async function(value) { return ArrayWithProperties.schema.validate(value, { strict: true }); @@ -4836,10 +4926,12 @@ export let DictionaryWithProperties; return yup.object().shape( Object.keys(value).reduce((object, key) => ({ ...object, - [key]: yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown() + [key]: ( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + ) }), {}) ).noUnknown(); }); @@ -5039,9 +5131,11 @@ import * as yup from 'yup'; export let ModelLink; (function (ModelLink) { - ModelLink.schema = yup.object().shape({ - id: yup.string() - }).noUnknown(); + ModelLink.schema = ( + yup.object().shape({ + id: yup.string() + }).noUnknown() + ); ModelLink.validate = async function(value) { return ModelLink.schema.validate(value, { strict: true }); @@ -5068,22 +5162,24 @@ import * as yup from 'yup'; export let ModelThatExtends; (function (ModelThatExtends) { - ModelThatExtends.schema = ModelWithString.schema.concat( - yup.object().shape({ - propExtendsA: yup.string(), - propExtendsB: ModelWithString.schema - }).noUnknown()) - ; + ModelThatExtends.schema = ( + ModelWithString.schema.concat( + yup.object().shape({ + propExtendsA: yup.string(), + propExtendsB: ModelWithString.schema + }).noUnknown() + ) + ); - ModelThatExtends.validate = async function(value) { - return ModelThatExtends.schema.validate(value, { strict: true }); - }; + ModelThatExtends.validate = async function(value) { + return ModelThatExtends.schema.validate(value, { strict: true }); + }; - ModelThatExtends.validateSync = function(value) { - return ModelThatExtends.schema.validateSync(value, { strict: true }); - }; + ModelThatExtends.validateSync = function(value) { + return ModelThatExtends.schema.validateSync(value, { strict: true }); + }; - })(ModelThatExtends || (ModelThatExtends = {}));" +})(ModelThatExtends || (ModelThatExtends = {}));" `; exports[`generation v3 javascript file(./test/result/v3/javascript/models/ModelThatExtendsExtends.js): ./test/result/v3/javascript/models/ModelThatExtendsExtends.js 1`] = ` @@ -5101,24 +5197,26 @@ import * as yup from 'yup'; export let ModelThatExtendsExtends; (function (ModelThatExtendsExtends) { - ModelThatExtendsExtends.schema = ModelWithString.schema.concat( - ModelThatExtends.schema.concat( - yup.object().shape({ - propExtendsC: yup.string(), - propExtendsD: ModelWithString.schema - }).noUnknown()) + ModelThatExtendsExtends.schema = ( + ModelWithString.schema.concat( + ModelThatExtends.schema.concat( + yup.object().shape({ + propExtendsC: yup.string(), + propExtendsD: ModelWithString.schema + }).noUnknown() + ) ) - ; + ); - ModelThatExtendsExtends.validate = async function(value) { - return ModelThatExtendsExtends.schema.validate(value, { strict: true }); - }; + ModelThatExtendsExtends.validate = async function(value) { + return ModelThatExtendsExtends.schema.validate(value, { strict: true }); + }; - ModelThatExtendsExtends.validateSync = function(value) { - return ModelThatExtendsExtends.schema.validateSync(value, { strict: true }); - }; + ModelThatExtendsExtends.validateSync = function(value) { + return ModelThatExtendsExtends.schema.validateSync(value, { strict: true }); + }; - })(ModelThatExtendsExtends || (ModelThatExtendsExtends = {}));" +})(ModelThatExtendsExtends || (ModelThatExtendsExtends = {}));" `; exports[`generation v3 javascript file(./test/result/v3/javascript/models/ModelWithArray.js): ./test/result/v3/javascript/models/ModelWithArray.js 1`] = ` @@ -5135,11 +5233,13 @@ import * as yup from 'yup'; export let ModelWithArray; (function (ModelWithArray) { - ModelWithArray.schema = yup.object().shape({ - prop: yup.array().of(ModelWithString.schema), - propWithFile: yup.array().of(yup.mixed()), - propWithNumber: yup.array().of(yup.number()) - }).noUnknown(); + ModelWithArray.schema = ( + yup.object().shape({ + prop: yup.array().of(ModelWithString.schema), + propWithFile: yup.array().of(yup.mixed()), + propWithNumber: yup.array().of(yup.number()) + }).noUnknown() + ); ModelWithArray.validate = async function(value) { return ModelWithArray.schema.validate(value, { strict: true }); @@ -5165,9 +5265,11 @@ import * as yup from 'yup'; export let ModelWithBoolean; (function (ModelWithBoolean) { - ModelWithBoolean.schema = yup.object().shape({ - prop: yup.boolean() - }).noUnknown(); + ModelWithBoolean.schema = ( + yup.object().shape({ + prop: yup.boolean() + }).noUnknown() + ); ModelWithBoolean.validate = async function(value) { return ModelWithBoolean.schema.validate(value, { strict: true }); @@ -5193,9 +5295,11 @@ import * as yup from 'yup'; export let ModelWithCircularReference; (function (ModelWithCircularReference) { - ModelWithCircularReference.schema = yup.object().shape({ - prop: ModelWithCircularReference.schema - }).noUnknown(); + ModelWithCircularReference.schema = ( + yup.object().shape({ + prop: ModelWithCircularReference.schema + }).noUnknown() + ); ModelWithCircularReference.validate = async function(value) { return ModelWithCircularReference.schema.validate(value, { strict: true }); @@ -5222,16 +5326,18 @@ import * as yup from 'yup'; export let ModelWithDictionary; (function (ModelWithDictionary) { - ModelWithDictionary.schema = yup.object().shape({ - prop: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.string() - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + ModelWithDictionary.schema = ( + yup.object().shape({ + prop: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.string() + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); ModelWithDictionary.validate = async function(value) { return ModelWithDictionary.schema.validate(value, { strict: true }); @@ -5258,11 +5364,13 @@ import * as yup from 'yup'; export let ModelWithDuplicateImports; (function (ModelWithDuplicateImports) { - ModelWithDuplicateImports.schema = yup.object().shape({ - propA: ModelWithString.schema, - propB: ModelWithString.schema, - propC: ModelWithString.schema - }).noUnknown(); + ModelWithDuplicateImports.schema = ( + yup.object().shape({ + propA: ModelWithString.schema, + propB: ModelWithString.schema, + propC: ModelWithString.schema + }).noUnknown() + ); ModelWithDuplicateImports.validate = async function(value) { return ModelWithDuplicateImports.schema.validate(value, { strict: true }); @@ -5289,9 +5397,11 @@ import * as yup from 'yup'; export let ModelWithDuplicateProperties; (function (ModelWithDuplicateProperties) { - ModelWithDuplicateProperties.schema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + ModelWithDuplicateProperties.schema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); ModelWithDuplicateProperties.validate = async function(value) { return ModelWithDuplicateProperties.schema.validate(value, { strict: true }); @@ -5326,13 +5436,15 @@ export let ModelWithEnum; ERROR: 'Error' }; - ModelWithEnum.schema = yup.object().shape({ - Test: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }).noUnknown(); + ModelWithEnum.schema = ( + yup.object().shape({ + Test: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }).noUnknown() + ); ModelWithEnum.validate = async function(value) { return ModelWithEnum.schema.validate(value, { strict: true }); @@ -5367,13 +5479,15 @@ export let ModelWithEnumFromDescription; ERROR: 3 }; - ModelWithEnumFromDescription.schema = yup.object().shape({ - Test: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }).noUnknown(); + ModelWithEnumFromDescription.schema = ( + yup.object().shape({ + Test: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }).noUnknown() + ); ModelWithEnumFromDescription.validate = async function(value) { return ModelWithEnumFromDescription.schema.validate(value, { strict: true }); @@ -5399,9 +5513,11 @@ import * as yup from 'yup'; export let ModelWithInteger; (function (ModelWithInteger) { - ModelWithInteger.schema = yup.object().shape({ - prop: yup.number() - }).noUnknown(); + ModelWithInteger.schema = ( + yup.object().shape({ + prop: yup.number() + }).noUnknown() + ); ModelWithInteger.validate = async function(value) { return ModelWithInteger.schema.validate(value, { strict: true }); @@ -5429,9 +5545,11 @@ import * as yup from 'yup'; export let ModelWithLink; (function (ModelWithLink) { - ModelWithLink.schema = yup.object().shape({ - prop: ModelLink.schema - }).noUnknown(); + ModelWithLink.schema = ( + yup.object().shape({ + prop: ModelLink.schema + }).noUnknown() + ); ModelWithLink.validate = async function(value) { return ModelWithLink.schema.validate(value, { strict: true }); @@ -5458,42 +5576,44 @@ import * as yup from 'yup'; export let ModelWithNestedEnums; (function (ModelWithNestedEnums) { - ModelWithNestedEnums.schema = yup.object().shape({ - arrayWithDescription: yup.array().of(yup.mixed().oneOf([ - 1, - 2, - 3 - ])), - arrayWithEnum: yup.array().of(yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ])), - dictionaryWithEnum: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }), {}) - ).noUnknown(); - }), - dictionaryWithEnumFromDescription: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + ModelWithNestedEnums.schema = ( + yup.object().shape({ + arrayWithDescription: yup.array().of(yup.mixed().oneOf([ + 1, + 2, + 3 + ])), + arrayWithEnum: yup.array().of(yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ])), + dictionaryWithEnum: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }), {}) + ).noUnknown(); + }), + dictionaryWithEnumFromDescription: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); ModelWithNestedEnums.validate = async function(value) { return ModelWithNestedEnums.schema.validate(value, { strict: true }); @@ -5519,13 +5639,19 @@ import * as yup from 'yup'; export let ModelWithNestedProperties; (function (ModelWithNestedProperties) { - ModelWithNestedProperties.schema = yup.object().shape({ - first: yup.object().shape({ - second: yup.object().shape({ - third: yup.string().nullable().required() - }).noUnknown().nullable().required() - }).noUnknown().nullable().required() - }).noUnknown(); + ModelWithNestedProperties.schema = ( + yup.object().shape({ + first: ( + yup.object().shape({ + second: ( + yup.object().shape({ + third: yup.string().nullable().required() + }).noUnknown() + ).nullable().required() + }).noUnknown() + ).nullable().required() + }).noUnknown() + ); ModelWithNestedProperties.validate = async function(value) { return ModelWithNestedProperties.schema.validate(value, { strict: true }); @@ -5552,15 +5678,17 @@ import * as yup from 'yup'; export let ModelWithProperties; (function (ModelWithProperties) { - ModelWithProperties.schema = yup.object().shape({ - boolean: yup.boolean(), - number: yup.number(), - reference: ModelWithString.schema, - required: yup.string().required(), - requiredAndNullable: yup.string().nullable().required(), - requiredAndReadOnly: yup.string().required(), - string: yup.string() - }).noUnknown(); + ModelWithProperties.schema = ( + yup.object().shape({ + boolean: yup.boolean(), + number: yup.number(), + reference: ModelWithString.schema, + required: yup.string().required(), + requiredAndNullable: yup.string().nullable().required(), + requiredAndReadOnly: yup.string().required(), + string: yup.string() + }).noUnknown() + ); ModelWithProperties.validate = async function(value) { return ModelWithProperties.schema.validate(value, { strict: true }); @@ -5587,9 +5715,11 @@ import * as yup from 'yup'; export let ModelWithReference; (function (ModelWithReference) { - ModelWithReference.schema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + ModelWithReference.schema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); ModelWithReference.validate = async function(value) { return ModelWithReference.schema.validate(value, { strict: true }); @@ -5615,9 +5745,11 @@ import * as yup from 'yup'; export let ModelWithString; (function (ModelWithString) { - ModelWithString.schema = yup.object().shape({ - prop: yup.string() - }).noUnknown(); + ModelWithString.schema = ( + yup.object().shape({ + prop: yup.string() + }).noUnknown() + ); ModelWithString.validate = async function(value) { return ModelWithString.schema.validate(value, { strict: true }); @@ -5641,21 +5773,25 @@ import * as yup from 'yup'; export let ProblemDetails; (function (ProblemDetails) { - ProblemDetails.schema = yup.object().shape({ - detail: yup.string().nullable(), - extensions: yup.lazy(value => { - return yup.object().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.object() - }), {}) - ).noUnknown(); - }), - instance: yup.string().nullable(), - status: yup.number().nullable(), - title: yup.string().nullable(), - type: yup.string().nullable() - }).noUnknown(); + ProblemDetails.schema = ( + yup.object().shape({ + detail: yup.string().nullable(), + extensions: yup.lazy(value => { + return yup.object().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: ( + yup.object() + ) + }), {}) + ).noUnknown(); + }), + instance: yup.string().nullable(), + status: yup.number().nullable(), + title: yup.string().nullable(), + type: yup.string().nullable() + }).noUnknown() + ); ProblemDetails.validate = async function(value) { return ProblemDetails.schema.validate(value, { strict: true }); @@ -6768,10 +6904,12 @@ export namespace ArrayWithProperties { export const schema = yup.array<{ foo?: string, bar?: string - }>().of(yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown()); + }>().of(( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + )); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -6957,10 +7095,12 @@ export namespace DictionaryWithProperties { }>>().shape( Object.keys(value).reduce((object, key) => ({ ...object, - [key]: yup.object().shape({ - foo: yup.string(), - bar: yup.string() - }).noUnknown() + [key]: ( + yup.object().shape({ + foo: yup.string(), + bar: yup.string() + }).noUnknown() + ) }), {}) ).noUnknown(); }); @@ -7168,9 +7308,11 @@ export interface ModelLink { export namespace ModelLink { - export const schema: yup.ObjectSchema = yup.object().shape({ - id: yup.string() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + id: yup.string() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7201,21 +7343,23 @@ export interface ModelThatExtends extends ModelWithString { export namespace ModelThatExtends { - export const schema: yup.ObjectSchema = ModelWithString.schema.concat( - yup.object().shape({ - propExtendsA: yup.string(), - propExtendsB: ModelWithString.schema - }).noUnknown()) - ; + export const schema: yup.ObjectSchema = ( + ModelWithString.schema.concat( + yup.object().shape({ + propExtendsA: yup.string(), + propExtendsB: ModelWithString.schema + }).noUnknown() + ) + ); - export async function validate(value: any): Promise { - return schema.validate(value, { strict: true }); - } + export async function validate(value: any): Promise { + return schema.validate(value, { strict: true }); + } - export function validateSync(value: any): ModelThatExtends { - return schema.validateSync(value, { strict: true }); - } - }" + export function validateSync(value: any): ModelThatExtends { + return schema.validateSync(value, { strict: true }); + } +}" `; exports[`generation v3 typescript file(./test/result/v3/typescript/models/ModelThatExtendsExtends.ts): ./test/result/v3/typescript/models/ModelThatExtendsExtends.ts 1`] = ` @@ -7238,23 +7382,25 @@ export interface ModelThatExtendsExtends extends ModelWithString, ModelThatExten export namespace ModelThatExtendsExtends { - export const schema: yup.ObjectSchema = ModelWithString.schema.concat( - ModelThatExtends.schema.concat( - yup.object().shape({ - propExtendsC: yup.string(), - propExtendsD: ModelWithString.schema - }).noUnknown()) + export const schema: yup.ObjectSchema = ( + ModelWithString.schema.concat( + ModelThatExtends.schema.concat( + yup.object().shape({ + propExtendsC: yup.string(), + propExtendsD: ModelWithString.schema + }).noUnknown() + ) ) - ; + ); - export async function validate(value: any): Promise { - return schema.validate(value, { strict: true }); - } + export async function validate(value: any): Promise { + return schema.validate(value, { strict: true }); + } - export function validateSync(value: any): ModelThatExtendsExtends { - return schema.validateSync(value, { strict: true }); - } - }" + export function validateSync(value: any): ModelThatExtendsExtends { + return schema.validateSync(value, { strict: true }); + } +}" `; exports[`generation v3 typescript file(./test/result/v3/typescript/models/ModelWithArray.ts): ./test/result/v3/typescript/models/ModelWithArray.ts 1`] = ` @@ -7277,11 +7423,13 @@ export interface ModelWithArray { export namespace ModelWithArray { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.array().of(ModelWithString.schema), - propWithFile: yup.array().of(yup.mixed()), - propWithNumber: yup.array().of(yup.number()) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.array().of(ModelWithString.schema), + propWithFile: yup.array().of(yup.mixed()), + propWithNumber: yup.array().of(yup.number()) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7313,9 +7461,11 @@ export interface ModelWithBoolean { export namespace ModelWithBoolean { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.boolean() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.boolean() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7344,9 +7494,11 @@ export interface ModelWithCircularReference { export namespace ModelWithCircularReference { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelWithCircularReference.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelWithCircularReference.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7376,16 +7528,18 @@ export interface ModelWithDictionary { export namespace ModelWithDictionary { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.string() - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.string() + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7417,11 +7571,13 @@ export interface ModelWithDuplicateImports { export namespace ModelWithDuplicateImports { - export const schema: yup.ObjectSchema = yup.object().shape({ - propA: ModelWithString.schema, - propB: ModelWithString.schema, - propC: ModelWithString.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + propA: ModelWithString.schema, + propB: ModelWithString.schema, + propC: ModelWithString.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7451,9 +7607,11 @@ export interface ModelWithDuplicateProperties { export namespace ModelWithDuplicateProperties { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7494,13 +7652,15 @@ export namespace ModelWithEnum { ERROR = 'Error' } - export const schema: yup.ObjectSchema = yup.object().shape({ - Test: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + Test: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7541,13 +7701,15 @@ export namespace ModelWithEnumFromDescription { ERROR = 3 } - export const schema: yup.ObjectSchema = yup.object().shape({ - Test: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + Test: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7579,9 +7741,11 @@ export interface ModelWithInteger { export namespace ModelWithInteger { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.number() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.number() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7612,9 +7776,11 @@ export interface ModelWithLink { export namespace ModelWithLink { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelLink.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelLink.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7647,42 +7813,44 @@ export interface ModelWithNestedEnums { export namespace ModelWithNestedEnums { - export const schema: yup.ObjectSchema = yup.object().shape({ - arrayWithDescription: yup.array<(1 | 2 | 3)>().of(yup.mixed().oneOf([ - 1, - 2, - 3 - ])), - arrayWithEnum: yup.array<('Success' | 'Warning' | 'Error')>().of(yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ])), - dictionaryWithEnum: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 'Success', - 'Warning', - 'Error' - ]) - }), {}) - ).noUnknown(); - }), - dictionaryWithEnumFromDescription: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.mixed().oneOf([ - 1, - 2, - 3 - ]) - }), {}) - ).noUnknown(); - }) - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + arrayWithDescription: yup.array<(1 | 2 | 3)>().of(yup.mixed().oneOf([ + 1, + 2, + 3 + ])), + arrayWithEnum: yup.array<('Success' | 'Warning' | 'Error')>().of(yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ])), + dictionaryWithEnum: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 'Success', + 'Warning', + 'Error' + ]) + }), {}) + ).noUnknown(); + }), + dictionaryWithEnumFromDescription: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: yup.mixed().oneOf([ + 1, + 2, + 3 + ]) + }), {}) + ).noUnknown(); + }) + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7715,13 +7883,19 @@ export interface ModelWithNestedProperties { export namespace ModelWithNestedProperties { - export const schema: yup.ObjectSchema = yup.object().shape({ - first: yup.object().shape({ - second: yup.object().shape({ - third: yup.string().nullable().required() - }).noUnknown().nullable().required() - }).noUnknown().nullable().required() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + first: ( + yup.object().shape({ + second: ( + yup.object().shape({ + third: yup.string().nullable().required() + }).noUnknown() + ).nullable().required() + }).noUnknown() + ).nullable().required() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7757,15 +7931,17 @@ export interface ModelWithProperties { export namespace ModelWithProperties { - export const schema: yup.ObjectSchema = yup.object().shape({ - boolean: yup.boolean(), - number: yup.number(), - reference: ModelWithString.schema, - required: yup.string().required(), - requiredAndNullable: yup.string().nullable().required(), - requiredAndReadOnly: yup.string().required(), - string: yup.string() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + boolean: yup.boolean(), + number: yup.number(), + reference: ModelWithString.schema, + required: yup.string().required(), + requiredAndNullable: yup.string().nullable().required(), + requiredAndReadOnly: yup.string().required(), + string: yup.string() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7795,9 +7971,11 @@ export interface ModelWithReference { export namespace ModelWithReference { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: ModelWithString.schema - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: ModelWithString.schema + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7829,9 +8007,11 @@ export interface ModelWithString { export namespace ModelWithString { - export const schema: yup.ObjectSchema = yup.object().shape({ - prop: yup.string() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + prop: yup.string() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -7863,21 +8043,25 @@ export interface ProblemDetails { export namespace ProblemDetails { - export const schema: yup.ObjectSchema = yup.object().shape({ - detail: yup.string().nullable(), - extensions: yup.lazy>(value => { - return yup.object>().shape( - Object.keys(value).reduce((object, key) => ({ - ...object, - [key]: yup.object() - }), {}) - ).noUnknown(); - }), - instance: yup.string().nullable(), - status: yup.number().nullable(), - title: yup.string().nullable(), - type: yup.string().nullable() - }).noUnknown(); + export const schema: yup.ObjectSchema = ( + yup.object().shape({ + detail: yup.string().nullable(), + extensions: yup.lazy>(value => { + return yup.object>().shape( + Object.keys(value).reduce((object, key) => ({ + ...object, + [key]: ( + yup.object() + ) + }), {}) + ).noUnknown(); + }), + instance: yup.string().nullable(), + status: yup.number().nullable(), + title: yup.string().nullable(), + type: yup.string().nullable() + }).noUnknown() + ); export async function validate(value: any): Promise { return schema.validate(value, { strict: true }); @@ -8420,9 +8604,9 @@ export class TypesService { parameterNumber: number = 123, parameterString: string | null = 'default', parameterBoolean: boolean | null = true, - parameterObject: any | null = null, + parameterObject: any = null, parameterArray: Array | null, - parameterDictionary: any | null, + parameterDictionary: any, parameterEnum: ('Success' | 'Warning' | 'Error') | null, id?: number ): Promise {