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

add type swagger2openapi #63631

Merged
merged 16 commits into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 70 additions & 0 deletions types/swagger2openapi/index.d.ts
@@ -0,0 +1,70 @@
// Type definitions for swagger2openapi 7.0
// Project: https://github.com/Mermade/oas-kit/tree/main/packages/swagger2openapi
// Definitions by: rxliuli <https://github.com/rxliuli>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Definitions by: rxliuli <https://github.com/rxliuli>
rxliuli marked this conversation as resolved.
Show resolved Hide resolved

// /*~ If this module is a UMD module that exposes a global variable 'myLib' when
// *~ loaded outside a module loader environment, declare that global here.
// *~ Otherwise, delete this declaration.
// */
// export as namespace myLib;

// /*~ If this module has methods, declare them as functions like so.
// */
// export function myMethod(a: string): string;
// export function myOtherMethod(a: number): number;

// /*~ You can declare types that are available via importing the module */
// export interface someType {
// name: string;
// length: number;
// extras?: string[];
// }

// /*~ You can declare properties of the module using const, let, or var */
// export const myField: number;

// /*~ If there are types, properties, or methods inside dotted names
// *~ of the module, declare them inside a 'namespace'.
// */
// export namespace subProp {
// /*~ For example, given this definition, someone could write:
// *~ import { subProp } from 'yourModule';
// *~ subProp.foo();
// *~ or
// *~ import * as yourMod from 'yourModule';
// *~ yourMod.subProp.foo();
// */
// function foo(): void;
// }

export class S2OError extends Error {}

import { OpenAPIV2, OpenAPIV3 } from 'openapi-types';

export interface ConvertObjOptions {
patch?: boolean;
warnOnly?: boolean;
}

export function convertObj(
rxliuli marked this conversation as resolved.
Show resolved Hide resolved
schema: OpenAPIV2.Document,
options: ConvertObjOptions,
): Promise<{
original: OpenAPIV2.Document;
text: string;
openapi: OpenAPIV3.Document;
}>;
export function convertObj(
schema: OpenAPIV2.Document,
options: ConvertObjOptions,
callback: (
err: S2OError | undefined,
options: {
original: OpenAPIV2.Document;
text: string;
openapi: OpenAPIV3.Document;
},
) => void,
): void;
6 changes: 6 additions & 0 deletions types/swagger2openapi/package.json
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"openapi-types": "^12.1.0"
}
}
6 changes: 6 additions & 0 deletions types/swagger2openapi/swagger2openapi-tests.ts
@@ -0,0 +1,6 @@
import { OpenAPIV2, OpenAPIV3 } from 'openapi-types';
import { convertObj } from 'swagger2openapi';

(async () => {
const r: OpenAPIV3.Document = (await convertObj(null as unknown as OpenAPIV2.Document, {})).openapi;
})();
23 changes: 23 additions & 0 deletions types/swagger2openapi/tsconfig.json
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"swagger2openapi-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/swagger2openapi/tslint.json
@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }