Skip to content

Commit 07d0cbf

Browse files
authored
feat!: improve anonym names (#2378)
1 parent 21068b8 commit 07d0cbf

File tree

24 files changed

+3016
-717
lines changed

24 files changed

+3016
-717
lines changed

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,84 @@ The generated Python code behavior remains unchanged - all imports will continue
5454

5555
## AsyncAPI
5656

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+
57135
### Multiple messages in operations now generate individual models
58136

59137
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.

examples/asyncapi-from-object/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Should be able to process a pure AsyncAPI object and should log expected output to console 1`] = `
44
Array [
5-
"class AnonymousSchema_1 {
5+
"class TestPayload {
66
private _email?: string;
77
88
constructor(input: {

examples/asyncapi-from-parser/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Should be able to process AsyncAPI object from parser and should log expected output to console 1`] = `
44
Array [
5-
"class AnonymousSchema_1 {
5+
"class TestPayload {
66
private _email?: string;
77
88
constructor(input: {

examples/asyncapi-from-v1-parser/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Should be able to process already parsed AsyncAPI document from old parser and should log expected output to console 1`] = `
44
Array [
5-
"class AnonymousSchema_1 {
5+
"class TestPayload {
66
private _email?: string;
77
88
constructor(input: {

examples/asyncapi-openapi-schema/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Should be able to process an AsyncAPI object with OpenAPI schema type and should log expected output to console 1`] = `
44
Array [
5-
"class AnonymousSchema_1 {
5+
"class ExamplePayload {
66
private _title?: string | null;
77
private _author?: string;
88
private _additionalProperties?: Map<string, any>;

examples/asyncapi-raml-schema/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Should be able to process an AsyncAPI object with RAML schema type and should log expected output to console 1`] = `
44
Array [
5-
"class AnonymousSchema_1 {
5+
"class ExamplePayload {
66
private _title: string;
77
private _author: string;
88
private _additionalProperties?: Map<string, any>;

src/processors/AbstractInputProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ProcessorOptions, InputMetaModel } from '../models';
22

33
export abstract class AbstractInputProcessor {
4-
public static MODELGEN_INFFERED_NAME = 'x-modelgen-inferred-name';
4+
public static MODELINA_INFERRED_NAME = 'x-modelgen-inferred-name';
55
abstract process(
66
input: any,
77
options?: ProcessorOptions

0 commit comments

Comments
 (0)