Inline schemas with no ids present problems for client code generation #54
fariadev22
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
There was some work done here: https://github.com/json-schema-org/vocab-idl but I believe it has stalled a little. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
I'm an API specifications expert at APIMatic. For those who might not know APIMatic is heavily involved in auto-generation of client SDKs from API specification formats especially OpenAPI. One of the key problems we've encountered over the years for code generation is handling inline schemas i.e. schemas that don't have a unique id assigned to them.
Problem
In APIMatic, for client code generation purposes, object schemas with known properties are converted into respective model classes in the chosen language. Similarly, enumerations are also converted to enum representations in the chosen language. To perform this conversion a unique code-friendly name is required. This works well for schemas defined globally in OpenAPI v3 with a unique name i.e. under the
components/schemas
but not so much for inline schemas that have no identifiers.Our fallback mechanisms for inline schemas involve processing the schema
title
instead. However,title
is not as often used as we'd like or are way too long/not code-friendly enough. The ultimate fallback mechanism we use is to simply auto-generate the name from the closest information available e.g. using the property name if the inline schema definition is found in schemaproperties
or by using the parameter name if the schema is linked to a parameter and so on. However, the names auto-generated this way aren't always user-friendly especially when those names have potential clashes with other such inline schemas (a parameter schema name might clash with a property schema name and so on) and have to be made unique somehow (by appending a number or some other approach).Suggestion
OpenAPI v4 allows setting a kind of a schema id much like an id for operations (
operationId
) that are expected to be unique, short and code-friendly. The problem with this approach could be regarding ensuring uniqueness as schemas are generally spread all over the place and even across files. But the naming problem would still be mitigated largely with this approach.I don't have any other suggestions at the moment but thought to put my ideas out anyway :)
Beta Was this translation helpful? Give feedback.
All reactions