poem icon indicating copy to clipboard operation
poem copied to clipboard

Generics produce invalid OpenAPI identifiers

Open Eugeny opened this issue 2 years ago • 15 comments

Having a generic type with #[derive(Object)] will produce identifiers like PaginatedResponse<SessionSnapshot> which look nice, but are not valid according to the spec:

Component names can only contain the characters A-Z a-z 0-9 - . _

It would be nicer to allow renaming them at the specialization site with an [oai(rename)], or allow forcing the definition to be inlined in the spec.

Eugeny avatar Jul 17 '22 21:07 Eugeny

It works fine in Swagger UI/Redoc/Rapidoc, maybe some code generation tools don't recognize it. 🙂

sunli829 avatar Jul 18 '22 02:07 sunli829

@sunli829 what's the best workaround? Currently, we use openapi-generator. Getting the same issue as @Eugeny did.

itsbalamurali avatar Jul 22 '22 08:07 itsbalamurali

@sunli829 can we transform for example PaginatedResponse<SessionSnapshot> to PaginatedResponseOfSessionSnapshot?

itsbalamurali avatar Jul 22 '22 08:07 itsbalamurali

Maybe the Object derive macro could also accept an #[oai(generic_name_format="{}<{}>")] and use it to generate the name

Eugeny avatar Jul 22 '22 08:07 Eugeny

Maybe the Object derive macro could also accept an #[oai(generic_name_format="{}<{}>")] and use to generate the name

This looks good 🙂

sunli829 avatar Jul 22 '22 08:07 sunli829

@Eugeny or @sunli829 any plans on landing this sooner?

itsbalamurali avatar Jul 23 '22 11:07 itsbalamurali

Currently the only solution is to avoid using generics. 🙂

sunli829 avatar Aug 01 '22 01:08 sunli829

@Eugeny are you interested in implementing this?

itsbalamurali avatar Aug 02 '22 19:08 itsbalamurali

No, I've already worked around it by just modifying the generated JSON schema in my code.

Eugeny avatar Aug 02 '22 21:08 Eugeny

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 02 '22 03:09 github-actions[bot]

Just pinging to keep the issue alive.

itsbalamurali avatar Sep 06 '22 23:09 itsbalamurali

@sunli829 Do you have some time to look at this?

itsbalamurali avatar Nov 01 '22 17:11 itsbalamurali

This problem can currently only be solved by avoiding the use of generics. 🙂

sunli829 avatar Nov 02 '22 01:11 sunli829

pinging to keep the issue alive.

itsbalamurali avatar Jan 04 '23 20:01 itsbalamurali

ping again :)

balaatsky avatar Jun 23 '23 11:06 balaatsky