@devlearning/swagger-generator 1.1.15 → 1.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,16 +47,28 @@ export class ModelDartWriter {
47
47
  var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
48
48
  fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
49
49
  const isFileField = property.typeName === 'File';
50
+ const isFileArrayField = isFileField && property.isArray === true;
50
51
  const jsonKeyAnnotation = isFileField
51
52
  ? "@JsonKey(includeFromJson: false, includeToJson: false)"
52
53
  : undefined;
54
+ const defaultAnnotation = isFileArrayField
55
+ ? "@Default(<File>[])"
56
+ : undefined;
57
+ // File fields are excluded from JSON serialization; they must not be `required` for fromJson.
58
+ const nullable = isFileField && !property.isArray
59
+ ? '?'
60
+ : (property.nullable && !property.isArray ? '?' : '');
61
+ const required = isFileField
62
+ ? ''
63
+ : (property.nullable && !property.isArray ? '' : 'required ');
53
64
  dartModel.fields.push({
54
65
  name: property.name,
55
66
  type: property.isArray ? `List<${fieldTypeName}>` : fieldTypeName,
56
67
  typeName: property.typeName,
57
- nullable: property.nullable && !property.isArray ? '?' : '',
58
- required: property.nullable && !property.isArray ? '' : 'required ',
68
+ nullable,
69
+ required,
59
70
  jsonKeyAnnotation,
71
+ defaultAnnotation,
60
72
  });
61
73
  if (property.isTypeReference) {
62
74
  if (imports.findIndex(x => x.type.typeName == property.typeName) == -1) {
@@ -13,6 +13,9 @@ abstract class {{className}} with _${{className}} {
13
13
  {{#jsonKeyAnnotation}}
14
14
  {{{jsonKeyAnnotation}}}
15
15
  {{/jsonKeyAnnotation}}
16
+ {{#defaultAnnotation}}
17
+ {{{defaultAnnotation}}}
18
+ {{/defaultAnnotation}}
16
19
  {{required}}{{{type}}}{{nullable}} {{name}},
17
20
  {{/fields}}
18
21
  }) = _{{className}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlearning/swagger-generator",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "description": "Swagger generator apis and models for Angular and NextJS",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -33,6 +33,7 @@ interface FieldDefinitionDart {
33
33
  nullable: string;
34
34
  required: string;
35
35
  jsonKeyAnnotation?: string;
36
+ defaultAnnotation?: string;
36
37
  }
37
38
 
38
39
  interface ExportClassDefinitionDart {
@@ -101,17 +102,30 @@ export class ModelDartWriter {
101
102
  fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
102
103
 
103
104
  const isFileField = property.typeName === 'File';
105
+ const isFileArrayField = isFileField && property.isArray === true;
104
106
  const jsonKeyAnnotation = isFileField
105
107
  ? "@JsonKey(includeFromJson: false, includeToJson: false)"
106
108
  : undefined;
109
+ const defaultAnnotation = isFileArrayField
110
+ ? "@Default(<File>[])"
111
+ : undefined;
112
+
113
+ // File fields are excluded from JSON serialization; they must not be `required` for fromJson.
114
+ const nullable = isFileField && !property.isArray
115
+ ? '?'
116
+ : (property.nullable && !property.isArray ? '?' : '');
117
+ const required = isFileField
118
+ ? ''
119
+ : (property.nullable && !property.isArray ? '' : 'required ');
107
120
 
108
121
  dartModel.fields!.push(<FieldDefinitionDart>{
109
122
  name: property.name,
110
123
  type: property.isArray ? `List<${fieldTypeName}>` : fieldTypeName,
111
124
  typeName: property.typeName,
112
- nullable: property.nullable && !property.isArray ? '?' : '',
113
- required: property.nullable && !property.isArray ? '' : 'required ',
125
+ nullable,
126
+ required,
114
127
  jsonKeyAnnotation,
128
+ defaultAnnotation,
115
129
  });
116
130
 
117
131
  if (property.isTypeReference) {
@@ -13,6 +13,9 @@ abstract class {{className}} with _${{className}} {
13
13
  {{#jsonKeyAnnotation}}
14
14
  {{{jsonKeyAnnotation}}}
15
15
  {{/jsonKeyAnnotation}}
16
+ {{#defaultAnnotation}}
17
+ {{{defaultAnnotation}}}
18
+ {{/defaultAnnotation}}
16
19
  {{required}}{{{type}}}{{nullable}} {{name}},
17
20
  {{/fields}}
18
21
  }) = _{{className}};