|
6 | 6 | "time" |
7 | 7 |
|
8 | 8 | "github.com/go-openapi/spec" |
| 9 | + |
9 | 10 | apiSpec "github.com/zeromicro/go-zero/tools/goctl/api/spec" |
10 | 11 | "github.com/zeromicro/go-zero/tools/goctl/internal/version" |
11 | 12 | ) |
@@ -271,34 +272,47 @@ func wrapCodeMsgProps(ctx Context, properties spec.SchemaProps, atDoc apiSpec.At |
271 | 272 | return properties |
272 | 273 | } |
273 | 274 |
|
| 275 | + if len(wrapCodeMsgMapping.Data) == 0 { |
| 276 | + return properties |
| 277 | + } |
| 278 | + |
274 | 279 | globalCodeDesc := ctx.BizCodeEnumDescription |
275 | 280 | methodCodeDesc := getStringFromKVOrDefault(atDoc.Properties, propertyKeyBizCodeEnumDescription, globalCodeDesc) |
276 | | - return spec.SchemaProps{ |
| 281 | + |
| 282 | + schemaProps := spec.SchemaProps{ |
277 | 283 | Type: []string{swaggerTypeObject}, |
278 | 284 | Properties: spec.SchemaProperties{ |
279 | | - wrapCodeMsgMapping.Code: { |
280 | | - SwaggerSchemaProps: spec.SwaggerSchemaProps{ |
281 | | - Example: 0, |
282 | | - }, |
283 | | - SchemaProps: spec.SchemaProps{ |
284 | | - Type: []string{swaggerTypeInteger}, |
285 | | - Description: methodCodeDesc, |
286 | | - }, |
287 | | - }, |
288 | | - wrapCodeMsgMapping.Msg: { |
289 | | - SwaggerSchemaProps: spec.SwaggerSchemaProps{ |
290 | | - Example: "ok", |
291 | | - }, |
292 | | - SchemaProps: spec.SchemaProps{ |
293 | | - Type: []string{swaggerTypeString}, |
294 | | - Description: "business message", |
295 | | - }, |
296 | | - }, |
297 | 285 | wrapCodeMsgMapping.Data: { |
298 | 286 | SchemaProps: properties, |
299 | 287 | }, |
300 | 288 | }, |
301 | 289 | } |
| 290 | + |
| 291 | + if len(wrapCodeMsgMapping.Code) > 0 { |
| 292 | + schemaProps.Properties[wrapCodeMsgMapping.Code] = spec.Schema{ |
| 293 | + SchemaProps: spec.SchemaProps{ |
| 294 | + Description: methodCodeDesc, |
| 295 | + Type: []string{swaggerTypeInteger}, |
| 296 | + }, |
| 297 | + SwaggerSchemaProps: spec.SwaggerSchemaProps{ |
| 298 | + Example: 0, |
| 299 | + }, |
| 300 | + } |
| 301 | + } |
| 302 | + |
| 303 | + if len(wrapCodeMsgMapping.Msg) > 0 { |
| 304 | + schemaProps.Properties[wrapCodeMsgMapping.Msg] = spec.Schema{ |
| 305 | + SchemaProps: spec.SchemaProps{ |
| 306 | + Description: "business message", |
| 307 | + Type: []string{swaggerTypeString}, |
| 308 | + }, |
| 309 | + SwaggerSchemaProps: spec.SwaggerSchemaProps{ |
| 310 | + Example: "ok", |
| 311 | + }, |
| 312 | + } |
| 313 | + } |
| 314 | + |
| 315 | + return schemaProps |
302 | 316 | } |
303 | 317 |
|
304 | 318 | func specExtensions(api apiSpec.Info) (spec.Extensions, *spec.Info) { |
|
0 commit comments