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

fix: buildRequest of multipart/formdata with array entries #1527

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/usage/http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Type notations are formatted like so:
Property | Description
--- | ---
`query` | `Object=null`. When provided, HTTP Client serialize it and appends the `queryString` to `Request.url` property.
`loadSpec` | `Boolean=undefined`. This property will be present and set to `true` when the `Request` was constructed internally by `SwaggerClient` to fetch the OAS definition defined by `url` or when resolving remote JSON References.
`requestInterceptor` | `Function=identity`. Either synchronous or asynchronous function transformer that accepts `Request` and should return `Request`.
`responseInterceptor` | `Function=identity`. Either synchronous or asynchronous function transformer that accepts `Response` and should return `Response`.
`userFetch` | `Function=cross-fetch`. Custom **asynchronous** fetch function that accepts two arguments: the `url` and the `Request` object and must return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
Expand Down Expand Up @@ -138,6 +139,57 @@ SwaggerClient.http(request);
// Requested URL: https://httpbin.org/?anotherOne=one,two&evenMore=hi&bar=1%202%203
```

##### Loading specification

`loadSpec` property signals when the Request was constructed implicitly by `SwaggerClient`.
This can happen in only two circumstances.

1. When `SwaggerClient` fetches the OAS definition specified by `url`
2. When `SwaggerClient` resolves the OAS definition by fetching remote JSON References

All other requests will not have this property present, or the property will be set to `false`.

*This following code snippet*:

```js
import SwaggerClient from 'swagger-client';

const requestInterceptor = (request) => {
console.log(request);

return request;
};

SwaggerClient({ url: 'https://petstore.swagger.io/v2/swagger.json', requestInterceptor })
.then(client => client.execute({
operationId: "findPetsByStatus",
parameters: { status: 3 },
requestInterceptor,
}));
```

*Will result in two requests, with only one containing `loadSpec` set to `true`:*

```js
{
url: 'https://petstore.swagger.io/v2/swagger.json',
loadSpec: true,
requestInterceptor: [Function: requestInterceptor],
responseInterceptor: null,
headers: { Accept: 'application/json, application/yaml' },
credentials: 'same-origin'
}
{
url: 'https://petstore.swagger.io/v2/pet/findByStatus?status=3',
credentials: 'same-origin',
headers: {},
requestInterceptor: [Function: requestInterceptor],
method: 'GET'
}
```



##### Request Interceptor

Request interceptor can be configured via `requestInterceptor` property in `Request` object.
Expand Down
26 changes: 26 additions & 0 deletions docs/usage/openapi-definition-resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ SwaggerClient.resolve({ url: 'https://raw.githubusercontent.com/swagger-api/swag
> *__Note:__ you can provide `Swagger.resolve` both `spec` and `url` options. In that case
`spec` will always be preferred and `url` option will be ignored.*

#### Authentication

When JSON-References points to a remote document protected by authentication,
`requestInterceptor` option can be used to provide request authentication (e.g. by setting `Authentication` header).

```js
import SwaggerClient from 'swagger-client';

const requestInterceptor = request => {
if (request.loadSpec) {
request.headers['Authorization'] = 'Bearer Asdf1234ThisIsMyToken';
}

return request;
};

SwaggerClient.resolve({
url: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml',
requestInterceptor,
});
```

> *__Note:__ Notice how we use [loadSpec](http-client.md#loading-specification) Request property to determine if the intercepted request was made to fetch the OAS definition.*



#### Errors

Resolver can also produce errors on various problems inside OpenAPI definition.
Expand Down
Loading