简体   繁体   中英

Generate Models from swagger or JSON in Spring boot

We have requirement that the DTOs should be generated from an document where we can define the fieldName & fieldType that may be Json or Yaml. We are going to use these DTOs in Rest controller as request dto and response dto. So, Requirement is that we can define our request & response fields as per client requirements and configure it in some documents and that are automatically taken in code. How can I achieve this in Spring boot java?

If you have bound to use only JSON format, you can try and use Avro . With it you can define the schema using JSON format and later generate Java code (& some other languages too) using Maven/Gradle plugins.

If using OpenAPI/Swagger specification you can use swagger-codegen to generate server stubs in Java.

If you are free to choose message format, you can also look in to other specifications like Thrift , Protocol Buffers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM