postmanlabs / swagger2-postman2

Module and library to convert Swagger 2.0 to a Postman Collection (v2.0)
Apache License 2.0
82 stars 42 forks source link

Cant't found types to use it with typescript #74

Open jyeros opened 4 years ago

jyeros commented 4 years ago

I am using typescript and install swagger2-postman2, but when I import it i got the error

Could not find a declaration file for module 'swagger2-postman2'. 'node_modules/swagger2-postman2/index.js' implicitly has an 'any' type.
  Try `npm install @types/swagger2-postman2` if it exists or add a new declaration (.d.ts) file containing `declare module 'swagger2-postman2';`ts(7016)

If i try npm install @types/swagger2-postman2 the response is no found.

Could you provide .d.ts file with typescript types.

jyeros commented 4 years ago

I generated a declaration (.d.ts) file containing declare module 'swagger2-postman2', it could be used as an started point, but would be nice if there is one official. I needed to add 2 devDependencies for types, openapi-types and @types/postman-collection

declare module 'swagger2-to-postmanv2' {
    interface ConvertOptions {
        requestNameSource?: 'URL' | 'Fallback';
        indentCharacter?: 'Space' | 'Tab';
        collapseFolders?: boolean;
        optimizeConversion?: boolean;
        requestParametersResolution?: 'Example' | 'Schema';
        exampleParametersResolution?: 'Example' | 'Schema';
        folderStrategy?: 'Paths' | 'Tags';
        includeAuthInfoInExample?: boolean;
    }
    type InputDataType = import('openapi-types').OpenAPIV2.Document | string;
    interface Input {
        type: 'file' | 'json' | 'string';
        data: InputDataType;
    }
    interface OptionDefinition {
        name: string;
        id: string;
        type: string;
        default: unknown;
        availableOptions: string[];
        description: string;
        external: boolean;
    }
    const validate: (
        input: Input
    ) => {
        result: boolean;
        reason?: string;
    };
    const convert: <T>(
        input: Input,
        options: ConvertOptions,
        callback: (
            err: Error | null,
            result: {
                result: boolean;
                output?: [
                    {
                        type: 'collection';
                        data: import('postman-collection').Collection;
                    }
                ];
            }
        ) => T
    ) => T;
    const getOptions: () => OptionDefinition[];
    const getMetaData: <T>(
        input: InputDataType,
        callback: (
            err: Error | null,
            result: {
                result: boolean;
                swagger?: import('openapi-types').OpenAPIV2.Document;
                reason?: string;
            }
        ) => T
    ) => T;
}