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
2 changes: 1 addition & 1 deletion packages/api/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from 'commander';

import commands from './cli/commands';
import commands from './commands';
import * as pkg from './packageInfo';

(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type Storage from '../storage';
import type Oas from 'oas';

import { PACKAGE_NAME, PACKAGE_VERSION } from '../../packageInfo';
import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo';

export interface InstallerOptions {
/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import makeDir from 'make-dir';
import ssri from 'ssri';
import validateNPMPackageName from 'validate-npm-package-name';

import { PACKAGE_VERSION } from '../packageInfo';

import Fetcher from './fetcher';
import { PACKAGE_VERSION } from './packageInfo';

export default class Storage {
static dir: string;
Expand Down
51 changes: 0 additions & 51 deletions packages/api/test/__fixtures__/oas.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TSGeneratorOptions } from '../../../../src/cli/codegen/languages/typescript';
import type { TSGeneratorOptions } from '../../../src/codegen/languages/typescript';

import { promises as fs } from 'fs';
import path from 'path';
Expand All @@ -10,9 +10,9 @@ import Oas from 'oas';
import uniqueTempDir from 'unique-temp-dir';
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';

import TSGenerator from '../../../../src/cli/codegen/languages/typescript';
import Storage from '../../../../src/cli/storage';
import * as packageInfo from '../../../../src/packageInfo';
import TSGenerator from '../../../src/codegen/languages/typescript';
import * as packageInfo from '../../../src/packageInfo';
import Storage from '../../../src/storage';

function assertSDKFixture(file: string, fixture: string, opts: TSGeneratorOptions = {}) {
return async () => {
Expand All @@ -23,7 +23,7 @@ function assertSDKFixture(file: string, fixture: string, opts: TSGeneratorOption
const actualFiles = await ts.generator();

// Determine if the generated code matches what we've got in our fixture.
const dir = path.resolve(path.join(__dirname, '..', '..', '..', '__fixtures__', 'sdk', fixture));
const dir = path.resolve(path.join(__dirname, '..', '..', '__fixtures__', 'sdk', fixture));

let expectedFiles: string[];
try {
Expand Down Expand Up @@ -63,7 +63,7 @@ function assertSDKFixture(file: string, fixture: string, opts: TSGeneratorOption
);

// Make sure that we can load the SDK without any TS compilation errors.
const sdk = await import(`../../../__fixtures__/sdk/${fixture}`).then(r => r.default);
const sdk = await import(`../../__fixtures__/sdk/${fixture}`).then(r => r.default);
expect(sdk.constructor.name).toBe('SDK');
};
}
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('typescript', () => {
});

it('should be able to make an API request (TS)', async () => {
const sdk = await import('../../../__fixtures__/sdk/simple-ts').then(r => r.default);
const sdk = await import('../../__fixtures__/sdk/simple-ts').then(r => r.default);
fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.searchParams);

await sdk.findPetsByStatus({ status: ['available'] }).then(({ data, status, headers, res }) => {
Expand All @@ -184,7 +184,7 @@ describe('typescript', () => {
});

it('should be able to make an API request with an `accept` header`', async () => {
const sdk = await import('../../../__fixtures__/sdk/simple-ts').then(r => r.default);
const sdk = await import('../../__fixtures__/sdk/simple-ts').then(r => r.default);
fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.headers);

await sdk
Expand All @@ -198,7 +198,7 @@ describe('typescript', () => {
});

it('should be able to make an API request (JS + CommonJS)', async () => {
const sdk = await import('../../../__fixtures__/sdk/simple-js-cjs').then(r => r.default);
const sdk = await import('../../__fixtures__/sdk/simple-js-cjs').then(r => r.default);
fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.searchParams);

await sdk.findPetsByStatus({ status: ['available'] }).then(({ data, status, headers, res }) => {
Expand All @@ -210,7 +210,7 @@ describe('typescript', () => {
});

it('should be able to make an API request (JS + ESM)', async () => {
const sdk = await import('../../../__fixtures__/sdk/simple-js-esm').then(r => r.default);
const sdk = await import('../../__fixtures__/sdk/simple-js-esm').then(r => r.default);
fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.searchParams);

await sdk.findPetsByStatus({ status: ['available'] }).then(({ data, status, headers, res }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Oas from 'oas';
import OASNormalize from 'oas-normalize';
import { describe, it, expect } from 'vitest';

import TSGenerator from '../../../../../src/cli/codegen/languages/typescript';
import TSGenerator from '../../../../src/codegen/languages/typescript';

// These APIs don't have any schemas so they should only be generating an `index.ts`.
const APIS_WITHOUT_SCHEMAS = ['poemist.com'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';

import { docblockEscape, generateTypeName, wordWrap } from '../../../../../src/cli/codegen/languages/typescript/util';
import { docblockEscape, generateTypeName, wordWrap } from '../../../../src/codegen/languages/typescript/util';

describe('ts codegen utils', () => {
describe('#docblockEscape', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import loadSpec from '@api/test-utils/load-spec';
import fetchMock from 'fetch-mock';
import { describe, beforeAll, it, expect } from 'vitest';

import Fetcher from '../../src/cli/fetcher';
import Fetcher from '../src/fetcher';

let readmeSpec;

Expand Down Expand Up @@ -200,16 +200,15 @@ describe('fetcher', () => {
const fetcher = new Fetcher(require.resolve('@readme/oas-examples/3.0/json/readme.json'));

const res = await fetcher.load();
expect(res.paths['/api-specification'].get.parameters).toBeDereferenced();
expect(res.paths?.['/api-specification']?.get?.parameters).toBeDereferenced();
});

it('should be able to handle a relative path', async () => {
const fetcher = new Fetcher('../api/test/__fixtures__/oas.json');
const fetcher = new Fetcher('../test-utils/definitions/simple.json');

await expect(fetcher.load()).resolves.toHaveProperty('info', {
version: '1.0.0',
title: 'Single Path',
description: 'This is a slimmed down single path version of the Petstore definition.',
title: 'Swagger Petstore',
});
});

Expand All @@ -218,7 +217,7 @@ describe('fetcher', () => {
const fetcher = new Fetcher(file);

const res = await fetcher.load();
expect(res.paths['/api-specification'].get.parameters).toBeDereferenced();
expect(res.paths?.['/api-specification']?.get?.parameters).toBeDereferenced();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import fetchMock from 'fetch-mock';
import uniqueTempDir from 'unique-temp-dir';
import { describe, beforeAll, beforeEach, afterEach, it, expect } from 'vitest';

import Storage from '../../src/cli/storage';
import { PACKAGE_VERSION } from '../../src/packageInfo';
import { PACKAGE_VERSION } from '../src/packageInfo';
import Storage from '../src/storage';

let petstoreSimple;

Expand Down Expand Up @@ -287,7 +287,7 @@ describe('storage', () => {
});

it('should be able to handle a relative path', async () => {
const file = '../api/test/__fixtures__/oas.json';
const file = '../test-utils/definitions/simple.json';
const storage = new Storage(file, 'relative-path');

expect(storage.isInLockfile()).toBe(false);
Expand All @@ -297,14 +297,13 @@ describe('storage', () => {
expect(storage.isInLockfile()).toBe(true);
expect(storage.getAPIDefinition().info).toStrictEqual({
version: '1.0.0',
title: 'Single Path',
description: 'This is a slimmed down single path version of the Petstore definition.',
title: 'Swagger Petstore',
});

expect(storage.getFromLockfile()).toStrictEqual({
identifier: 'relative-path',
source: file,
integrity: 'sha512-Qi5BB9mfzkRqHe0rMvjRmKunNJ21zILF0e4KzYKi2hMw+zLfi2idmmn0lAngdRwqYdGIKTXUWhJNn0i3iDqUUg==',
integrity: 'sha512-Ey83iRY4tY7JCCUI03eqfNb8YsxKlBdLILXcLDBbxZ1a2X/YfTspCTA8mLp6aaG9gRSyNMhI1hmtSlduWZw8RA==',
installerVersion: PACKAGE_VERSION,
});
});
Expand Down Expand Up @@ -337,7 +336,7 @@ describe('storage', () => {
});

it('should error if definition is not a valid openapi file', async () => {
await expect(new Storage(require.resolve('../../package.json'), 'invalid').load()).rejects.toThrow(
await expect(new Storage(require.resolve('../package.json'), 'invalid').load()).rejects.toThrow(
"Sorry, that doesn't look like a valid OpenAPI definition.",
);
});
Expand Down