Skip to content

Commit 7fea54f

Browse files
authored
Merge branch 'next' into fix/typescript-date-mapping
2 parents cbca257 + c192e80 commit 7fea54f

File tree

78 files changed

+4317
-1021
lines changed

Some content is hidden

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

78 files changed

+4317
-1021
lines changed

.github/workflows/if-nodejs-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ jobs:
141141
fields: repo,action,workflow
142142
text: 'Release workflow failed in release job'
143143
env:
144-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}
144+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}

docs/advanced.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ This document contains many of the advanced use-cases that you may stumble upon
1515
- [Change the generated indentation type and size](#change-the-generated-indentation-type-and-size)
1616
- [Change the type mapping](#change-the-type-mapping)
1717
- [Changing the constrain rules](#changing-the-constrain-rules)
18-
- [Customizing the interpreter options](#customizing-the-interpreter-options)
1918

2019
<!-- tocstop -->
2120

@@ -104,15 +103,3 @@ There can be multiple reasons why you want to change the default constrain rules
104103
Check out this [example out for a live demonstration](../examples/overwrite-default-constraint/) for how to overwrite the default constraints.
105104

106105
Check out this [example out for a live demonstration](../examples/overwrite-naming-formatting/) for how to overwrite the naming formatting for models.
107-
108-
## Customizing the interpreter options
109-
110-
According to JSON schema draft 7, if `additionalProperties` or `additionalItems` are omitted, their default value is `true`. The `Interpreter` honors this behavior, however this creates more loose models that might not be the intention for the developer.
111-
112-
We suggest not using this option if it can be avoided, as it limits your generated models to include any additional properties, and would simply be ignored. Instead adapt your schemas to be more strict by setting these keywords to `false`. This option should really only be used when you have no control over your input and the output is unintended.
113-
114-
To set the interpreter up to ignore the default behavior, you can further restrict your models with the following options:
115-
- `ignoreAdditionalProperties` - if set, it ensures that `additionalProperties` by default is ignored.
116-
- `ignoreAdditionalItems` - if set, it ensures that `additionalItems` by default is ignored.
117-
118-
Check out this [example out for a live demonstration](../examples/passing-interpreter-options/) for how to customize the behavior of `additionalProperties`.

docs/inputs/JSON_Schema.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,115 @@
1-
# Interpretation of JSON Schema to CommonModel
1+
# JSON Schema as an input
2+
3+
## Processor Options
4+
5+
The JSON Schema input processor provides several options to customize how schemas are interpreted into models. These options can be passed to the generator via the `processorOptions` parameter.
6+
7+
### Available Options
8+
9+
#### `interpretSingleEnumAsConst`
10+
**Type**: `boolean` (default: `false`)
11+
12+
When enabled, a single enum value like `{enum: ['test']}` will be interpreted the same as `{const: 'test'}`. This reduces the number of enums being generated and uses constant values instead.
13+
14+
**Example**:
15+
```typescript
16+
const generator = new TypeScriptGenerator({
17+
processorOptions: {
18+
jsonSchema: {
19+
interpretSingleEnumAsConst: true
20+
}
21+
}
22+
});
23+
```
24+
25+
See the [json-schema-single-enum-as-const example](../../examples/json-schema-single-enum-as-const) for a complete usage example.
26+
27+
#### `propertyNameForAdditionalProperties`
28+
**Type**: `string` (default: `'additionalProperties'`)
29+
30+
Changes which property name should be used to represent `additionalProperties` in JSON Schema. This is useful when you want to customize the generated property name for additional properties in your models.
31+
32+
**Example**:
33+
```typescript
34+
const generator = new TypeScriptGenerator({
35+
processorOptions: {
36+
jsonSchema: {
37+
propertyNameForAdditionalProperties: 'metadata'
38+
}
39+
}
40+
});
41+
```
42+
43+
See the [json-schema-additional-properties-representation example](../../examples/json-schema-additional-properties-representation) for a complete usage example.
44+
45+
#### `allowInheritance`
46+
**Type**: `boolean` (default: `false`)
47+
48+
Enables support for inheritance in the generated models. When enabled, models can extend from other models based on the schema structure (such as `allOf` patterns).
49+
50+
**Example**:
51+
```typescript
52+
const generator = new TypeScriptGenerator({
53+
processorOptions: {
54+
jsonSchema: {
55+
allowInheritance: true
56+
}
57+
}
58+
});
59+
```
60+
61+
See the [json-schema-allow-inheritance example](../../examples/json-schema-allow-inheritance) for a complete usage example.
62+
63+
#### `disableCache`
64+
**Type**: `boolean` (default: `false`)
65+
66+
Disables the seenSchemas cache in the Interpreter. This option should only be used in specific internal scenarios and generally should not be modified by end users.
67+
68+
#### `ignoreAdditionalProperties`
69+
**Type**: `boolean` (default: `false`)
70+
71+
For JSON Schema draft 7, `additionalProperties` are by default `true`, but this might create unintended properties in the models. Use this option to ignore default `additionalProperties` for models that have other properties defined with them.
72+
73+
**Note**: ONLY use this option if you do not have control over your schema files. Instead, adapt your schemas to be more strict by setting `additionalProperties: false`.
74+
75+
**Example**:
76+
```typescript
77+
const generator = new TypeScriptGenerator({
78+
processorOptions: {
79+
jsonSchema: {
80+
ignoreAdditionalProperties: true
81+
}
82+
}
83+
});
84+
```
85+
86+
See the [json-schema-ignore-additional-properties example](../../examples/json-schema-ignore-additional-properties) for a complete usage example.
87+
88+
#### `ignoreAdditionalItems`
89+
**Type**: `boolean` (default: `false`)
90+
91+
For JSON Schema draft 7, `additionalItems` are by default `true`, but this might create unintended types for arrays. Use this option to ignore default `additionalItems` for models as long as there are other types set for the array.
92+
93+
**Note**: ONLY use this option if you do not have control over the schema files you use to generate models from. Instead, you should adapt your schemas to be more strict by setting `additionalItems: false`.
94+
95+
**Example**:
96+
```typescript
97+
const generator = new TypeScriptGenerator({
98+
processorOptions: {
99+
jsonSchema: {
100+
ignoreAdditionalItems: true
101+
}
102+
}
103+
});
104+
```
105+
106+
See the [json-schema-ignore-additional-items example](../../examples/json-schema-ignore-additional-items) for a complete usage example.
107+
108+
---
109+
110+
For a comprehensive example demonstrating multiple processor options together, see the [json-schema-processor-options example](../../examples/json-schema-processor-options).
111+
112+
## Interpretation of JSON Schema to CommonModel
2113

3114
The library transforms JSON Schema from data validation rules to data definitions (`CommonModel`(s)).
4115

docs/migrations/version-4-to-5.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Migration from v4 to v5
2+
3+
There are no required changes to move from v4 to v5.

docs/migrations/version-5-to-6.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Migration from v5 to v6
2+
3+
This document contain all the breaking changes and migrations guidelines for adapting your code to the new version.
4+
5+
## Removed deprecated `interpreter` option from `ProcessorOptions`
6+
7+
The deprecated `interpreter` option has been removed from `ProcessorOptions`. You should now use the `jsonSchema` option instead.
8+
9+
**Before (v5):**
10+
```typescript
11+
const result = await generator.generate({
12+
processorOptions: {
13+
interpreter: {
14+
// interpreter options
15+
}
16+
}
17+
});
18+
```
19+
20+
**After (v6):**
21+
```typescript
22+
const result = await generator.generate({
23+
processorOptions: {
24+
jsonSchema: {
25+
// JSON Schema processor options
26+
}
27+
}
28+
});
29+
```
30+
## Python
31+
32+
### Removal of deprecated `importsStyle` option
33+
34+
The `importsStyle` option was deprecated in v4 and has now been completely removed in v6. This option is no longer needed as all Python models now use explicit import style (`from . import ${model.name}`) to support circular model dependencies.
35+
36+
If you were still using this option in your code, simply remove it from your generator options:
37+
38+
```ts
39+
// Before (v5 and earlier)
40+
const generator = new PythonGenerator();
41+
const models = await generator.generateCompleteModels(schema, {
42+
importsStyle: 'explicit', // This option is no longer available
43+
packageName: 'modelina'
44+
});
45+
46+
// After (v6)
47+
const generator = new PythonGenerator();
48+
const models = await generator.generateCompleteModels(schema, {
49+
packageName: 'modelina'
50+
});
51+
```
52+
53+
The generated Python code behavior remains unchanged - all imports will continue to use the explicit style.
54+
55+
## AsyncAPI
56+
57+
### Improved schema naming strategy
58+
59+
Modelina v6 introduces a significantly improved naming strategy for AsyncAPI schemas, providing more meaningful and context-aware names for generated models to minimize the amount of `Anonymous Schema`. If you have explicitly defined names for all models, this should not affect you.
60+
61+
#### Channel-based naming for inline message payloads
62+
63+
Inline message payloads (without explicit message names) now derive their names from the channel path instead of receiving generic anonymous names.
64+
65+
**Before (v5):**
66+
```yaml
67+
asyncapi: 2.0.0
68+
channels:
69+
/user/signedup:
70+
subscribe:
71+
message:
72+
payload:
73+
type: object
74+
properties:
75+
email:
76+
type: string
77+
```
78+
Generated model: `AnonymousSchema_1` or `<anonymous-message-1>Payload`
79+
80+
**After (v6):**
81+
Generated model: `UserSignedupPayload` (derived from channel path `/user/signedup`)
82+
83+
#### Hierarchical naming for nested schemas
84+
85+
Nested schemas in properties, `allOf`, `oneOf`, `anyOf`, `dependencies`, and `definitions` now receive hierarchical names based on their parent schema and property path.
86+
87+
**Before (v5):**
88+
```yaml
89+
components:
90+
schemas:
91+
MainSchema:
92+
type: object
93+
properties:
94+
config:
95+
type: object
96+
properties:
97+
setting:
98+
type: string
99+
```
100+
Generated models: `MainSchema`, `AnonymousSchema_2`, `AnonymousSchema_3`
101+
102+
**After (v6):**
103+
Generated models: `MainSchema`, `MainSchemaConfig`, `MainSchemaConfigSetting`
104+
105+
#### Improved handling of composition keywords
106+
107+
Schemas using `allOf`, `oneOf`, and `anyOf` now generate more descriptive names:
108+
109+
**Before (v5):**
110+
```yaml
111+
components:
112+
schemas:
113+
Pet:
114+
oneOf:
115+
- type: object
116+
properties:
117+
bark: { type: boolean }
118+
- type: object
119+
properties:
120+
meow: { type: boolean }
121+
```
122+
Generated models: `Pet`, `AnonymousSchema_1`, `AnonymousSchema_2`
123+
124+
**After (v6):**
125+
Generated models: `Pet`, `PetOneOfOption0`, `PetOneOfOption1`
126+
127+
#### Enhanced naming for special schema types
128+
129+
- **Array items**: `ParentSchemaItem` instead of `AnonymousSchema_N`
130+
- **Pattern properties**: `ParentSchemaPatternProperty` instead of `AnonymousSchema_N`
131+
- **Additional properties**: `ParentSchemaAdditionalProperty` instead of `AnonymousSchema_N`
132+
- **Dependencies**: `ParentSchemaDependencyName` instead of `AnonymousSchema_N`
133+
- **Definitions**: `ParentSchemaDefinitionName` instead of `AnonymousSchema_N`
134+
135+
### Multiple messages in operations now generate individual models
136+
137+
When processing AsyncAPI v3 documents with multiple messages in a single operation, Modelina now correctly generates individual models for each message payload in addition to the `oneOf` wrapper model.
138+
139+
**Example AsyncAPI Document:**
140+
```yaml
141+
asyncapi: 3.0.0
142+
info:
143+
title: User Service
144+
version: 1.0.0
145+
channels:
146+
userEvents:
147+
address: user/events
148+
messages:
149+
UserCreated:
150+
$ref: '#/components/messages/UserCreated'
151+
UserUpdated:
152+
$ref: '#/components/messages/UserUpdated'
153+
operations:
154+
onUserEvents:
155+
action: receive
156+
channel:
157+
$ref: '#/channels/userEvents'
158+
messages:
159+
- $ref: '#/channels/userEvents/messages/UserCreated'
160+
- $ref: '#/channels/userEvents/messages/UserUpdated'
161+
components:
162+
messages:
163+
UserCreated:
164+
payload:
165+
type: object
166+
properties:
167+
id:
168+
type: string
169+
name:
170+
type: string
171+
UserUpdated:
172+
payload:
173+
type: object
174+
properties:
175+
id:
176+
type: string
177+
name:
178+
type: string
179+
updatedAt:
180+
type: string
181+
```
182+
183+
**Before (v5):**
184+
```typescript
185+
const generator = new JavaGenerator();
186+
const models = await generator.generate(inputModel);
187+
// Problem: No UserCreated or UserUpdated classes were generated
188+
```
189+
190+
**After (v6):**
191+
```typescript
192+
const generator = new JavaGenerator();
193+
const models = await generator.generate(inputModel);
194+
// ✓ Now generates:
195+
// - UserCreatedPayload.java
196+
// - UserUpdatedPayload.java
197+
// - userEvents interface (discriminated union)
198+
```
199+
200+
No code changes are required. This is an enhancement that fixes incomplete model generation. If you have custom post-processing logic that filters generated models, you may need to adjust it to handle the additional models.

docs/presets.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Modelina uses something called **presets** to extend the rendered model. You can
3737
- [**Package**](#package)
3838
- [**Union**](#union)
3939
- [**Tuple**](#tuple)
40+
- [**NewType**](#newtype)
4041
+ [Dart](#dart)
4142
- [**Class**](#class-4)
4243
- [**Enum**](#enum-5)
@@ -496,6 +497,17 @@ This preset is a generator for the meta model `ConstrainedTupleModel` and [can b
496497
| `field` | | `field` object as a [`ConstrainedTupleValueModel`](./internal-model.md#the-constrained-meta-model) instance, `fieldIndex`. |
497498
| `structMacro` | | `field` object as a [`ConstrainedTupleValueModel`](./internal-model.md#the-constrained-meta-model) instance, `fieldIndex`. |
498499

500+
#### **NewType**
501+
502+
This preset is a generator for the meta model `ConstrainedMetaModel` and [can be accessed through the `model` argument](#presets-shape).
503+
This preset is called each time the [New Type pattern](https://doc.rust-lang.org/rust-by-example/generics/new_types.html) is used to wrap
504+
non-object models (i.e., boolean, integers, floats, strings or arrays).
505+
506+
| Method | Description | Additional arguments |
507+
|---|---|---|
508+
| `field` | A method to extend rendered the only field: the wrapped model. | |
509+
| `structMacro` | | |
510+
499511
### Dart
500512
#### **Class**
501513

0 commit comments

Comments
 (0)