Skip to content

Commit

Permalink
Add docs and tests for aliases (#587)
Browse files Browse the repository at this point in the history
Add docs and tests for aliases with `value_type`.
  • Loading branch information
jayvdb authored Apr 17, 2023
1 parent 0cf37c0 commit 6c89f81
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions utoipa-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ use self::{
/// This is useful in cases where the default type does not correspond to the actual type e.g. when
/// any third-party types are used which are not [`ToSchema`][to_schema]s nor [`primitive` types][primitive].
/// The value can be any Rust type what normally could be used to serialize to JSON or either virtual type _`Object`_
/// or _`Value`.
/// or _`Value`_, or an alias defined using `#[aliases(..)]`.
/// _`Object`_ will be rendered as generic OpenAPI object _(`type: object`)_.
/// _`Value`_ will be rendered as any OpenAPI value (i.e. no `type` restriction).
/// * `title = ...` Literal string value. Can be used to define title for struct in OpenAPI
Expand All @@ -149,7 +149,7 @@ use self::{
/// This is useful in cases where the default type does not correspond to the actual type e.g. when
/// any third-party types are used which are not [`ToSchema`][to_schema]s nor [`primitive` types][primitive].
/// The value can be any Rust type what normally could be used to serialize to JSON, or either virtual type _`Object`_
/// or _`Value`.
/// or _`Value`_, or an alias defined using `#[aliases(..)]`.
/// _`Object`_ will be rendered as generic OpenAPI object _(`type: object`)_.
/// _`Value`_ will be rendered as any OpenAPI value (i.e. no `type` restriction).
/// * `inline` If the type of this field implements [`ToSchema`][to_schema], then the schema definition
Expand Down Expand Up @@ -1650,7 +1650,7 @@ pub fn openapi(input: TokenStream) -> TokenStream {
/// This is useful in cases where the default type does not correspond to the actual type e.g. when
/// any third-party types are used which are not [`ToSchema`][to_schema]s nor [`primitive` types][primitive].
/// The value can be any Rust type what normally could be used to serialize to JSON, or either virtual type _`Object`_
/// or _`Value`.
/// or _`Value`_, or an alias defined using `#[aliases(..)]`.
/// _`Object`_ will be rendered as generic OpenAPI object _(`type: object`)_.
/// _`Value`_ will be rendered as any OpenAPI value (i.e. no `type` restriction).
///
Expand Down
2 changes: 1 addition & 1 deletion utoipa-gen/tests/path_derive_auto_types_actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use actix_web::{get, HttpResponse, Responder, ResponseError};
use assert_json_diff::assert_json_eq;

#[test]
fn path_operation_auto_types_ressponses() {
fn path_operation_auto_types_responses() {
/// Test item to to return
#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
struct Item<'s> {
Expand Down
19 changes: 17 additions & 2 deletions utoipa-gen/tests/schema_derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,7 @@ fn derive_complex_enum_as() {
#[test]
fn derive_component_with_primitive_aliases() {
#[derive(Debug, OpenApi)]
#[openapi(components(schemas(BarString, BarInt)))]
#[openapi(components(schemas(BarString, BarInt, Foo)))]
struct ApiDoc;

#[derive(ToSchema)]
Expand All @@ -3187,6 +3187,12 @@ fn derive_component_with_primitive_aliases() {
#[allow(dead_code)]
bar: R,
}
#[derive(ToSchema)]
struct Foo {
#[allow(dead_code)]
#[schema(value_type=BarString)]
baz: Bar<String>,
}

let doc = ApiDoc::openapi();
let doc_value = &serde_json::to_value(doc).unwrap();
Expand Down Expand Up @@ -3214,9 +3220,18 @@ fn derive_component_with_primitive_aliases() {
},
"type": "object",
"required": ["bar"]
},
"Foo": {
"properties": {
"baz": {
"$ref": "#/components/schemas/BarString",
}
},
"type": "object",
"required": ["baz"]
}
})
)
);
}

#[test]
Expand Down

0 comments on commit 6c89f81

Please sign in to comment.