-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fixture0 as test + example in README.
- Loading branch information
mkrause
committed
May 25, 2024
1 parent
d3f986c
commit 4270afa
Showing
9 changed files
with
337 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "Example API", | ||
"version": "0.1.0" | ||
}, | ||
"components": { | ||
"schemas": { | ||
"Category": { | ||
"type": "object", | ||
"properties": { | ||
"name": { "type": "string" }, | ||
"subcategories": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/components/schemas/Category" | ||
}, | ||
"default": {} | ||
} | ||
}, | ||
"required": ["name"] | ||
}, | ||
"User": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"title": "Unique ID", | ||
"type": "string", | ||
"format": "uuid" | ||
}, | ||
"name": { | ||
"title": "The user's full name.", | ||
"type": "string" | ||
}, | ||
"last_logged_in": { | ||
"title": "When the user last logged in.", | ||
"type": "string", "format": "date-time" | ||
}, | ||
"role": { | ||
"title": "The user's role within the system.", | ||
"description": "Roles:\n- ADMIN: Administrative permissions\n- USER: Normal permissions\n- AUDITOR: Read only permissions", | ||
"type": "string", | ||
"enum": ["ADMIN", "USER", "AUDITOR"] | ||
}, | ||
"interests": { | ||
"type": "array", | ||
"items": { "$ref": "#/components/schemas/Category" }, | ||
"default": [] | ||
} | ||
}, | ||
"required": ["name", "last_logged_in", "role"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import { type GenerationSpec } from '../../src/generation/generationSpec.ts'; | ||
|
||
|
||
export default { | ||
generationMethod: { method: 'bundled', bundleName: 'fixture0' }, | ||
hooks: {}, | ||
runtime: {}, | ||
modules: { | ||
'./Category.ts': { | ||
definitions: [ | ||
{ | ||
action: 'generate-schema', | ||
schemaId: 'Category', | ||
typeDeclarationEncoded: `{ | ||
readonly name: string, | ||
readonly subcategories?: undefined | { readonly [key: string]: _CategoryEncoded } | ||
}`, | ||
typeDeclaration: `{ | ||
readonly name: string, | ||
readonly subcategories: { readonly [key: string]: _Category } | ||
}`, | ||
}, | ||
], | ||
}, | ||
}, | ||
} satisfies GenerationSpec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright (c) Fortanix, Inc. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { promisify } from 'node:util'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { exec as execCallback } from 'node:child_process'; | ||
|
||
import { Schema as S } from '@effect/schema'; | ||
|
||
import assert from 'node:assert/strict'; | ||
import { test } from 'node:test'; | ||
|
||
|
||
const exec = promisify(execCallback); | ||
|
||
test('fixture0', { timeout: 30_000/*ms*/ }, async (t) => { | ||
const before = async () => { | ||
const cwd = path.dirname(fileURLToPath(import.meta.url)); | ||
console.log('Preparing fixture0...'); | ||
const { stdout, stderr } = await exec(`./generate_fixture.sh fixture0`, { cwd }); | ||
}; | ||
await before(); | ||
|
||
// @ts-ignore Will not type check until the generation is complete. | ||
const fixture = await import('../project_simulation/generated/fixture0/fixture0.ts'); | ||
|
||
await t.test('User', async (t) => { | ||
const user1 = { | ||
id: '5141C532-90CA-4F12-B3EC-22776F9DDD80', | ||
name: 'Alice', | ||
last_logged_in: '2024-05-25T19:20:39.482Z', | ||
role: 'USER', | ||
interests: [ | ||
{ name: 'Music' }, | ||
], | ||
}; | ||
assert.deepStrictEqual(S.decodeUnknownSync(fixture.User)(user1), { | ||
...user1, | ||
last_logged_in: new Date('2024-05-25T19:20:39.482Z'), // Transformed to Date | ||
interests: [ | ||
{ name: 'Music', subcategories: {} }, // Added default value | ||
], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.