Skip to content

Commit

Permalink
Do not inline non-primitive type parameters by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Le Roux committed Nov 4, 2024
1 parent a792520 commit 872f17c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions utoipa-gen/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,17 @@ impl ComponentSchema {

schema.to_tokens(tokens);
} else {
let index = container.generics.get_generic_type_param_index(type_tree);
// only set schema references tokens for concrete non generic types
let schema_type = SchemaType {
path: Cow::Borrowed(&rewritten_path),
nullable,
};
let index = if schema_type.is_primitive() {
container.generics.get_generic_type_param_index(type_tree)
} else {
None
};

// forcibly inline primitive type parameters, otherwise use references
if index.is_none() {
let reference_tokens = if let Some(children) = &type_tree.children {
let composed_generics = Self::compose_generics(
Expand Down
6 changes: 3 additions & 3 deletions utoipa-gen/tests/openapi_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use assert_json_diff::{assert_json_eq, assert_json_include};
use serde::Serialize;
use serde_json::{json, Value};
use utoipa::{
openapi::{RefOr, Response, ResponseBuilder},
openapi::{schema, RefOr, Response, ResponseBuilder},
OpenApi, ToResponse,
};
use utoipa_gen::ToSchema;
Expand Down Expand Up @@ -560,8 +560,8 @@ fn openapi_schemas_resolve_schema_references() {

#[derive(ToSchema)]
enum Element<T> {
One(T),
Many(Vec<T>),
One(#[schema(inline)] T),
Many(#[schema(inline)] Vec<T>),
}

#[derive(ToSchema)]
Expand Down

0 comments on commit 872f17c

Please sign in to comment.