← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 10296.b.2.a · 生成模型:未记录

区分生成代码与手写实现

理解等级:中级

生成可重建的控制器接口、路由和模型,业务逻辑放在单独实现中。Spring 示例将 operationId 变成方法名,用注解挂载路由与约束,手写商品读取、必需字段赋值和异常转换。约束生成不能代替填充必需属性或校验真实错误响应。

规格变更后可在常规构建中重生成,只让生成器写回它拥有的文件,或用忽略规则保护手写内容。默认生成器的输出不适合团队时,可先调整配置和模板,再视需要选择自定义生成器。每次升级都应能编译并观察实际响应和 SDK 的方法名变化。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 通过代码与定义生成促进遵约 6.2 Generating code from OpenAPI · 查看原书依据

      You can regenerate the API service code from the updated product-catalog-v1-1.oas.yaml file. But you don’t want to overwrite the custom changes you added to the ProductsApiController.java file. To prevent this, add **ProductsApiController.java to the product-catalog-service/.openapi-generator-ignore file. Then, navigate to the chapter6 folder, and run the command shown in the next listing to generate the code using the product-catalog-v1-1.oas.yaml file.

    参考来源

    - 位置:《Automating API Delivery APIOps with OpenAPI》《第 06 章 通过代码与定义生成促进遵约》(6.2 Generating code from OpenAPI;来源项目 book-source,extracted/Automating API Delivery APIOps with OpenAPI/_epub-src/OEBPS/Text/chapter-6.xhtml#p75) - 结论依据:说明更新权威定义后保护手写控制器,让响应模型按定义重生成。 - 原始内容:You can regenerate the API service code from the updated product-catalog-v1-1.oas.yaml file. But you don’t want to overwrite the custom changes you added to the ProductsApiController.java file. To prevent this, add **ProductsApiController.java to the product-catalog-service/.openapi-generator-ignore file. Then, navigate to the chapter6 folder, and run the command shown in the next listing to generate the code using the product-catalog-v1-1.oas.yaml file.