Open ahl opened 2 years ago
"title"
can appear at any level of the schema too, and that is actually very convenient because it means one can define type structure separately from schema structure.
I would prefer an implementation that looks for title
first and for definition name second. It just so happens to line up with schema generator jsonschema-gentypes in Python: https://github.com/camptocamp/jsonschema-gentypes
JSON schema gives us two direct sources of types names: the keys in references dictionary and the
title
field in schema metadata. Note also that while the former are necessarily unique, the latter may not be. In addition, we can get hints about names. Consider for example a JSON object that looks like this:The outer object may have a name, but the value of
fooObj
may not (or it may have a title that is not unique). We could include a "distinguishing hint" in these cases which might be the enclosing type and property name, or may come from the external caller e.g. our OpenAPI processor could use theoperationId
.After processing all types, we could choose to always include the distinguishing hint in the name, only include it if it was needed to resolve conflicting types, or raise an error if it as needed to disambiguate conflicting types.
This would require a change in the API which currently is of the form
schemars::schema::Schema -> proc_macro2::TokenStream
i.e. we will no longer be sure of the type name until all schemas have been examined.