We publish single module to npm: swagger-client.
swagger-client
is meant for consumption by any JavaScript engine (node.js, browser, etc...).
The npm package contains transpiled and minified ES5 compatible code.
$ npm install swagger-client
Increasing installation speed:
swagger-client
integrates with ApiDOM and use it
as a direct dependency. Some transitive dependencies of ApiDOM are optional,
which means we can use override package.json field
to speed up the installation:
"overrides": {
"@swagger-api/apidom-reference": {
"@swagger-api/apidom-ns-asyncapi-2": "npm:[email protected]",
"@swagger-api/apidom-ns-openapi-2": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-api-design-systems-json": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-json": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-openapi-json-2": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-openapi-yaml-2": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-openapi-json-3-0": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-workflows-json-1": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-workflows-yaml-1": "npm:[email protected]",
"@swagger-api/apidom-parser-adapter-yaml-1-2": "npm:[email protected]"
}
}
NOTE 1: Above override uses empty npm package called "-" to override optional ApiDOM transitive dependencies.
NOTE 2: When ApiDOM optional dependencies fail to install, you can safely ignore it as
swagger-client
can work without these optional dependencies.
After installed successfully:
import SwaggerClient from 'swagger-client';
const SwaggerClient = require('swagger-client');
You can embed Swagger UI's code directly in your HTML by using unpkg's interface.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SwaggerClient test</title>
<script src="https://unpkg.com/swagger-client"></script>
<script>
new SwaggerClient('http://petstore.swagger.io/v2/swagger.json')
.then(
client => client.apis.pet.addPet({ id: 1, body: { name: "bobby" } }),
reason => console.error('failed to load the spec: ' + reason)
)
.then(
addPetResult => console.log(addPetResult.body),
reason => console.error('failed on api call: ' + reason)
);
</script>
</head>
<body>
check console in browser's dev. tools
</body>
</html>
See unpkg's main page for more information on how to use unpkg.