Repository: lukeautry/tsoa (ts)

Issue:
Unknown type: TypeLiteral when using a dictionary on a model object
Hi,

When I try and generate the model I get this error:

      Unknown type: TypeLiteral

I thought I knew what was causing this, but its clear now that I don't.  Its from one of my models, but that's about it.

Any suggestions?


Support for index signatures
Seems like index signatures such as
```
class myClass {
    nodes: {
        [nodeName: string]: Node;
    };
}
```
are not currently supported.

https://www.typescriptlang.org/docs/handbook/advanced-types.html#index-types-and-string-index-signatures

nodes will just show as an empty object in the swagger file.




Pull request:
nOL: Generate index signature specifications
### All Submissions:

* [x] Have you followed the guidelines in our [Contributing](https://github.com/lukeautry/tsoa/tree/master/docs/CONTRIBUTING.md) document?
* [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/lukeautry/tsoa/pulls) for the same update/change?
* [x] Have you written unit tests?
* [x] Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
* [x] This PR is associated with an existing issue?

**Closing issues**

- closes #374 
- closes #50

### If this is a new feature submission:

* [x] Has the issue had a maintainer respond to the issue and clarify that the feature is something that aligns with the [goals](https://github.com/lukeautry/tsoa#goal) and [philosophy](https://github.com/lukeautry/tsoa#philosophy) of the project?

**Potential Problems With The Approach**

Not aware

**Test plan**

Updated the existing specs

Patch:
diff --git a/src/swagger/specGenerator.ts b/src/swagger/specGenerator.ts
index 65175d00..0a95e263 100644
--- a/src/swagger/specGenerator.ts
+++ b/src/swagger/specGenerator.ts
@@ -89,6 +89,7 @@ export abstract class SpecGenerator {
   protected abstract getSwaggerTypeForUnionType(type: Tsoa.UnionType);
 
   protected abstract getSwaggerTypeForIntersectionType(type: Tsoa.IntersectionType);
+
   public getSwaggerTypeForObjectLiteral(objectLiteral: Tsoa.ObjectLiteralType): Swagger.Schema {
     const properties = objectLiteral.properties.reduce((acc, property: Tsoa.Property) => {
       return {
@@ -97,12 +98,15 @@ export abstract class SpecGenerator {
       };
     }, {});
 
+    const additionalProperties = objectLiteral.additionalProperties && this.getSwaggerType(objectLiteral.additionalProperties);
+
     const required = objectLiteral.properties.filter(prop => prop.required).map(prop => prop.name);
 
     // An empty list required: [] is not valid.
     // If all properties are optional, do not specify the required keyword.
     return {
       properties,
+      ...(additionalProperties && { additionalProperties }),
       ...(required && required.length && { required }),
       type: 'object',
     };


Test patch:
diff --git a/tests/unit/swagger/definitionsGeneration/definitions.spec.ts b/tests/unit/swagger/definitionsGeneration/definitions.spec.ts
index 9087e368..2d86bc94 100644
--- a/tests/unit/swagger/definitionsGeneration/definitions.spec.ts
+++ b/tests/unit/swagger/definitionsGeneration/definitions.spec.ts
@@ -430,7 +430,13 @@ describe('Definition generation', () => {
                 name: { type: 'string' },
                 nested: {
                   properties: {
-                    additionals: { properties: {}, type: 'object' },
+                    additionals: {
+                      properties: {},
+                      type: 'object',
+                      additionalProperties: {
+                        $ref: '#/definitions/TypeAliasModel1',
+                      },
+                    },
                     allNestedOptional: {
                       properties: { one: { type: 'string' }, two: { type: 'string' } },
                       type: 'object',
@@ -462,11 +468,6 @@ describe('Definition generation', () => {
           Object.keys(definition.properties!).length,
           `because the swagger spec (${currentSpec.specName}) should only produce property schemas for properties that live on the TypeScript interface.`,
         );
-
-        expect(Object.keys(assertionsPerProperty)).to.length(
-          Object.keys(definition.properties!).length,
-          `because the swagger spec (${currentSpec.specName}) should only produce property schemas for properties that live on the TypeScript interface.`,
-        );
       });
     });
 
diff --git a/tests/unit/swagger/schemaDetails3.spec.ts b/tests/unit/swagger/schemaDetails3.spec.ts
index 6a079e60..b0e110d9 100644
--- a/tests/unit/swagger/schemaDetails3.spec.ts
+++ b/tests/unit/swagger/schemaDetails3.spec.ts
@@ -225,6 +225,9 @@ describe('Definition generation for OpenAPI 3.0.0', () => {
                     additionals: {
                       properties: {},
                       type: 'object',
+                      additionalProperties: {
+                        $ref: '#/components/schemas/TypeAliasModel1',
+                      },
                     },
                     allNestedOptional: {
                       properties: { one: { type: 'string' }, two: { type: 'string' } },