Я следил за этим постом и пытался сгенерировать код сервера C # ядра asp.net с помощью swagger, но почему-то проверки maxLength
, minLength
и pattern
не появляются в сгенерированном классе 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
Есть идеи, что здесь пошло не так.