Is there a way to use Swagger just for validation without using the whole framework?

前端 未结 1 1550
自闭症患者
自闭症患者 2021-01-23 17:54

Suppose I have an existing Java service implementing a JSON HTTP API, and I want to add a Swagger schema and automatically validate requests and responses against it without ret

1条回答
  •  囚心锁ツ
    2021-01-23 18:34

    I don't think there's anything ready to do this alone, but you can easily do this by the following:

    • Grab the SchemaValidator from the Swagger Inflector project. You can use this to validate inbound and outbound payloads
    • Assign a schema portion to your request/response definitions. That means you'll need to assign a specific section of the JSON schema to your operations
    • Create a filter for your API to grab the payloads and use the schema

    That will let you easily see if the payloads match the expected structure.

    Of course, this is all done for you automatically with Inflector but there should be enough of the raw components to help you do this inside your own implementation

    0 讨论(0)
提交回复
热议问题