Skip to content

Fix: prevent warnings when importing decoder #9

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openapi-typescript-validator",
"version": "3.2.0",
"version": "3.2.1",
"description": "Generate typescript with ajv validation based on openapi schemas",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/generate/generate-compile-decoders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import { $ModelImports } from './models';
import jsonSchema from './schema.json';

const ajv = new Ajv({ strict: false });
ajv.compile(jsonSchema);
$Formats
ajv.compile(jsonSchema);

// Decoders
$Decoders
Expand Down
1 change: 1 addition & 0 deletions tests/src/__snapshots__/custom-schema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Screen, ImageComponent, ListerComponent } from \\"./models\\";
import jsonSchema from \\"./schema.json\\";

const ajv = new Ajv({ strict: false });

ajv.compile(jsonSchema);

// Decoders
Expand Down
4 changes: 2 additions & 2 deletions tests/src/__snapshots__/format-schema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { User, Price } from \\"./models\\";
import jsonSchema from \\"./schema.json\\";

const ajv = new Ajv({ strict: false });
ajv.compile(jsonSchema);
addFormats(ajv, { mode: \\"fast\\", formats: [\\"date\\", \\"time\\"] });
ajv.compile(jsonSchema);

// Decoders
export const UserDecoder: Decoder<User> = {
Expand Down Expand Up @@ -53,8 +53,8 @@ import { User, Price } from \\"./models\\";
import jsonSchema from \\"./schema.json\\";

const ajv = new Ajv({ strict: false });
ajv.compile(jsonSchema);
addFormats(ajv, undefined);
ajv.compile(jsonSchema);

// Decoders
export const UserDecoder: Decoder<User> = {
Expand Down
7 changes: 7 additions & 0 deletions tests/src/format-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import fs from "fs";
import { generate } from "openapi-typescript-validator";
import Ajv from 'ajv';
import spyOn = jest.spyOn;

describe("format-schema - compile based", () => {
const name = "format";
Expand All @@ -19,6 +20,12 @@ describe("format-schema - compile based", () => {
});
});

test("should not generate warnings on import", async () => {
const consoleWarnSpy = spyOn(console, 'warn');
await import(path.join(generatedDir, 'decoders.ts'));
expect(consoleWarnSpy).not.toHaveBeenCalled();
});

test("files should match", () => {
const files = fs.readdirSync(generatedDir);
expect(files).toEqual([
Expand Down
3 changes: 2 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"declaration": true,
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "tests"]
Expand Down