Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index was out of range. Must be non-negative and less than the size of the collection. #853

Closed
phinett opened this issue Jul 21, 2017 · 3 comments

Comments

@phinett
Copy link

phinett commented Jul 21, 2017

Getting the following error when generating my typescript file. This is on the latest version of nswag.

Worked fine on a previous version (can't remember which version exactly, think it was 10. something)

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at NJsonSchema.CodeGeneration.DefaultValueGenerator.GetEnumDefaultValue(JsonSchema4 schema, JsonSchema4 actualSchema, String typeNameHint)
   at NJsonSchema.CodeGeneration.TypeScript.TypeScriptDefaultValueGenerator.GetDefaultValue(JsonSchema4 schema, Boolean allowsNull, String targetType, String typeNameHint, Boolean useSchemaDefault)
   at NJsonSchema.CodeGeneration.Models.PropertyModelBase.get_DefaultValue()
   at NJsonSchema.CodeGeneration.TypeScript.Templates.ClassTemplate.TransformText()
   at NJsonSchema.CodeGeneration.TypeScript.Templates.ClassTemplate.Render()
   at NJsonSchema.CodeGeneration.TypeScript.TypeScriptGenerator.GenerateType(String typeNameHint)
   at NJsonSchema.CodeGeneration.TypeResolverBase`1.GenerateTypes(ExtensionCode extensionCode)
   at NSwag.CodeGeneration.TypeScript.Models.TypeScriptFileTemplateModel..ctor(String clientCode, IEnumerable`1 clientClasses, SwaggerDocument document, TypeScriptExtensionCode extensionCode, SwaggerToTypeScriptClientGeneratorSettings settings, TypeScriptTypeResolver resolver)
   at NSwag.CodeGeneration.TypeScript.SwaggerToTypeScriptClientGenerator.GenerateFile(String clientCode, IEnumerable`1 clientClasses, ClientGeneratorOutputType outputType)
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile(SwaggerDocument document, ClientGeneratorOutputType type)
   at NSwag.Commands.SwaggerToTypeScriptClientCommand.<<RunAsync>b__100_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NSwag.Commands.SwaggerToTypeScriptClientCommand.<RunAsync>d__100.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NSwag.Commands.SwaggerToTypeScriptClientCommand.<RunAsync>d__99.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NSwag.Commands.NSwagDocumentBase.<ExecuteAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NSwagStudio.ViewModels.DocumentViewModel.<>c__DisplayClass15_0.<<GenerateAsync>b__0>d.MoveNext() in C:\projects\nswag\src\NSwagStudio\ViewModels\DocumentViewModel.cs:line 45
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyToolkit.Mvvm.ViewModelBase.<>c__DisplayClass14_0.<<RunTaskAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyToolkit.Mvvm.ViewModelBase.<RunTaskAsync>d__12`1.MoveNext()
@RicoSuter
Copy link
Owner

Somewhere in your swagger spec you have an enumeration and a default value which is (probably) not in the enumerations list... Can post this part of the spec so that I can reproduce this problem?

@RicoSuter
Copy link
Owner

I think I've fixed this in NJS (see commit above) and upgraded NJS in NSwag, please test with the latest CI artifacts: https://ci.appveyor.com/project/rsuter/nswag-25x6o

@phinett
Copy link
Author

phinett commented Aug 8, 2017

Thanks for this, it has partially fixed the issue for me, i no longer get the index out of range exception now.
But i noticed some issues with default values being set now:

src\common\api.ts:6315:69
TS2339: Property '_0' does not exist on type 'typeof DiscountUsageLimitType'.

I am using string enums, but it looks like it's trying to refer to my enums as integers.

I may be wrong though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants