English 中文(简体)
使用aspnetcore 6.x嵌套类名打开API生成器
原标题:Open API Generator using aspnetcore 6.x nested classes names

问题

在使用ASP.NET Core的Open API Generator 6.x版中,由于未知原因,嵌套对象类型被创建为自己的类。5.x版本的openapi生成器对嵌套对象使用了相同的类。

yml规范中有这两个组件(示例repo中的event-api-v1.swagger.3.0.3.yaml)

components:
  schemas:
    EventIdentifier:
      title: EventIdentifier
      type: object
      properties:
        eventId:
          type: string
        occurrenceDate:
          type: string
          nullable: true
      example:
        eventId:  43128940213498123 
        occurrenceDate:  2021-05-30T15:00:00+12:00 

    BookingCreate:
      title: BookingCreate
      type: object
      description: A particular person s booking for an event.
      required:
        - eventId
        - personId
      properties:
        eventId:
          allOf:
            - $ref:  #/components/schemas/EventIdentifier 
          description:  A unique identifier for the event that the booking relates to. 
        personId:
          type: string
          nullable: false

版本5.x生成C#作为

public class BookingCreate : IEquatable<BookingCreate>
{
    public EventIdentifier EventId { get; set; }
}

但是,6.x版本正在生成

public class BookingCreate : IEquatable<BookingCreate>
{
    public BookingCreateEventId EventId { get; set; }
}

对于已经建立的大型项目来说,采用6.x版本的openapi生成器是一个巨大的障碍。

问题

这种行为上的改变可以通过配置或自定义模板恢复到5.x行为吗?

关于自定义模板,在检查model.mustache文件时,dataType提供的值将作为EventId属性的BookingCreateEventId/SpeakerCreateEventId提供,因此无法轻松自定义。

观察

将openapi规范更改为3.1(例如,event-api-v1.swagger.3.1.yaml)会导致EventId的类型被设置回EventIdentifier,但生成器还不支持3.1,因此所有的基元类型都被生成为对象。

代码

可以在此处找到一个小型测试项目:https://github.com/marcsstevenson/OpenApiGeneratorTesting

尝试次数

曾尝试使用openapi生成器的6.0、6.1、6.2、6.3、6.4、6.5、6.6版本,但无法复制5.x版本的代码输出

最佳回答

我可以确认我也有同样的行为,而且不仅仅是在aspnetcore生成器上。

经过进一步检查,我认为您面临的问题是由于您使用了allOf运算符(如果提到的对象是否是组合对象,我认为这会混淆解析器?)。

删除它,应该会生成正确的模型。

https://github.com/marcsstevenson/OpenApiGeneratorTesting/pull/1

Relevant GitHub issue https://github.com/OpenAPITools/openapi-generator/issues/12838

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签