文章
Jeff Liu · 一月 7, 2021 阅读大约需 2 分钟

从持久类和序列类生成 Swagger 规范

最近,我需要从持久类和序列类生成一个 Swagger 规范,所以我发布了我的代码(它并不完整 - 你仍然需要处理应用程序的细节,但这是一个开始)。 代码在这里

假设你有下面的类:

 

你可以通过以下代码自动生成此 Swagger 定义:

 REST.Test.Person:
   type: "object"
   properties:
     Age:
       type: "integer"
     DOB:
       type: "string"
     FavoriteColors:
       type: "array"
       items:
         type: "string"
     FavoriteNumbers:
       type: "object"
     Home:
       $ref: "#/definitions/REST.Test.Address"
     Name:
       type: "string"
     Office:
       $ref: "#/definitions/REST.Test.Address"
     SSN:
       type: "string"
     Spouse:
       $ref: "#/definitions/REST.Test.Person"
 REST.Test.Address:
   type: "object"
   properties:
     City:
       type: "string"
     State:
       type: "string"
     Street:
       type: "string"
     Zip:
       type: "string"

主方法:Utils.YAML:GenerateClasses

测试运行:do ##class(Utils.YAML).Test()

00
2 0 0 23
Log in or sign up to continue