CacheControl / CacheControl/hippie-swagger

(Nice-to-have) - Read dereferenced Swagger from file

Open
#48 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
183
Forks
23
PR merge metrics
No merged PRs in 30d

Description

I'd like to have a central (common) instance of the `hippieSwaggerApp()` function, to make it cleaner for each of my tests to call it. As a workaround, within each Test Suite, I've duplicated the function:

```js
import hippie from "hippie-swagger";
import { username, password } from "common/resources/httpAuth.json";

describe("Test Swagger examples for Foo", () => {
let dereferencedSwagger;

function myApp() {
return hippie(dereferencedSwagger).base(baseUrl).auth(username, password).json();
}

before(async () => {
dereferencedSwagger = await parseSwaggerDoc(mySwaggerDoc);
});

context("", () => {
it("Returns 200, when sending a valid request", async () => {
await myApp()
.header("Auth-Type", "auth")
.header("Auth-Token", authToken)
.get(`my/route/{id}`)
.pathParams({
id: my.id,
})
.expectStatus(200)
.end();
});
```

However, it would be really nice to have a setup script which parses the Swagger Doc (as we have multiple APIs), and writes the dereferenced contents to a temp file. Allowing for:

```js
// common/path/commonHippieApp.js
import hippie from "hippie-swagger";
import { username, password } from "common/resources/httpAuth.json";

export const commonHippieApp = (pathToSwaggerDoc, baseUrl) => {
return hippie(pathToSwaggerDoc).base(baseUrl).auth(username, password).json();
}
```
```js
// service/path/myHippieApp.js
import commonHippieApp from "common/path/commonHippieApp";

const swaggerPath = "path/to/dereferencedSwagger.json"

export const myHippieApp = () => {
return commonHippieApp(swaggerPath, "http://some.base/uri");
}
```
```js
// tests.spec.js
import myHippieApp from "service/path/myHippieApp";

describe("Test Swagger examples for Foo", () => {
context("", () => {
it("Returns 200, when sending a valid request", async () => {
await myHippieApp()
.header("Auth-Type", "auth")
.header("Auth-Token", authToken)
.get(`my/route/{id}`)
.pathParams({
id: my.id,
})
.expectStatus(200)
.end();
});
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.