softwaremill / tapir

Rapid development of self-documenting APIs
https://tapir.softwaremill.com
Apache License 2.0
1.32k stars 402 forks source link

Validation of endpoints against a given OpenAPI schema #3645

Open adamw opened 3 months ago

adamw commented 3 months ago

Sometimes it might be desirable to verify if the endpoints match a given OpenAPI schema. To implement this, we would need to parse the schema (see https://github.com/softwaremill/sttp-apispec/issues/2 - although this is already partially done), and then invoke comparison of the two schemas (generated from endpoints & parsed), ignoring fields which do not matter (e.g. descriptions, or examples)

ghik commented 2 months ago

What's the "user story" here? Is it something like:

  1. User has a given OpenAPI to implement
  2. Decides to do it manually instead of using codegen
  3. Writes an API in tapir but wants to validate it against the given OpenAPI

?

adamw commented 2 months ago

This, or: develops an API, publishes it, and wants to ensure that anything that's changed doesn't break the published contract

ghik commented 2 months ago

https://github.com/softwaremill/sttp-apispec/pull/157 introduced SchemaComparator to check compatibility between schemas. This is likely the most complex part of full OpenAPI validation. Schema comparator would be used:

Possible improvements to SchemaComparator:

Further work needed to have a full OpenApi comparator:

ghik commented 2 months ago

Proposed structure for compatibility issues reported by full OpenAPI comparator

Compatibility issues for content comparison:

Note: "writer" and "reader" correspond to: