Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/node-swagger-generator/lib/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
IAbstractedType, IType, ITyped, IImportedType,
IDefinition, IProperty,
IAbstractedTypeConverter,
SchemaLessAbstractedType, ArrayAbstractedType, BuiltinAbstractedType, CustomAbstractedType, FileAbstractedType, MapAbstractedType, GenericAbstractedType, ImportedAbstractedType
VoidAbstractedType, SchemaLessAbstractedType, ArrayAbstractedType, BuiltinAbstractedType, CustomAbstractedType, FileAbstractedType, MapAbstractedType, GenericAbstractedType, ImportedAbstractedType
} from './typing';

//import servicesVersion = ts.servicesVersion;
Expand Down Expand Up @@ -681,6 +681,9 @@ class GenericTypeConverter implements IAbstractedTypeConverter<IAbstractedType>{
constructor(private contextBuilder: ContextBuilder) {
}

voidTypeConvert(type: VoidAbstractedType): IAbstractedType {
return type;
}
schemaLessTypeConvert(type: SchemaLessAbstractedType): IAbstractedType {
return type;
}
Expand Down
16 changes: 15 additions & 1 deletion src/node-swagger-generator/lib/languages/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
IAbstractedType, IType, ITyped, IImportedType,
IDefinition, IProperty,
IAbstractedTypeConverter,
SchemaLessAbstractedType, ArrayAbstractedType, BuiltinAbstractedType, CustomAbstractedType, FileAbstractedType, MapAbstractedType, GenericAbstractedType, ImportedAbstractedType
VoidAbstractedType, SchemaLessAbstractedType, ArrayAbstractedType, BuiltinAbstractedType, CustomAbstractedType, FileAbstractedType, MapAbstractedType, GenericAbstractedType, ImportedAbstractedType
} from '../typing';
import swagger = require('swagger-parser');
import _ = require('lodash');
Expand Down Expand Up @@ -35,6 +35,10 @@ class CSharpAbstractedTypeConverter implements IAbstractedTypeConverter<IType> {

}

voidTypeConvert(type: VoidAbstractedType): CSharpType {
return CSharpType.void();
}

schemaLessTypeConvert(type: SchemaLessAbstractedType): CSharpType {
return CSharpType.any;
}
Expand Down Expand Up @@ -94,6 +98,7 @@ class CSharpType implements IType {
isArray: boolean;
itemType: CSharpType;
isFile: boolean;
isVoid: boolean;
isGeneric: boolean;
genericArguments: CSharpType[];
isDictionary: boolean;
Expand Down Expand Up @@ -124,6 +129,15 @@ class CSharpType implements IType {
public static any: CSharpType = new CSharpType('object', null, true, false, false, false, false);
public static file: CSharpType = new CSharpType('IFile', null, true, false, false, false, true);
public static dateTimeOffset: CSharpType = new CSharpType('DateTimeOffset', null, true, false, false, false, false);
private static _void: CSharpType;

public static void(){
if (!CSharpType._void){
CSharpType._void = new CSharpType('void', null, true, false, false, false, false);
CSharpType._void.isVoid = true;
}
return CSharpType._void;
}

public static ambient(name: string, namespace: string): CSharpType {
var type = new CSharpType(name.replace('<>', ""), null, true, false, false, false, false);
Expand Down
16 changes: 15 additions & 1 deletion src/node-swagger-generator/lib/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
IAbstractedType, IType, ITyped, IImportedType,
IDefinition, IProperty,
IAbstractedTypeConverter,
SchemaLessAbstractedType, ArrayAbstractedType, BuiltinAbstractedType, CustomAbstractedType, FileAbstractedType, MapAbstractedType, GenericAbstractedType, ImportedAbstractedType
VoidAbstractedType, SchemaLessAbstractedType, ArrayAbstractedType, BuiltinAbstractedType, CustomAbstractedType, FileAbstractedType, MapAbstractedType, GenericAbstractedType, ImportedAbstractedType
} from '../typing';
import swagger = require('swagger-parser');
import _ = require('lodash');
Expand Down Expand Up @@ -35,6 +35,10 @@ class TypescriptAbstractedTypeConverter implements IAbstractedTypeConverter<ITyp

}

voidTypeConvert(type: VoidAbstractedType): TypescriptType {
return TypescriptType.void();
}

schemaLessTypeConvert(type: SchemaLessAbstractedType): TypescriptType {
return TypescriptType.any;
}
Expand Down Expand Up @@ -94,6 +98,7 @@ class TypescriptType implements IType {
isArray: boolean;
itemType: TypescriptType;
isFile: boolean;
isVoid: boolean;
isGeneric: boolean;
genericArguments: TypescriptType[];
isDictionary: boolean;
Expand Down Expand Up @@ -123,6 +128,15 @@ class TypescriptType implements IType {
public static boolean: TypescriptType = new TypescriptType('boolean', null, true, false, false, false, false);
public static any: TypescriptType = new TypescriptType('any', null, true, false, false, false, false);
public static file: TypescriptType = new TypescriptType('Uint8Array', null, true, false, false, false, true);
private static _void: TypescriptType;

public static void(){
if (!TypescriptType._void){
TypescriptType._void = new TypescriptType('void', null, true, false, false, false, false);
TypescriptType._void.isVoid = true;
}
return TypescriptType._void;
}

public static ambient(name: string, namespace: string): TypescriptType {
var type = new TypescriptType(name.replace('<>', ""), null, true, false, false, false, false);
Expand Down
7 changes: 7 additions & 0 deletions src/node-swagger-generator/lib/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ITyped {
}

export interface IAbstractedTypeConverter<T> {
voidTypeConvert(type: SchemaLessAbstractedType): T;
schemaLessTypeConvert(type: SchemaLessAbstractedType): T;
mapTypeConvert(type: MapAbstractedType): T;
builtinTypeConvert(type: BuiltinAbstractedType): T;
Expand Down Expand Up @@ -62,6 +63,12 @@ export interface IDefinition extends IExtensible {
}


export class VoidAbstractedType implements IAbstractedType {
convert<T>(converter: IAbstractedTypeConverter<T>): T {
return converter.voidTypeConvert(this);
}
}

export class SchemaLessAbstractedType implements IAbstractedType {
convert<T>(converter: IAbstractedTypeConverter<T>): T {
return converter.schemaLessTypeConvert(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#if type.isVoid}}
Task
{{/if}}
{{#unless type.isVoid}}
Task<{{> type }}>
{{/unless}}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace {{options.rootNamespace}} {
});
{{/if}}

Func<CancellationToken, Task<{{> type successResponse.[0]}}>> executeRequest = async (ct) =>
Func<CancellationToken, {{> task successResponse.[0]}}> executeRequest = async (ct) =>
{
var message = new HttpRequestMessage();
message.RequestUri = new Uri(uri, UriKind.Absolute);
Expand Down Expand Up @@ -97,7 +97,9 @@ namespace {{options.rootNamespace}} {
var response = await httpClient.SendAsync(message, ct);

if (response.IsSuccessStatusCode){
return await this.TransformResponseAsync<{{> type successResponse.[0]}}>(response);
{{#unless successResponse.[0].type.isVoid}}
return await this.TransformResponseAsync<{{> type successResponse.[0]}}>(response);
{{/unless}}
} else {
{{#if @root.options.operation.onError.useOKSchema}}
throw await this.MapToException<{{> type successResponse.[0]}}>(response);
Expand Down