diff --git a/examples/generate-scala-enums/README.md b/examples/generate-scala-enums/README.md new file mode 100644 index 0000000000..167791ec4a --- /dev/null +++ b/examples/generate-scala-enums/README.md @@ -0,0 +1,17 @@ +# Scala Enums + +A basic example of how to use Modelina and output a Scala enumeration. + +## How to run this example + +Run this example using: + +```sh +npm i && npm run start +``` + +If you are on Windows, use the `start:windows` script instead: + +```sh +npm i && npm run start:windows +``` diff --git a/examples/generate-scala-enums/index.spec.ts b/examples/generate-scala-enums/index.spec.ts new file mode 100644 index 0000000000..7afa11cb9c --- /dev/null +++ b/examples/generate-scala-enums/index.spec.ts @@ -0,0 +1,15 @@ +const spy = jest.spyOn(global.console, 'log').mockImplementation(() => { + return; +}); +import { generate } from './index'; + +describe('Should be able to render Kotlin Enums', () => { + afterAll(() => { + jest.restoreAllMocks(); + }); + test('and should log expected output to console', async () => { + await generate(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); + }); +}); diff --git a/examples/generate-scala-enums/index.ts b/examples/generate-scala-enums/index.ts new file mode 100644 index 0000000000..458cc94c8d --- /dev/null +++ b/examples/generate-scala-enums/index.ts @@ -0,0 +1,20 @@ +import { ScalaGenerator } from '../../src/generators/scala'; + +const generator = new ScalaGenerator(); +const jsonSchemaDraft7 = { + $schema: 'http://json-schema.org/draft-07/schema#', + additionalProperties: false, + $id: 'protocol', + type: ['string', 'int', 'boolean'], + enum: ['HTTP', 1, 'HTTPS', true] +}; + +export async function generate(): Promise { + const models = await generator.generate(jsonSchemaDraft7); + for (const model of models) { + console.log(model.result); + } +} +if (require.main === module) { + generate(); +} diff --git a/examples/generate-scala-enums/package-lock.json b/examples/generate-scala-enums/package-lock.json new file mode 100644 index 0000000000..71205d5b99 --- /dev/null +++ b/examples/generate-scala-enums/package-lock.json @@ -0,0 +1,10 @@ +{ + "name": "generate-scala-enums", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "hasInstallScript": true + } + } +} diff --git a/examples/generate-scala-enums/package.json b/examples/generate-scala-enums/package.json new file mode 100644 index 0000000000..f3f7301a7c --- /dev/null +++ b/examples/generate-scala-enums/package.json @@ -0,0 +1,12 @@ +{ + "config": { + "example_name": "generate-scala-enums" + }, + "scripts": { + "install": "cd ../.. && npm i", + "start": "../../node_modules/.bin/ts-node --cwd ../../ ./examples/$npm_package_config_example_name/index.ts", + "start:windows": "..\\..\\node_modules\\.bin\\ts-node --cwd ..\\..\\ .\\examples\\%npm_package_config_example_name%\\index.ts", + "test": "../../node_modules/.bin/jest --config=../../jest.config.js ./examples/$npm_package_config_example_name/index.spec.ts", + "test:windows": "..\\..\\node_modules\\.bin\\jest --config=..\\..\\jest.config.js examples/%npm_package_config_example_name%/index.spec.ts" + } +} diff --git a/examples/generate-scala-models/README.md b/examples/generate-scala-models/README.md new file mode 100644 index 0000000000..c8770e41e7 --- /dev/null +++ b/examples/generate-scala-models/README.md @@ -0,0 +1,17 @@ +# Scala Data Models + +A basic example of how to use Modelina and output a Scala data model. + +## How to run this example + +Run this example using: + +```sh +npm i && npm run start +``` + +If you are on Windows, use the `start:windows` script instead: + +```sh +npm i && npm run start:windows +``` diff --git a/examples/generate-scala-models/index.spec.ts b/examples/generate-scala-models/index.spec.ts new file mode 100644 index 0000000000..010afc6245 --- /dev/null +++ b/examples/generate-scala-models/index.spec.ts @@ -0,0 +1,15 @@ +const spy = jest.spyOn(global.console, 'log').mockImplementation(() => { + return; +}); +import { generate } from './index'; + +describe('Should be able to render Kotlin Models', () => { + afterAll(() => { + jest.restoreAllMocks(); + }); + test('and should log expected output to console', async () => { + await generate(); + expect(spy.mock.calls.length).toEqual(3); + expect(spy.mock.calls[0]).toMatchSnapshot(); + }); +}); diff --git a/examples/generate-scala-models/index.ts b/examples/generate-scala-models/index.ts new file mode 100644 index 0000000000..74cde5421c --- /dev/null +++ b/examples/generate-scala-models/index.ts @@ -0,0 +1,41 @@ +import { ScalaGenerator } from '../../src/generators/scala'; + +const generator = new ScalaGenerator(); +const jsonSchemaDraft7 = { + $schema: 'http://json-schema.org/draft-07/schema#', + type: 'object', + additionalProperties: false, + properties: { + email: { + type: 'string', + format: 'email' + }, + cache: { + type: 'integer' + }, + website: { + type: 'object', + additionalProperties: false, + properties: { + domain: { + type: 'string', + format: 'url' + }, + protocol: { + type: 'string', + enum: ['HTTP', 'HTTPS'] + } + } + } + } +}; + +export async function generate(): Promise { + const models = await generator.generate(jsonSchemaDraft7); + for (const model of models) { + console.log(model.result); + } +} +if (require.main === module) { + generate(); +} diff --git a/examples/generate-scala-models/package-lock.json b/examples/generate-scala-models/package-lock.json new file mode 100644 index 0000000000..61b5cb38ef --- /dev/null +++ b/examples/generate-scala-models/package-lock.json @@ -0,0 +1,10 @@ +{ + "name": "generate-scala-models", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "hasInstallScript": true + } + } +} diff --git a/examples/generate-scala-models/package.json b/examples/generate-scala-models/package.json new file mode 100644 index 0000000000..5ca775bc64 --- /dev/null +++ b/examples/generate-scala-models/package.json @@ -0,0 +1,12 @@ +{ + "config": { + "example_name": "generate-scala-models" + }, + "scripts": { + "install": "cd ../.. && npm i", + "start": "../../node_modules/.bin/ts-node --cwd ../../ ./examples/$npm_package_config_example_name/index.ts", + "start:windows": "..\\..\\node_modules\\.bin\\ts-node --cwd ..\\..\\ .\\examples\\%npm_package_config_example_name%\\index.ts", + "test": "../../node_modules/.bin/jest --config=../../jest.config.js ./examples/$npm_package_config_example_name/index.spec.ts", + "test:windows": "..\\..\\node_modules\\.bin\\jest --config=..\\..\\jest.config.js examples/%npm_package_config_example_name%/index.spec.ts" + } +} diff --git a/package.json b/package.json index 375294a7f8..bc7a340031 100644 --- a/package.json +++ b/package.json @@ -127,8 +127,7 @@ "generate:assets": "npm run build:prod && npm run docs && npm run generate:readme:toc && npm run format", "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", "prepublishOnly": "npm run build:prod && npm run generate:readme:toc && npm run format", - "format": "prettier --config .prettierrc \"./**/*.ts\" --write", - "format-now": "prettier --config .prettierrc test/generators/scala/ScalaGenerator.spec.ts --write" + "format": "prettier --config .prettierrc \"./**/*.ts\" --write" }, "publishConfig": { "access": "public"