Skip to content

Commit 0aab5b9

Browse files
jonaslagonikennethaasanjano-petrasnilkanth987
authored
feat!: release v3 (#1599)
* feat!: convert to use multi parser (#1587) * feat!: adds support for duration in java (#1604) * feat: enable AsyncAPI v3 (#1600) * fix!: add csharp support for DateTime, TimeSpan, Guid (#1612) * feat!: adds extend in common, meta, and constrained models (#1613) * feat!: adds inheritance with interfaces for java (#1593) * chore: remove duplicate version entry for AsyncAPI processor (#1609) * feat!: render python union in pydantic in the pre 3.10 way (#1626) * feat: add file path as input (#1601) * feat!: add options as parameter to constraints (#1667) * fix: (un)marshalling tuple and dictionary unwrapping for Typescript (#1717) * fix: jsonbinpack preset and runtime tests (#1718) * chore: fix linting * chore: remove unused directory * feat!: add useJavascriptReservedKeywords option for TS (#1727) * feat: enable raw properties for interface (#1729) * fix: newtonsoft could not handle enum values (#1731) * chore: update Java runtime tests (#1739) * fix: edge case where references was incorrect handled for JSON Schema (#1754) * fix: recursion bug for get nearest dependencies (#1757) --------- Co-authored-by: Kenneth Aasan <[email protected]> Co-authored-by: jano-petras <[email protected]> Co-authored-by: Nilkanth Parmar <[email protected]>
1 parent a91b3d0 commit 0aab5b9

File tree

229 files changed

+4877
-1249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+4877
-1249
lines changed

.eslintrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"security",
77
"github",
88
"jest",
9-
"prettier"
9+
"prettier",
10+
"unused-imports"
1011
],
1112
"extends": [
1213
"eslint:recommended",
@@ -55,7 +56,7 @@
5556
"no-empty-character-class": 2,
5657
"no-self-compare": 2,
5758
"valid-typeof": 2,
58-
"no-unused-vars": 0,
59+
"unused-imports/no-unused-imports": 2,
5960
"handle-callback-err": 2,
6061
"no-shadow-restricted-names": 2,
6162
"no-new-require": 2,
@@ -138,7 +139,6 @@
138139
"prefer-const": 2,
139140
"prefer-spread": 2,
140141
"prefer-template": 2,
141-
"@typescript-eslint/no-unused-vars": 2,
142142
"prettier/prettier": 2,
143143
"sonarjs/no-identical-functions": "off",
144144
"sonarjs/prefer-single-boolean-return": "off",

docs/languages/TypeScript.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ There are special use-cases that each language supports; this document pertains
1717
- [Generate example data function](#generate-example-data-function)
1818
- [Rendering complete models to a specific module system](#rendering-complete-models-to-a-specific-module-system)
1919
- [Rendering comments from description and example fields](#rendering-comments-from-description-and-example-fields)
20+
- [Rendering raw properties for interface](#rendering-raw-properties-for-interface)
2021

2122
<!-- tocstop -->
2223

@@ -101,4 +102,10 @@ Check out this [example for a live demonstration how to generate the complete Ty
101102
## Rendering comments from description and example fields
102103
You can use the `TS_DESCRIPTION_PRESET` to generate JSDoc style comments from description and example fields in your model.
103104

104-
See [this example](../../examples/typescript-generate-comments) for how this can be used.
105+
See [this example](../../examples/typescript-generate-comments) for how this can be used.
106+
107+
## Rendering raw properties for interface
108+
109+
You can use the `rawPropertyNames: true` and `modelType: 'interface'` together to generate models that use raw properties.
110+
111+
See [this example](../../examples/typescript-generate-raw-properties) for how this can be used.

docs/migrations/version-2-to-3.md

+341
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
# Migration from v2 to v3
2+
3+
This document contains all the breaking changes and migrations guidelines for adapting your code to the new version.
4+
5+
## allowInheritance set to true will enable inheritance
6+
7+
This feature introduces a new option called `allowInheritance` in the interpreter options, which controls whether the generated models should inherit when the schema includes an `allOf`. By default, this option is set to false, which means that you'll not be affected if this property is not set. In the `MetaModel` and the `ConstrainedMetaModel` options, there is now an `extend` property (a list of models) and an `isExtended` property (boolean).
8+
9+
Here is an example of how to use the new feature and the `allowInheritance` option in your code:
10+
11+
```ts
12+
const generator = new JavaFileGenerator({
13+
processorOptions: {
14+
interpreter: {
15+
allowInheritance: true
16+
}
17+
}
18+
});
19+
```
20+
21+
## TypeScript
22+
23+
### JS reserved keywords are no longer applied by default
24+
By default up until now, JS reserved keywords have been checked for TS as well. Which means that something like:
25+
26+
```
27+
{
28+
$schema: 'http://json-schema.org/draft-07/schema#',
29+
type: 'object',
30+
additionalProperties: false,
31+
properties: {
32+
location: {
33+
type: 'string'
34+
}
35+
}
36+
}
37+
```
38+
39+
Would be default be rendered as:
40+
```ts
41+
class Root {
42+
private _reservedLocation?: string;
43+
44+
constructor(input: {
45+
reservedLocation?: string,
46+
}) {
47+
this._reservedLocation = input.reservedLocation;
48+
}
49+
50+
get reservedLocation(): string | undefined { return this._reservedLocation; }
51+
set reservedLocation(reservedLocation: string | undefined) { this._reservedLocation = reservedLocation; }
52+
}
53+
```
54+
55+
However, without setting `useJavascriptReservedKeywords: true` by default the following will be generated:
56+
57+
```ts
58+
class Root {
59+
private _location?: string;
60+
61+
constructor(input: {
62+
location?: string,
63+
}) {
64+
this._location = input.location;
65+
}
66+
67+
get location(): string | undefined { return this._location; }
68+
set location(location: string | undefined) { this._location = location; }
69+
}
70+
```
71+
72+
## JavaScript
73+
74+
Is not affected by this change.
75+
76+
## C#
77+
78+
### System.TimeSpan is used when format is time
79+
80+
This example used to generate a `string`, but is now instead using `System.TimeSpan`.
81+
82+
```yaml
83+
type: object
84+
properties:
85+
duration:
86+
type: string
87+
format: time
88+
```
89+
90+
will generate
91+
92+
```csharp
93+
public class TestClass {
94+
private System.TimeSpan duration;
95+
...
96+
}
97+
```
98+
99+
### System.DateTime is used when format is date-time
100+
101+
This example used to generate a `string`, but is now instead using `System.DateTime`.
102+
103+
```yaml
104+
type: object
105+
properties:
106+
dob:
107+
type: string
108+
format: date-time
109+
```
110+
111+
will generate
112+
113+
```csharp
114+
public class TestClass {
115+
private System.DateTime dob;
116+
...
117+
}
118+
```
119+
120+
### System.Guid is used when format is uuid
121+
122+
This example used to generate a `string`, but is now instead using `System.Guid`.
123+
124+
```yaml
125+
type: object
126+
properties:
127+
uniqueId:
128+
type: string
129+
format: uuid
130+
```
131+
132+
will generate
133+
134+
```csharp
135+
public class TestClass {
136+
private System.Guid uniqueId;
137+
...
138+
}
139+
```
140+
141+
## Java
142+
143+
### java.time.Duration is used when format is duration
144+
145+
This example used to generate a `String`, but is now instead using `java.time.Duration`.
146+
147+
```yaml
148+
type: object
149+
properties:
150+
duration:
151+
type: string
152+
format: duration
153+
```
154+
155+
will generate
156+
157+
```java
158+
public class TestClass {
159+
private java.time.Duration duration;
160+
...
161+
}
162+
```
163+
164+
### inheritance will generate interfaces
165+
166+
Please read the section about [allowInheritance](#allowinheritance-set-to-true-will-enable-inheritance) first. When `allowInheritance` is enabled, interfaces will be generated for schemas that uses `allOf`:
167+
168+
```yaml
169+
components:
170+
messages:
171+
Vehicle:
172+
payload:
173+
oneOf:
174+
- $ref: '#/components/schemas/Car'
175+
- $ref: '#/components/schemas/Truck'
176+
schemas:
177+
Vehicle:
178+
title: Vehicle
179+
type: object
180+
discriminator: vehicleType
181+
properties:
182+
vehicleType:
183+
title: VehicleType
184+
type: string
185+
length:
186+
type: number
187+
format: float
188+
required:
189+
- vehicleType
190+
Car:
191+
allOf:
192+
- '#/components/schemas/Vehicle'
193+
- type: object
194+
properties:
195+
vehicleType:
196+
const: Car
197+
Truck:
198+
allOf:
199+
- '#/components/schemas/Vehicle'
200+
- type: object
201+
properties:
202+
vehicleType:
203+
const: Truck
204+
```
205+
206+
will generate
207+
208+
```java
209+
public interface NewVehicle {
210+
VehicleType getVehicleType();
211+
}
212+
213+
public class Car implements NewVehicle, Vehicle {
214+
private final VehicleType vehicleType = VehicleType.CAR;
215+
private Float length;
216+
private Map<String, Object> additionalProperties;
217+
218+
public VehicleType getVehicleType() { return this.vehicleType; }
219+
220+
@Override
221+
public Float getLength() { return this.length; }
222+
@Override
223+
public void setLength(Float length) { this.length = length; }
224+
}
225+
226+
public enum VehicleType {
227+
CAR((String)\\"Car\\"), TRUCK((String)\\"Truck\\");
228+
229+
private String value;
230+
231+
VehicleType(String value) {
232+
this.value = value;
233+
}
234+
235+
public String getValue() {
236+
return value;
237+
}
238+
239+
public static VehicleType fromValue(String value) {
240+
for (VehicleType e : VehicleType.values()) {
241+
if (e.value.equals(value)) {
242+
return e;
243+
}
244+
}
245+
throw new IllegalArgumentException(\\"Unexpected value '\\" + value + \\"'\\");
246+
}
247+
248+
@Override
249+
public String toString() {
250+
return String.valueOf(value);
251+
}
252+
}
253+
254+
public interface Vehicle {
255+
public Float getLength();
256+
public void setLength(Float length);
257+
}
258+
259+
public class Truck implements NewVehicle, Vehicle {
260+
private final VehicleType vehicleType = VehicleType.TRUCK;
261+
private Float length;
262+
private Map<String, Object> additionalProperties;
263+
264+
public VehicleType getVehicleType() { return this.vehicleType; }
265+
266+
@Override
267+
public Float getLength() { return this.length; }
268+
@Override
269+
public void setLength(Float length) { this.length = length; }
270+
}
271+
```
272+
273+
## Kotlin
274+
275+
Is not affected by this change.
276+
277+
## Rust
278+
279+
Is not affected by this change.
280+
281+
## Python
282+
283+
### Union type for the Pydantic preset supports Python pre 3.10
284+
285+
Modelina used to use the newer way of representing unions in Python by using the `|` operator. In the Pydantic preset, this is now adjusted to support Python pre 3.10 by using `Union[Model1, Model2]` instead:
286+
287+
```yaml
288+
title: UnionTest
289+
type: object
290+
properties:
291+
unionTest:
292+
oneOf:
293+
- title: Union1
294+
type: object
295+
properties:
296+
testProp1:
297+
type: string
298+
- title: Union2
299+
type: object
300+
properties:
301+
testProp2:
302+
type: string
303+
```
304+
305+
will generate
306+
307+
```python
308+
class UnionTest(BaseModel):
309+
unionTest: Optional[Union[Union1, Union2]] = Field()
310+
additionalProperties: Optional[dict[Any, Any]] = Field()
311+
312+
class Union1(BaseModel):
313+
testProp1: Optional[str] = Field()
314+
additionalProperties: Optional[dict[Any, Any]] = Field()
315+
316+
class Union2(BaseModel):
317+
testProp2: Optional[str] = Field()
318+
additionalProperties: Optional[dict[Any, Any]] = Field()
319+
```
320+
321+
## Go
322+
323+
Is not affected by this change.
324+
325+
## Dart
326+
327+
Is not affected by this change.
328+
329+
## C++
330+
331+
Is not affected by this change.
332+
333+
## Options in constraints
334+
335+
As part of https://github.com/asyncapi/modelina/issues/1475 we had the need to access options in the constraint logic, therefore all constraints now have direct access to the provided options.
336+
337+
To make it easier we now expose types for each of the constraints in each language to make it easier to re-use in TS integrations. They can be accessed as following:
338+
339+
```ts
340+
import { <language>ConstantConstraint, <language>EnumKeyConstraint, <language>EnumValueConstraint, <language>ModelNameConstraint, <language>PropertyKeyConstraint } from @asyncapi/modelina
341+
```

examples/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ These are all specific examples only relevant to the TypeScript generator:
137137
- [typescript-use-esm](./typescript-use-esm) - A basic example that generate the models to use ESM module system.
138138
- [typescript-use-cjs](./typescript-use-cjs) - A basic example that generate the models to use CJS module system.
139139
- [typescript-generate-jsonbinpack](./typescript-generate-jsonbinpack) - A basic example showing how to generate models that include [jsonbinpack](https://github.com/sourcemeta/jsonbinpack) functionality.
140+
- [typescript-generate-raw-properties](./typescript-generate-raw-properties) - A basic example showing how to generate models that use raw properties for interface.
141+
- [typescript-use-js-reserved-keyword](./typescript-use-js-reserved-keyword) - A basic example showing how you can generate the models that take reserved JS keywords into account for model names, properties or enum keys.
142+
140143

141144
### Kotlin
142145
These are all specific examples only relevant to the Kotlin generator:

0 commit comments

Comments
 (0)