【问题标题】:How to generate mocks for open API spec file by using openapi-generator如何使用 openapi-generator 为开放的 API 规范文件生成模拟
【发布时间】:2019-09-24 21:28:13
【问题描述】:

faq-generators 表示生成服务器代码作为实现 API 后端的起点,以下是服务器生成器的一些用例:

模拟 - 根据响应对象中定义的示例字段轻松提供 API 后端进行模拟。

我很好奇如何通过使用 Spring 的 Gradle 插件来做到这一点(没有正确的示例)。

【问题讨论】:

    标签: java spring spring-boot openapi openapi-generator


    【解决方案1】:

    我使用这个胡子模板根据我在 swagger.json 和 swager-codegen 中的 swagger 示例生成一个 mocks.json

    
    { 
        {{#apiInfo}}
            {{#apis}}"{{classname}}":
                { {{#operations}}
                    {{#operation}}
                        {{#examples}}
                            "{{nickname}}": {{#example}}{{{example}}}{{/example}}{{^example}}null{{/example}}{{#hasMore}},{{/hasMore}}
                        {{/examples}}
                    {{/operation}}
                  {{/operations}} 
                } {{#hasMore}},{{/hasMore}}
            {{/apis}}
        {{/apiInfo}} 
    }
    
    

    【讨论】:

      猜你喜欢
      • 2022-10-13
      • 1970-01-01
      • 2022-07-23
      • 1970-01-01
      • 2019-12-12
      • 2021-08-08
      • 1970-01-01
      • 2022-07-15
      • 1970-01-01
      相关资源
      最近更新 更多