Json Schema from Tapir Schema

Hello all,

apologies for a potentially stupid question: would it make sense to generate Json schema from tapir Schema? So far we are using GitHub - andyglow/scala-jsonschema: Scala JSON Schema, but this is yet another derivation path to handle.

Yes, you can use OpenAPI 3.1 (which isn’t yet supported by swagger, hence it’s not the default), where the schemas are a superset of json schemas as far as I remember. Take a look at GitHub - softwaremill/sttp-apispec: OpenAPI, AsyncAPI and JSON Schema Scala models., it would be good to know what’s missing (either in code or documentation) to address these use-cases.

Thank you for pointing into this direction! I stumbled uopn sttp.tapir.docs.apispec.schema.Schemas but could not find a way to instantiate it, other than to copycat the code from sttp.tapir.docs.openapi.EndpointToOpenAPIDocs.

I believe we are missing an api which would allow to convert sttp.tapir.Schema into sttp.apispec.Schema. Currently, glue code components are package-private (like sttp.tapir.docs.openapi.EndpointToOpenAPIDocs).

Ah yes, you are right, that’s not exposed right now. But this can be changed of course :wink:

Please create an issue :slight_smile: And/or a PR - this would probably go to the apispec-docs module

Out of curiosity, can you share what is your use-case?

Here is the ticket (no PR :frowning: ) with some rationale: Expose converters from tapir Schema to Json Schema (sttp.apispec.Schema) · Issue #2838 · softwaremill/tapir · GitHub

1 Like