Open rxdiscovery opened 8 months ago
Currently it is not possible to customize the OpenAPI name corresponding to a generic type. If you need a legal name, you can only avoid using generics.
I have a proposition, why not take the template ( [{}] ) directly from a global variable, which can be modified?
fn name() -> Cow<'static, str> {
format!("[{}]", T::name()).into()
}
to
fn name() -> Cow<'static, str> {
format!(get_vec_gen_template(), T::name()).into()
}
https://github.com/poem-web/poem/pull/671 implemented a solution for the generics problem, but sadly got no feedback so far.
The current output is non-compliant with the OpenAPI spec, even if SwaggerUI & Co don't complain:
All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9.-_]+$
(https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#components-object)
The problem I see with both your suggestion (Prefix with ListOf
instead of wrapping in brackets) as well as the one in #671 (replace special characters with underscore) is that it might collide with non-generics that use the same name - but IMHO both solutions would be preferable to just not be able to use Generics at all without generating invalid OpenAPI specs.
@sunli829 would you be open to a PR that removes the disallowed characters, and if so, do you have a preference for the format (i.e., replace punctuation with underscores, Prefix with a String like "Of", ...)?
Hello,
@amtelekom if we make the template dynamic so that each developer can customize it only for their needs
I think @sunli829 is so busy lately, it would be nice if he assigned a moderator to help him.
Hello, Poem #[aoi] , must allow you to choose the strategy for generating generic structure names,
Response\ for example, should have the symbol name Reponse_T or ResponseForT or ResponseOfT
and Response\<[T]> => ResponseOfListT for example.
when I want to generate code with the swagger spec using openapi generator, I get this error because the generic names contain special characters :
Response and Response<[City]> will generate the same structure : ResponseCity , ResponseCity, the generated code has no way of differentiating between them.
but if we rename the [City] to ListCity, for example, the result will be : ResponseCity and ResponseListCity
to simplify, here is the part concerned :
transform [T] into ListOfT , because [ and ] characters are not allowed
to
Thanks in advance :1st_place_medal: