From fda843ff48a20b18834d0a6fba2531d9aff0b394 Mon Sep 17 00:00:00 2001 From: martineaus83 <78589770+martineaus83@users.noreply.github.com> Date: Wed, 2 Oct 2024 21:27:16 +0200 Subject: [PATCH] Resolve bug https://github.com/bcherny/json-schema-to-typescript/issues/637 Incorrect Generation if oneOf is used mixed with properties --- src/generator.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index fb8d23b0..1fed3944 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -119,14 +119,27 @@ function declareNamedTypes(ast: AST, options: Options, rootASTName: string, proc case 'ENUM': return '' case 'INTERFACE': - return getSuperTypesAndParams(ast) + const superclass = getSuperTypesAndParams(ast) .map( ast => (ast.standaloneName === rootASTName || options.declareExternallyReferenced) && declareNamedTypes(ast, options, rootASTName, processed), ) .filter(Boolean) - .join('\n') + .join('\n'); + const code = [ + hasStandaloneName(ast) ? generateStandaloneType(ast, options) : undefined, + ast.params + .map(ast => declareNamedTypes(ast, options, rootASTName, processed)) + .filter(Boolean) + .join('\n'), + 'spreadParam' in ast && ast.spreadParam + ? declareNamedTypes(ast.spreadParam, options, rootASTName, processed) + : undefined, + ] + .filter(Boolean) + .join('\n'); + return superclass+"\n"+code; case 'INTERSECTION': case 'TUPLE': case 'UNION':