Skip to content

Commit

Permalink
Merge branch 'feat/stretchable-layout' of github.com:jerensl/modelina…
Browse files Browse the repository at this point in the history
… into feat/stretchable-layout

merge from master
  • Loading branch information
jerensl committed Aug 6, 2024
2 parents a382171 + f7237e5 commit f175444
Show file tree
Hide file tree
Showing 23 changed files with 559 additions and 123 deletions.
12 changes: 12 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,18 @@
"code",
"test"
]
},
{
"login": "tomdevroomen",
"name": "Tom de Vroomen",
"avatar_url": "https://avatars.githubusercontent.com/u/4637986?v=4",
"profile": "https://github.com/tomdevroomen",
"contributions": [
"code",
"example",
"doc",
"test"
]
}
],
"contributorsPerLine": 7,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Discussions](https://img.shields.io/github/discussions/asyncapi/modelina)](https://github.com/asyncapi/modelina/discussions)
[![Website](https://img.shields.io/website?label=website&url=https%3A%2F%2Fwww.modelina.org)](https://www.modelina.org)
[![Playground](https://img.shields.io/website?label=playground&url=https%3A%2F%2Fwww.modelina.org%2Fplayground)](https://www.modelina.org/playground) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-92-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-93-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Your one-stop tool for generating accurate and well-tested models for representing the message payloads. Use it as a tool in your development workflow, or a library in a larger integrations, entirely in your control.
Expand Down Expand Up @@ -442,6 +442,7 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://pike.github.io/"><img src="https://avatars.githubusercontent.com/u/43494?v=4?s=100" width="100px;" alt="Axel Hecht"/><br /><sub><b>Axel Hecht</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Pike" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=Pike" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tomdevroomen"><img src="https://avatars.githubusercontent.com/u/4637986?v=4?s=100" width="100px;" alt="Tom de Vroomen"/><br /><sub><b>Tom de Vroomen</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=tomdevroomen" title="Code">💻</a> <a href="#example-tomdevroomen" title="Examples">💡</a> <a href="https://github.com/asyncapi/modelina/commits?author=tomdevroomen" title="Documentation">📖</a> <a href="https://github.com/asyncapi/modelina/commits?author=tomdevroomen" title="Tests">⚠️</a></td>
</tr>
</tbody>
</table>
Expand Down
17 changes: 17 additions & 0 deletions examples/java-generate-jakarta-constraint-annotation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Jakarta validation constraints annotations

A basic example that shows how Java data models having `jakarta.validation.constraints` annotations can be generated.

## 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
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Should be able to generate models with jakarta.validation.constraints annotations and should log expected output to console 1`] = `
Array [
"public class JakartaAnnotation {
@NotNull
@Min(0)
private double minNumberProp;
@NotNull
@Max(99)
private double maxNumberProp;
@Size(min=2, max=3)
private Object[] arrayProp;
@Pattern(regexp=\\"^I_\\")
@Size(min=3)
private String stringProp;
private Map<String, Object> additionalProperties;
public double getMinNumberProp() { return this.minNumberProp; }
public void setMinNumberProp(double minNumberProp) { this.minNumberProp = minNumberProp; }
public double getMaxNumberProp() { return this.maxNumberProp; }
public void setMaxNumberProp(double maxNumberProp) { this.maxNumberProp = maxNumberProp; }
public Object[] getArrayProp() { return this.arrayProp; }
public void setArrayProp(Object[] arrayProp) { this.arrayProp = arrayProp; }
public String getStringProp() { return this.stringProp; }
public void setStringProp(String stringProp) { this.stringProp = stringProp; }
public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; }
public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; }
}",
]
`;
15 changes: 15 additions & 0 deletions examples/java-generate-jakarta-constraint-annotation/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const spy = jest.spyOn(global.console, 'log').mockImplementation(() => {
return;
});
import { generate } from './index';

describe('Should be able to generate models with jakarta.validation.constraints annotations', () => {
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();
});
});
34 changes: 34 additions & 0 deletions examples/java-generate-jakarta-constraint-annotation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { JavaGenerator, JAVA_CONSTRAINTS_PRESET } from '../../src';

const generator = new JavaGenerator({
presets: [
{
preset: JAVA_CONSTRAINTS_PRESET,
options: {
importFrom: 'jakarta'
}
}
]
});
const jsonSchemaDraft7 = {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'JakartaAnnotation',
type: 'object',
properties: {
min_number_prop: { type: 'number', minimum: 0 },
max_number_prop: { type: 'number', exclusiveMaximum: 100 },
array_prop: { type: 'array', minItems: 2, maxItems: 3 },
string_prop: { type: 'string', pattern: '^I_', minLength: 3 }
},
required: ['min_number_prop', 'max_number_prop']
};

export async function generate(): Promise<void> {
const models = await generator.generate(jsonSchemaDraft7);
for (const model of models) {
console.log(model.result);
}
}
if (require.main === module) {
generate();
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/java-generate-jakarta-constraint-annotation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"config" : { "example_name" : "java-generate-jakarta-constraint-annotation" },
"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"
}
}
17 changes: 17 additions & 0 deletions examples/kotlin-generate-jakarta-constraint-annotation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Jakarta validation constraints annotations

A basic example that shows how Kotlin data models having `jakarta.validation.constraints` annotations can be generated.

## 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
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Should be able to generate models with jakarta.validation.constraints annotations and should log expected output to console 1`] = `
Array [
"data class JakartaAnnotation(
@get:NotNull
@get:Min(0)
val minNumberProp: Double,
@get:NotNull
@get:Max(99)
val maxNumberProp: Double,
@get:Min(101)
val minNumberPropExclusive: Double? = null,
@get:Size(min=2, max=3)
val arrayProp: List<Any>? = null,
@get:Pattern(regexp=\\"^I_\\")
@get:Size(min=3)
val stringProp: String? = null,
val additionalProperties: Map<String, Any>? = null,
)",
]
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const spy = jest.spyOn(global.console, 'log').mockImplementation(() => {
return;
});
import { generate } from './index';

describe('Should be able to generate models with jakarta.validation.constraints annotations', () => {
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();
});
});
35 changes: 35 additions & 0 deletions examples/kotlin-generate-jakarta-constraint-annotation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { KotlinGenerator, KOTLIN_CONSTRAINTS_PRESET } from '../../src';

const generator = new KotlinGenerator({
presets: [
{
preset: KOTLIN_CONSTRAINTS_PRESET,
options: {
importFrom: 'jakarta'
}
}
]
});
const jsonSchemaDraft7 = {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'JakartaAnnotation',
type: 'object',
properties: {
min_number_prop: { type: 'number', minimum: 0 },
max_number_prop: { type: 'number', exclusiveMaximum: 100 },
min_number_prop_exclusive: { type: 'number', exclusiveMinimum: 100 },
array_prop: { type: 'array', minItems: 2, maxItems: 3 },
string_prop: { type: 'string', pattern: '^I_', minLength: 3 }
},
required: ['min_number_prop', 'max_number_prop']
};

export async function generate(): Promise<void> {
const models = await generator.generate(jsonSchemaDraft7);
for (const model of models) {
console.log(model.result);
}
}
if (require.main === module) {
generate();
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"config" : { "example_name" : "kotlin-generate-jakarta-constraint-annotation" },
"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"
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asyncapi/modelina",
"version": "3.6.0",
"version": "3.7.0",
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
"license": "Apache-2.0",
"homepage": "https://www.modelina.org",
Expand Down
Loading

0 comments on commit f175444

Please sign in to comment.