Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tajnymag committed Mar 3, 2024
1 parent 05e65fe commit 0e2d6fe
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/reproduce.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install dependencies
run: npm install
- name: Run generator
run: node generate-bearer-type-error.cjs
run: node test-bearer-type-error.cjs
reproduce-component-separator-error:
runs-on: ubuntu-latest
steps:
Expand All @@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: npm install
- name: Run generator
run: node generate-component-separator-error.cjs
run: node test-component-separator-error.cjs
reproduce-root-path-error:
runs-on: ubuntu-latest
steps:
Expand All @@ -36,4 +36,4 @@ jobs:
- name: Install dependencies
run: npm install
- name: Run generator
run: node generate-root-path-error.cjs
run: node test-root-path-error.cjs
22 changes: 0 additions & 22 deletions generate-root-path-error.cjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const path = require('path');
const assert = require('assert');

const { openapiToTsJsonSchema, fastifyIntegrationPlugin } = require('openapi-ts-json-schema');

const FILENAME = 'bearer-type-error.yaml';
const OUTPUT_PATH = path.resolve(__dirname, `generated-${path.basename(FILENAME, path.extname(FILENAME))}`);

async function processSpec(filename) {
return openapiToTsJsonSchema({
openApiSchema: path.resolve(__dirname, filename),
openApiSchema: path.resolve(__dirname, FILENAME),
definitionPathsToGenerateFrom: ['paths', 'components.schemas'],
refHandling: 'keep',
outputPath: path.resolve(__dirname, `generated-${path.basename(filename, path.extname(filename))}`),
outputPath: OUTPUT_PATH,
plugins: [
fastifyIntegrationPlugin({
sharedSchemasFilter: ({ schemaId }) => schemaId.startsWith('/components/schemas'),
Expand All @@ -16,7 +21,8 @@ async function processSpec(filename) {
}

async function generate() {
await processSpec('component-separator-error.yaml');
// does not throw
await assert.doesNotReject(processSpec(FILENAME));
}

generate();
32 changes: 32 additions & 0 deletions test-component-separator-error.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path');
const assert = require('assert');
const fs = require('fs');
const { openapiToTsJsonSchema, fastifyIntegrationPlugin } = require('openapi-ts-json-schema');

const FILENAME = 'component-separator-error.yaml';
const OUTPUT_PATH = path.resolve(__dirname, `generated-${path.basename(FILENAME, path.extname(FILENAME))}`);

async function processSpec(filename) {
return openapiToTsJsonSchema({
openApiSchema: path.resolve(__dirname, FILENAME),
definitionPathsToGenerateFrom: ['paths', 'components.schemas'],
refHandling: 'keep',
outputPath: OUTPUT_PATH,
plugins: [
fastifyIntegrationPlugin({
sharedSchemasFilter: ({ schemaId }) => schemaId.startsWith('/components/schemas'),
}),
],
});
}

async function generate() {
// does not throw
await assert.doesNotReject(processSpec(FILENAME));

// contains the expected import
const fastifyIntegrationContens = fs.readFileSync(path.resolve(OUTPUT_PATH, 'fastify-integration.ts'), 'utf8');
assert.ok(fastifyIntegrationContens.includes('import componentsSchemasHelloWorld from "./components/schemas/HelloWorld";'));
}

generate();
11 changes: 8 additions & 3 deletions generate-bearer-type-error.cjs → test-root-path-error.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const path = require('path');
const assert = require('assert');
const { openapiToTsJsonSchema, fastifyIntegrationPlugin } = require('openapi-ts-json-schema');

const FILENAME = 'root-path-error.yaml';
const OUTPUT_PATH = path.resolve(__dirname, `generated-${path.basename(FILENAME, path.extname(FILENAME))}`);

async function processSpec(filename) {
return openapiToTsJsonSchema({
openApiSchema: path.resolve(__dirname, filename),
openApiSchema: path.resolve(__dirname, FILENAME),
definitionPathsToGenerateFrom: ['paths', 'components.schemas'],
refHandling: 'keep',
outputPath: path.resolve(__dirname, `generated-${path.basename(filename, path.extname(filename))}`),
outputPath: OUTPUT_PATH,
plugins: [
fastifyIntegrationPlugin({
sharedSchemasFilter: ({ schemaId }) => schemaId.startsWith('/components/schemas'),
Expand All @@ -16,7 +20,8 @@ async function processSpec(filename) {
}

async function generate() {
await processSpec('bearer-type-error.yaml');
// does not throw
await assert.doesNotReject(processSpec(FILENAME));
}

generate();

0 comments on commit 0e2d6fe

Please sign in to comment.