@necessarylion/adonis-autoswagger 0.0.21 → 0.0.22

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.
@@ -379,6 +379,7 @@ class AutoSwagger {
379
379
  in: 'query',
380
380
  name: key,
381
381
  required: required.includes(key),
382
+ description: data.description,
382
383
  schema: data,
383
384
  });
384
385
  }
@@ -109,6 +109,8 @@ class ValidatorParser {
109
109
  const field = property["fieldName"];
110
110
  if (type === "object") {
111
111
  obj[field] = { type: "object", ...this.#parseSchema(property, refs) };
112
+ if (meta.description)
113
+ obj[field].description = meta.description;
112
114
  }
113
115
  else {
114
116
  // if array
@@ -123,24 +125,26 @@ class ValidatorParser {
123
125
  };
124
126
  }
125
127
  else {
126
- const meta = this.#getMetaFromValidations(property["each"]["validations"], refs);
128
+ const itemMeta = this.#getMetaFromValidations(property["each"]["validations"], refs);
127
129
  const subType = this.#getType(property["each"]["subtype"]);
128
130
  obj[field] = {
129
131
  type: "array",
130
132
  items: {
131
- type: this.#getType(property["each"]["type"]),
132
- ...meta,
133
+ type: this.#getType(property["each"]["type"], property["each"]["subtype"]),
134
+ ...itemMeta,
133
135
  format: subType === 'multipartFile' ? 'binary' : undefined,
134
- example: meta.example ??
135
- meta.minimum ??
136
+ example: itemMeta.example ??
137
+ itemMeta.minimum ??
136
138
  this.exampleGenerator.exampleByType(subType),
137
139
  },
138
140
  };
139
141
  }
142
+ if (meta.description)
143
+ obj[field].description = meta.description;
140
144
  }
141
145
  else {
142
146
  obj[field] = {
143
- type: this.#getType(type),
147
+ type: this.#getType(type, property["subtype"]),
144
148
  example: meta.example ??
145
149
  meta.minimum ??
146
150
  this.exampleGenerator.exampleByType("number"),
@@ -156,15 +160,22 @@ class ValidatorParser {
156
160
  result["required"] = required;
157
161
  return result;
158
162
  }
159
- #getType(type) {
163
+ #getType(type, subtype) {
160
164
  if (type == "literal") {
161
- return "string";
165
+ // vine says "literal" for every plain value and keeps the real type in subtype
166
+ return subtype === "number" || subtype === "boolean" ? subtype : "string";
162
167
  }
163
168
  return type;
164
169
  }
165
170
  #getMetaFromValidations(validations, refs) {
166
171
  let meta = {};
167
172
  for (const validation of validations) {
173
+ if (refs[validation["ruleFnId"]].options?.description) {
174
+ meta = {
175
+ ...meta,
176
+ description: refs[validation["ruleFnId"]].options.description,
177
+ };
178
+ }
168
179
  if (refs[validation["ruleFnId"]].options?.example) {
169
180
  meta = {
170
181
  ...meta,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@necessarylion/adonis-autoswagger",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Auto-Generate swagger docs for AdonisJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",