Skip to content

Commit

Permalink
chore: exclude test util file from bundle
Browse files Browse the repository at this point in the history
docs: improve README
  • Loading branch information
yhnavein committed Jul 14, 2024
1 parent e631cfd commit ef16710
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,10 @@ function error(e) {
| Paths inheritance, comments (descriptions) | |
| Getting documents from remote locations or as path reference (local file) | |
| Grouping endpoints by tags + handle gracefully duplicate operation ids | |

## Used by

<div style="display: flex; gap: 1rem;">
<a href="https://www.britishcouncil.org"><img alt="British Council" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/BritishCouncil.png/320px-BritishCouncil.png" style="height: 50px;" /></a>
<a href="https://kpmg.com/"><img alt="KPMG" src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/KPMG.svg/320px-KPMG.svg.png" style="height: 50px;" /></a>
</div>
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swaggie",
"version": "1.0.0",
"version": "1.0.1",
"description": "Generate TypeScript REST client code from an OpenAPI spec",
"author": {
"name": "Piotr Dabrowski",
Expand All @@ -25,7 +25,7 @@
},
"scripts": {
"build": "sucrase ./src -d ./dist --transforms typescript,imports && npm run rm-tests && npm run types",
"rm-tests": "find dist/ -name '*.spec.js' -type f -delete",
"rm-tests": "find dist/ \\( -name '*.spec.js' -o -name 'types.js' \\) -type f -delete",
"types": "tsc src/types.ts --outDir dist/ --declaration --emitDeclarationOnly && cp test/index.d.ts ./dist/",
"test": "mocha",
"coverage": "npx nyc -r text -r json-summary mocha"
Expand Down
10 changes: 9 additions & 1 deletion src/gen/genOperations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { OpenAPIV3 as OA3 } from 'openapi-types';

import { prepareOperations, fixDuplicateOperations, getOperationName } from './genOperations';
import type { ApiOperation } from '../types';
import { getClientOptions } from '../utils';
import { getClientOptions } from '../../test/test.utils';

describe('prepareOperations', () => {
const opts = getClientOptions();
Expand Down Expand Up @@ -624,6 +624,14 @@ describe('getOperationName', () => {
input: { opId: 'Test_GetPetStory', group: 'Test' },
expected: 'getPetStory',
},
{
input: { opId: 'Passport.login', group: 'Test' },
expected: 'passportLogin',
},
{
input: { opId: 'Passport:login', group: 'Test' },
expected: 'passportLogin',
},
];

for (const { input, expected } of testCases) {
Expand Down
2 changes: 1 addition & 1 deletion src/gen/genTypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import type { OpenAPIV3 as OA3, OpenAPIV3_1 as OA31 } from 'openapi-types';

import generateTypes, { renderComment } from './genTypes';
import { getClientOptions, getDocument } from '../utils';
import { getClientOptions, getDocument } from '../../test/test.utils';

describe('generateTypes', () => {
const opts = getClientOptions();
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { MockAgent, setGlobalDispatcher } from 'undici';

import { runCodeGenerator, applyConfigFile } from './';
import { mockRequest } from './utils';
import { mockRequest } from '../test/test.utils';
import type { CliOptions } from './types';

describe('runCodeGenerator', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/swagger/operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import type { OpenAPIV3 as OA3 } from 'openapi-types';

import { getOperations } from './operations';
import { getDocument } from '../utils';
import { getDocument } from '../../test/test.utils';
import type { ApiOperation } from '../types';

describe('getOperations', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/swagger/typesExtractor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import type { OpenAPIV3 as OA3 } from 'openapi-types';
import type { ClientOptions } from '../types';
import { getParameterType, getTypeFromSchema } from './typesExtractor';
import { getClientOptions } from '../utils';
import { getClientOptions } from '../../test/test.utils';

describe('getParameterType', () => {
describe('empty cases', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/documentLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { MockAgent, setGlobalDispatcher } from 'undici';

import { loadSpecDocument } from './documentLoader';
import { mockRequest } from './test.utils';
import { mockRequest } from '../../test/test.utils';

// URLs are not used to fetch anything. We are faking responses through SinonJS
const petstore3 = {
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './utils';
export * from './documentLoader';
export * from './test.utils';
export * from './templateManager';
4 changes: 2 additions & 2 deletions src/utils/test.utils.ts → test/test.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import type { OpenAPIV3 as OA3 } from 'openapi-types';
import type { MockAgent } from 'undici';

import type { ClientOptions } from '../types';
import type { ClientOptions } from '../src/types';

/**
* Returns a valid OpenAPI 3.0 document with the minimal required fields.
Expand Down Expand Up @@ -50,7 +50,7 @@ export function mockRequest(mockAgent: MockAgent, url: string, responseFileName:
const urlObject = new URL(url);
const mockPool = mockAgent.get(urlObject.origin);

const response = fs.readFileSync(path.join(__dirname, '..', '..', 'test', responseFileName), {
const response = fs.readFileSync(path.join(__dirname, responseFileName), {
encoding: 'utf-8',
});

Expand Down

0 comments on commit ef16710

Please sign in to comment.