3.7.101 • Published 10 months ago

@taktikorg/id-adipisci v3.7.101

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Swagger API Client Builder

Automatically generate an API client on top of Axios using Swagger document.

Basically using the Swagger document to generate a client in reverse.

Features

  • Uses operationIds for function names.

  • Optionally it can use the Swagger schema for input validation.

  • Automatically converts the body to the correct content-type, but you can manually override it by defining the content-type in the axios request options.

  • If the protocol, host and base path are defined then it will use them as baseURL, but you can manually override it by defining the baseURL in the axios config.

  • Supports Swagger v2 and OpenAPI v3.

  • Can be installed as a global package and export a standalone API client via the CLI.

  • CLI can export both JavaScript and TypeScript.

Caveats

  • operationId property is required for all paths.

Install

npm install @taktikorg/id-adipisci

Or

yarn add @taktikorg/id-adipisci

CLI

You can install the package globally using:

npm i @taktikorg/id-adipisci -g

Usage

Usage: @taktikorg/id-adipisci -i <input> -o <output> [options]
Options:

  -i, --input           Input swagger file path or URL (.json or .yaml or .yml)
  -o, --output          Output file path (.js or .ts)
  -v, --validation      Use jsonschema validation
  -e, --es              Use ES module import instead of CommonJs
  -t, --ts              Use TypeScript instead of JavaScript
  -s, --silent          Silent export (just export without prompts but will show errors)
  -T, --target          Target output ("file" or "bash")
  -V, --version         Show version

CLI Examples

Export to JavaScript with ES imports
@taktikorg/id-adipisci -i https://petstore3.swagger.io/api/v3/openapi.json -o ./path/to/output.js -v -e
Export to JavaScript with CommonJs requires
@taktikorg/id-adipisci -i https://petstore3.swagger.io/api/v3/openapi.json -o ./path/to/output.js -v
Export to TypeScript
@taktikorg/id-adipisci -i https://petstore3.swagger.io/api/v3/openapi.json -o ./path/to/output.ts -v -t

Code Example

const SwaggerClientBuilder = require("@taktikorg/id-adipisci");

async function main() {
    try {

        const swaggerFile = 'https://petstore3.swagger.io/api/v3/openapi.json'; // Or use file path

        const Client = new SwaggerClientBuilder(swaggerFile, {
            // Optional: Axios instance config
            baseURL: 'https://petstore3.swagger.io/api/v3'
        })

        await Client.build();

        const response = await Client.getPetById({
            params: { petId: 1 }
            /*
            query:{},
            body:{},

            // Axios request options
            options:{
                headers:{...}
            }
            */
        });

        console.log(response.data);


        // You can also export the client to a file from code
        await Client.export('./client.js',{
            validation: true,
        });

    } catch (error) {
        console.log(error);
    }
}

main();
dataViewreduxio-tsdeterministicinvariantpathwalkingreact-hooksmakevest$.extendfile systembrowserlistenersObject.entriesutili18ncompilerjson-schemaapigetintrinsictypedSethigher-orderES2018valuetc39utilitykarmatoolkitform-validationeventEmitterFloat32Arraytranspilerprettyget.envsearchStreamexecissuperagentstringifyInt8ArraysymbolplugincharactersSymbol.toStringTagArrayBuffer.prototype.slicevaluesajaxmomentpolyfillObject.istypedarrayclientfunctionalponyfillECMAScript 3fixed-widthtsfetchTypedArraysharedarraybufferUint32ArrayparenttrimatomdefinetrimStartboundinternaljsdomeslintspringES2023figletindom-testing-libraryyupproxymatchAllslottransformaccessordescriptioncolorselectronavabannerbufferpackage.jsoncommanderESrulesshamObject.fromEntriestostringtagYAMLArray.prototype.flattenjshintcheckString.prototype.matchAllnamesrssregular expressionssameValueZerocloudfronteventDispatcherenvpoint-freees2017user-streamsrestlook-upxtermObservableenumerablejsonschemaES2019circularmetadataredux-toolkitwarningexpressionminimalbinreadhas-ownwaapijestutil.inspectloggingnodetypescriptindicatorcloudsearchkeysObject.definePropertyzeroqueueweakmapserializationidtermprocessstoragegatewayconfigHyBiwalkyamlCSSStyleDeclarationasyncformsStyleSheetperformanthasOwnPropertyperformancechannelgitignoreJSON-SchemaeslintplugintranspileassertsconcatMapinstallasteriskshashECMAScript 7regexpdefinePropertyscheme-validationECMAScript 2021setImmediatePushspinnerreactsesmake dirinstallerObject.assignweaksetworkerlintmatchES2015feedfast-clonetapclass-validatorvpcttyforkpositiveschematakemkdirhttpsbabel-corearktypenegative zeroquerycontainscss-in-jsvarsextenditerateescapetddPromisenodejses-shim APIsomeflagsswfhtmlpreprocessorArray.prototype.flatdeep-copylanguageUint16ArrayfilterflattenprototypeBigInt64Arrayargstestingdebugutilitiessidedynamodbrequirees2018serializetapeES2020routerpushamazonES2016tslibdragrandomidentifiersworkflowglobRxReactiveXapollojQuerysubprocessprefixsymlinksstyled-componentssetteristanbulchineseeast-asian-widthbrowserslistprotoownframeworkpropertymruecmascript6to5prunecolumncomputed-typeses2015cloudformationnegativeECMAScript 5ReactiveExtensionszxcolorprivate datathreeobjArray.prototype.findLastsqsgroupByES7argumentgenericsstablejoihooksMicrosoftECMAScript 2023styleguideshebangBigUint64Arraybusyregular-expressionfull-widthfromerrorshrinkwrapes2016animationfast-copy-0harmonyglobal this valuetimeremoveexecfileprivatecoverageRegExp#flagsrmdirec2glacierregular expressionajvserializerassertreact-hook-formObjectemr@@toStringTagbinarydebuggerstringifiercodesphonewritablegetOwnPropertyDescriptoroffsetelasticachesymbolsArrayBuffer#sliceignoreisConcatSpreadablefnmatchmatchesansisinatraclassnamesdirectorytelephonea11yoptionaccessibilityairbnblinkvalidationformatsetdateECMAScript 2019fsiereversegroupsimpledbSystem.globalroutecssequalitybundlerIteratorgetPrototypeOftoobjectECMAScript 2018nameautoprefixerconsumerapidrfc4122hardlinksreadableES8postcss-plugin[[Prototype]]speednumberendpointstructuredClonetraversevariableszodfindestreefunctionbabelwgetcall-boundes8npmignorebuffersclieslint-pluginWeakSettoArrayrecursiveupmkdirpkoreanfullwidthespreexhrformattingwaitlrukinesisconstdependenciescolourquerystringmapUnderscore__proto__rgbfindLastIndexhasOwnRxJSfunction.lengthexpressjasminevalidatetrimLeftfindupprogressdiffmonoreporeversedwidthargvl10nprotocol-buffersarrayoutputmoduleseffect-tscurriedbddsource map_.extendvalidatorfolderfpsurlfindLastenderESnextdomexecutejsonfastcloneshelljavascriptUint8Arrayrm -rfes5windowiamES6WebSocketsdataviewobjectWeakMapECMAScript 2017typeerrorpnpm9purehookformReflect.getPrototypeOfObservablesglobalThisfind-upstreamenvironment0sortedpicomatchrangeerrorartreact-testing-librarycurlshimcommandemittextquotewritetesterfantasy-landformutilsinstrumentationroute53deepintrinsices7optimizerInt32Arrayemojijson-schema-validationlastlocationinferencestylingtypedarraysES2017terminalpromiseclonemanipulationjapanesepackagesURLSearchParamshasramdaWebSocketomithelperssnsCSSbeanstalkString.prototype.trimcallhelpercoremobilehttpstylescallbindkeycachereworkconfigurablebindviewcloudtrailsyntaxpyyamlfastextradayjsastinputrobustwhatwgUint8ClampedArraypipermschememkdirsES5collectionappcjkconcatspeccolumnsgesturesentriesFloat64Arraytacitdeleteeventsfpfilelibphonenumbercore-jsloggernpmcallbacklogarraysreusedeepcopychromeObject.keysassignredactsharedECMAScript 2015workspace:*byteLengthglobalStreamstransport256propertieswhichdatacharactertypesafebyteOffsetjsloadbalancingtypejsdiffdependency managerframertoStringTagsuperstructRFC-6455Object.valuesjsxpackagecloudwatches6managermoveidlequeueMicrotaskstarterspinnersTypeBoxawesomesaucelookprotobufArray.prototype.flatMapacorns3importflagparserArray.prototype.includesreal-timeincludesnopenativeglobalsxmlsafefullimportexportcollection.es6waftrimEndcryptotoSortedfast-deep-copypinostylestreamscoercibletestes-shimsrestfulES2022parseequaluuidgraphqlposemoduleebspatchagentreact posemochaglobal objectletgdprArraywebObject.getPrototypeOfimmerefficientrequestfastifyparentsruntimesettingsselfURLstringoptimistbytereduceECMAScriptsetPrototypeOfdescriptors3dsortgetopttypeofAsyncIteratorlockfileautoscalingdirbrowserlistjson-schema-validatortrimRightECMAScript 2022spawnassertioncreatecallboundoncecompareasciichildresolvefunctionsfastcopycode pointsMaptyped arrayconsolevisuallocalflatqsforEachtypesECMAScript 2016ArrayBufferarraybufferbinariesflatMapiteratorSymbolInt16ArrayRegExp.prototype.flagsesgetterdescriptorlengthenvironmentseveryreact animationes-abstractroutingvalidreducerTypeScriptunicode
3.7.101

10 months ago

3.7.100

10 months ago

3.7.99

10 months ago

3.7.98

10 months ago

3.7.97

10 months ago

3.7.96

10 months ago

3.7.95

10 months ago

3.7.94

11 months ago

3.7.93

11 months ago

3.7.92

11 months ago

3.7.91

11 months ago

3.7.90

11 months ago

3.7.89

11 months ago

3.7.88

11 months ago

3.7.87

11 months ago

3.7.86

11 months ago

3.7.85

11 months ago

3.7.84

11 months ago

3.7.83

11 months ago

3.7.82

11 months ago

3.7.81

11 months ago

3.7.80

11 months ago

3.7.79

11 months ago

3.7.78

11 months ago

3.7.77

11 months ago

3.7.76

11 months ago

3.7.75

11 months ago

3.7.74

11 months ago

3.7.73

11 months ago

3.7.72

11 months ago

3.7.71

11 months ago

3.7.70

11 months ago

3.7.69

11 months ago

3.7.68

11 months ago

3.7.67

11 months ago

3.7.66

11 months ago

3.7.65

11 months ago

3.7.64

12 months ago

3.6.64

12 months ago

3.6.63

12 months ago

3.6.62

12 months ago

3.6.61

12 months ago

3.6.60

12 months ago

3.6.59

12 months ago

3.6.58

12 months ago

3.5.58

12 months ago

3.5.57

12 months ago

3.5.56

12 months ago

3.5.55

12 months ago

3.5.54

12 months ago

3.5.53

12 months ago

3.5.52

12 months ago

3.5.51

12 months ago

3.5.50

12 months ago

3.5.49

12 months ago

3.5.48

12 months ago

3.5.47

12 months ago

3.5.46

1 year ago

3.4.46

1 year ago

3.4.45

1 year ago

3.4.44

1 year ago

3.3.44

1 year ago

3.3.43

1 year ago

3.3.42

1 year ago

3.3.41

1 year ago

3.2.41

1 year ago

3.2.40

1 year ago

3.2.39

1 year ago

3.2.38

1 year ago

3.2.37

1 year ago

3.2.36

1 year ago

3.2.35

1 year ago

3.2.34

1 year ago

3.2.33

1 year ago

3.1.33

1 year ago

2.1.33

1 year ago

2.1.32

1 year ago

2.1.31

1 year ago

2.1.30

1 year ago

2.1.29

1 year ago

2.1.28

1 year ago

2.1.27

1 year ago

2.1.26

1 year ago

2.1.25

1 year ago

2.1.24

1 year ago

2.1.23

1 year ago

2.1.22

1 year ago

2.1.21

1 year ago

2.1.20

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago