Regarding this issue:
I could really use such a “static validator”.
Thing is, that I don’t think it’s feasible to fully validate “statically”.
By “static” I mean given 2 definitions, whether they’re in openAPI format, scala tAPIr code, or anything else, I don’t think we can always prove they’re “isomorphic”.
Same API can be described in multiple ways.
For instance, an API that responds with a body that references a schema like:
components:
schemas:
User:
type: object
properties:
email:
type: string
name:
type: string
required:
- email
- name
can also be documented in a more relaxed way, e.g:
components:
schemas:
User:
type: object
additionalProperties:
type: string
The definition still holds, and correct for all possible outputs.
In Scala, it would be equivalent to use a case class of String members: case class User(email: String, name: String)
and replace it with a more permissive type Map[String, String]
which would still be correct.
When you think about it, you could document every API with Any
as return type, and it will be correct.
Other corner cases are different uses of oneOf
, anyOf
, allOf
, not
…
is
oneOf:
- string
- boolean
different than:
not:
oneOf:
- integer
- number
- array
- object
?
Point is, validating 2 schemas equivalency is hard.
It’s easier to validate that a specific request/response does not violate a given contract.
When I researched this, I came across this:
https://bitbucket.org/atlassian/swagger-request-validator
(and also: Bitbucket )
My goal was to use openapi contract generated from a non-scala service (python) to generate a scala client (zio).
I ended up writing the contract manually, for exactly the same reasons mentioned above.
The openapi contract generated from python was very general, used allOf
to denote inheritance with fields, while I needed to be specific, and generate sealed traits with oneOf
instead.
So now, the problem was: how do I validate that the manually written contract stays correct?
You can see why I take interest in this issue.
Any ideas on how to make it usable when the schemas are actually different, but still describe the same requests/responses in a different way?