Skip to content

Commit

Permalink
Merge branch 'master' into fix_playground
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Nov 6, 2023
2 parents 2ab22f5 + e2c4fa3 commit 7303fcf
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
9 changes: 5 additions & 4 deletions docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ This readme file goes into details how to integrate Modelina into various enviro
+ [TypeScript and Jest](#typescript-and-jest)
* [Security NOTICE](#security-notice)
- [Integrate Modelina in an AsyncAPI generator template](#integrate-modelina-in-an-asyncapi-generator-template)
- [Integrate Modelina into Maven](#integrate-modelina-into-maven)

<!-- tocstop -->

## Integrate Modelina in a browser

Integrating Modelina into websites is is one of the core features, and each framework is different, so here are some of examples:

- [Using Modelina in React](../examples/integrate-with-react/)
- [Using Modelina in Next](../examples/integrate-with-next/)
-
- [Using Modelina in React](../examples/integrate-with-react)
- [Using Modelina in Next](../examples/integrate-with-next)

> NOTICE: Modelina only works server side and not on the client side. In the React example its always rendered on the server side, and with Next you have to utilize [data fetching techniques](https://nextjs.org/docs/basic-features/data-fetching/overview) to retrieve the generated code from the server.
There are a few exceptions to the features Modelina support in a website environment. Those are listed here below:
Expand Down Expand Up @@ -63,7 +64,7 @@ There are at least two ways you can integrate Modelina into your build process f
- DO work with other inputs then AsyncAPI
- DO work when needing extensive build options and configurations

Checkout the Maven example here: [Integrate Modelina into Maven](../examples/integrate-modelina-into-maven/maven-project/)
Checkout the Maven example here: [Integrate Modelina into Maven](../examples/integrate-modelina-into-maven)

**AsyncAPI CLI**

Expand Down
1 change: 1 addition & 0 deletions docs/languages/Java.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ There are special use-cases that each language supports; this document pertains
+ [JSON marshaling and unmarshaling methods](#json-marshaling-and-unmarshaling-methods)
* [To and from XML](#to-and-from-xml)
* [To and from binary](#to-and-from-binary)
- [Integrate Modelina into Maven](#integrate-modelina-into-maven)

<!-- tocstop -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
exports[`Should be able to render python models and should log expected output to console: class-model 1`] = `
Array [
"class Root(BaseModel):
optionalField: Optional[str] = Field(alias='this field is optional')
requiredField: str = Field(alias='this field is required')
optionalField: Optional[str] = Field(alias='''this field is optional''')
requiredField: str = Field(alias='''this field is required''')
noDescription: Optional[str] = Field()
options: Optional[Options] = Field()
",
Expand Down
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": "2.0.1",
"version": "2.0.2",
"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
2 changes: 1 addition & 1 deletion src/generators/python/presets/Pydantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const PYTHON_PYDANTIC_CLASS_PRESET: ClassPresetType<PythonOptions> = {
? params.property.property.type
: `Optional[${params.property.property.type}]`;
const alias = params.property.property.originalInput['description']
? `alias='${params.property.property.originalInput['description']}'`
? `alias='''${params.property.property.originalInput['description']}'''`
: '';

return `${params.property.propertyName}: ${type} = Field(${alias})`;
Expand Down
34 changes: 34 additions & 0 deletions test/generators/python/presets/Pydantic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
PythonGenerator,
PYTHON_PYDANTIC_PRESET
} from '../../../../src/generators/python';

describe('PYTHON_PYDANTIC_PRESET', () => {
let generator: PythonGenerator;

beforeEach(() => {
generator = new PythonGenerator({
presets: [PYTHON_PYDANTIC_PRESET]
});
});

test('should render pydantic for class', async () => {
const doc = {
title: 'Test',
type: 'object',
properties: {
prop: {
description: `test
multi
line
description`,
type: 'string'
}
}
};

const models = await generator.generate(doc);
expect(models).toHaveLength(1);
expect(models[0].result).toMatchSnapshot();
});
});
11 changes: 11 additions & 0 deletions test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PYTHON_PYDANTIC_PRESET should render pydantic for class 1`] = `
"class Test(BaseModel):
prop: Optional[str] = Field(alias='''test
multi
line
description''')
additionalProperties: Optional[dict[Any, Any]] = Field()
"
`;

0 comments on commit 7303fcf

Please sign in to comment.