Skip to content
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
1 change: 1 addition & 0 deletions docs/usage/tags-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Option | Description
`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.
`skipNormalization` | `Boolean=false`. Normalization creates unique operationIds when explicit operationIds are duplicates, and preserve originals.

> *__Note:__ for more information about [requestInterceptor](http-client.md#request-interceptor), [responseInterceptor](http-client.md#response-interceptor) and [userFetch](https://github.com/swagger-api/swagger-js/blob/master/docs/usage/http-client.md#custom-fetch), please refer to the [HTTP Client](http-client.md) documentation.*

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Swagger.prototype = {
useCircularStructures: this.useCircularStructures,
requestInterceptor: this.requestInterceptor || null,
responseInterceptor: this.responseInterceptor || null,
skipNormalization: this.skipNormalization || false,
...options,
}).then((obj) => {
this.originalSpec = this.spec;
Expand Down
104 changes: 104 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import xmock from 'xmock';
import cloneDeep from 'lodash/cloneDeep';

import Swagger from '../src/index';

Expand Down Expand Up @@ -710,4 +711,107 @@ describe('constructor', () => {
.catch(cb);
});
});

describe('skipNormalization', () => {
const spec = {
openapi: '3.0.0',
info: {
title: 'Cloudpotato - Medwork',
description: 'The Cloudpotato API',
version: '1.0.3',
contact: {},
},
tags: [],
servers: [],
paths: {
'/v1/clients/{id}/groups': {
get: {
operationId: 'getGroups',
summary: '',
parameters: [
{
name: 'options',
required: false,
in: 'query',
schema: {
type: 'string',
},
},
{
name: 'id',
required: true,
in: 'path',
schema: {
type: 'number',
},
},
],
responses: {
200: {
description: '',
},
},
tags: ['clients'],
security: [
{
bearer: [],
},
],
},
},
'/v1/groups': {
get: {
operationId: 'getGroups',
summary: '',
parameters: [],
responses: {
200: {
description: '',
},
},
tags: ['groups'],
security: [
{
bearer: [],
},
],
},
},
},
};

/**
* We're deep-cloning the spec before using it as resolution mutates
* the original object.
*/

describe('skipNormalization', () => {
describe('given skipNormalization option not provided', () => {
test('should resolve with normalized interfaces', async () => {
const client = await new Swagger({ spec: cloneDeep(spec) });

expect(client.apis.clients.getGroups1).toBeInstanceOf(Function);
expect(client.apis.groups.getGroups2).toBeInstanceOf(Function);
});
});

describe('given skipNormalization option provided as `false`', () => {
test('should resolve with normalized interfaces', async () => {
const client = await new Swagger({ spec: cloneDeep(spec), skipNormalization: false });

expect(client.apis.clients.getGroups1).toBeInstanceOf(Function);
expect(client.apis.groups.getGroups2).toBeInstanceOf(Function);
});
});

describe('given skipNormalization option provided as `true`', () => {
test('should resolve with normalized interfaces', async () => {
const client = await new Swagger({ spec: cloneDeep(spec), skipNormalization: true });

expect(client.apis.clients.getGroups).toBeInstanceOf(Function);
expect(client.apis.groups.getGroups).toBeInstanceOf(Function);
});
});
});
});
});