大张旗鼓的C#代码生成最大长度验证丢失

时间:2019-10-11 07:46:49

标签: c# asp.net-core swagger swagger-codegen swagger-editor

我一直遵循此post,并试图使用大摇大摆来生成asp.net核心C#服务器代码,但是不出现maxLengthminLengthpattern验证在生成的c#类上,我假设它会是属性的一种属性,例如我将获得[Required]属性用于模型验证。

我的Yaml如下:

swagger: '2.0'
info:
  title: My Cars API
  description: Simple API for demonstrating json validation
  version: 1.0.0
host: localhost
schemes:
  - http
produces:
  - application/json
paths:
  /cars:
    post:
      summary: Add a new (dream) car
      description: |
        Adds a new car to the database.
      tags:
        - Cars
      parameters:
        - name: car
          schema:
            $ref: '#/definitions/Car'
          in: body
          required: true
          description: the new dream car
      responses:
        '200':
          description: Succeeded
        '500':
          description: unexpected error
definitions:
  Registration:
    type: object
    required:
    - state
    - plate_number
    properties:
      state:
        type: string
        description: Two letter state abbreviation code
        pattern: '^[A-Z]{2}$'
      plate_number:
        type: string
        description: The license plate number
        minLength: 1
        maxLength: 8
  Car:
    type: object
    required:
    - make
    - model
    - model_year
    - doors
    - vin
    - color
    properties:
      make:
        type: string
        description: The name of the vehicle manufacturer
      model:
        type: string
        description: The name of the vehicle model
        maxLength: 10
      model_year:
        type: string
        description: The manufacturers model year
        pattern: '^[0-9]{2,4}$'
        minLength: 2
      doors:
        type: integer
        description: The number of doors
        minimum: 2
        maximum: 5
      vin:
        type: string
        description: The vehicle VIN number
        pattern: '^[a-zA-Z0-9]{17}$'
      color:
        type: string
        description: Manufacturers vehicle color
      registration:
        $ref: '#/definitions/Registration'

并且生成的汽车模型部分为:

namespace IO.Swagger.Models
{ 
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public partial class Car : IEquatable<Car>
    { 
        /// <summary>
        /// The name of the vehicle manufacturer
        /// </summary>
        /// <value>The name of the vehicle manufacturer</value>
        [Required]
        [DataMember(Name="make")]
        public string Make { get; set; }

        /// <summary>
        /// The name of the vehicle model
        /// </summary>
        /// <value>The name of the vehicle model</value>
        [Required]
        [DataMember(Name="model")]
        public string Model { get; set; }

        /// <summary>
        /// The manufacturers model year
        /// </summary>
        /// <value>The manufacturers model year</value>
        [Required]
        [DataMember(Name="model_year")]
        public string ModelYear { get; set; }

        /// <summary>
        /// The number of doors
        /// </summary>
        /// <value>The number of doors</value>
        [Required]
        [DataMember(Name="doors")]
        public int? Doors { get; set; }

        /// <summary>
        /// The vehicle VIN number
        /// </summary>
        /// <value>The vehicle VIN number</value>
        [Required]
        [DataMember(Name="vin")]
        public string Vin { get; set; }

        /// <summary>
        /// Manufacturers vehicle color
        /// </summary>
        /// <value>Manufacturers vehicle color</value>
        [Required]
        [DataMember(Name="color")]
        public string Color { get; set; }

        /// <summary>
        /// Gets or Sets Registration
        /// </summary>
        [DataMember(Name="registration")]
        public Registration Registration { get; set; }
    }
}

我们可以看到生成了[Required]属性,但没有maxLength等属性。

我使用的cli命令是:

 java -jar swagger-codegen-cli.jar generate -i mycar.json -l aspnetcore -o samples/server

任何想法这里出了什么问题。

0 个答案:

没有答案