@@ -2,12 +2,16 @@ use actix_web::middleware::Logger;
2
2
use actix_web:: web:: { Json , Path } ;
3
3
use actix_web:: { App , Error } ;
4
4
5
+ use actix_web:: test:: { call_service, init_service, try_read_body_json, TestRequest } ;
5
6
use apistos:: app:: OpenApiWrapper ;
6
7
use apistos:: spec:: Spec ;
7
8
use apistos:: web:: { delete, get, patch, post, put, resource, scope, tagged_resource, tagged_scope, ServiceConfig } ;
8
- use apistos_gen:: api_operation;
9
+ use apistos_gen:: { api_operation, ApiComponent } ;
9
10
use apistos_models:: info:: Info ;
10
11
use apistos_models:: tag:: Tag ;
12
+ use apistos_models:: OpenApi ;
13
+ use schemars:: JsonSchema ;
14
+ use serde:: Serialize ;
11
15
12
16
#[ actix_web:: test]
13
17
async fn actix_routing ( ) {
@@ -97,12 +101,79 @@ async fn actix_routing() {
97
101
) ;
98
102
}
99
103
104
+ #[ actix_web:: test]
105
+ async fn actix_routing_multiple_root_definition_holder ( ) {
106
+ #[ derive( ApiComponent , JsonSchema , Serialize ) ]
107
+ pub ( crate ) struct TestResponse {
108
+ pub ( crate ) value : String ,
109
+ }
110
+
111
+ #[ derive( ApiComponent , JsonSchema , Serialize ) ]
112
+ pub ( crate ) struct TestResponse2 {
113
+ pub ( crate ) value : String ,
114
+ }
115
+
116
+ #[ api_operation( tag = "pet" ) ]
117
+ pub ( crate ) async fn test ( _params : Path < ( u32 , String ) > ) -> Result < Json < TestResponse > , Error > {
118
+ Ok ( Json ( TestResponse {
119
+ value : "plop" . to_string ( ) ,
120
+ } ) )
121
+ }
122
+
123
+ #[ api_operation( tag = "pet" ) ]
124
+ pub ( crate ) async fn test2 ( _params : Path < String > ) -> Result < Json < TestResponse2 > , Error > {
125
+ Ok ( Json ( TestResponse2 {
126
+ value : "plop" . to_string ( ) ,
127
+ } ) )
128
+ }
129
+
130
+ let info = Info {
131
+ title : "A well documented API" . to_string ( ) ,
132
+ description : Some ( "Really well document I mean it" . to_string ( ) ) ,
133
+ terms_of_service : Some ( "https://terms.com" . to_string ( ) ) ,
134
+ ..Default :: default ( )
135
+ } ;
136
+ let tags = vec ! [
137
+ Tag {
138
+ name: "pet" . to_owned( ) ,
139
+ ..Default :: default ( )
140
+ } ,
141
+ Tag {
142
+ name: "A super tag" . to_owned( ) ,
143
+ ..Default :: default ( )
144
+ } ,
145
+ Tag {
146
+ name: "Another super tag" . to_owned( ) ,
147
+ ..Default :: default ( )
148
+ } ,
149
+ ] ;
150
+ let spec = Spec {
151
+ info : info. clone ( ) ,
152
+ tags : tags. clone ( ) ,
153
+ ..Default :: default ( )
154
+ } ;
155
+
156
+ let app = App :: new ( )
157
+ . document ( spec)
158
+ . service ( scope ( "test" ) . service ( resource ( "/{plop_id}/{clap_name}" ) . route ( get ( ) . to ( test) ) ) )
159
+ . service ( scope ( "test2" ) . service ( resource ( "/{clap_name}" ) . route ( get ( ) . to ( test2) ) ) )
160
+ . build ( "/openapi.json" ) ;
161
+ let app = init_service ( app) . await ;
162
+
163
+ let req = TestRequest :: get ( ) . uri ( "/openapi.json" ) . to_request ( ) ;
164
+ let resp = call_service ( & app, req) . await ;
165
+ assert ! ( resp. status( ) . is_success( ) ) ;
166
+
167
+ let body: OpenApi = try_read_body_json ( resp) . await . expect ( "Unable to read body" ) ;
168
+ let components = body. components . expect ( "Unable to get components" ) ;
169
+
170
+ assert_eq ! ( components. schemas. len( ) , 2 ) ;
171
+ }
172
+
100
173
// Imports bellow aim at making clippy happy. Those dependencies are necessary for integration-test.
101
174
use actix_service as _;
102
- use actix_web:: test:: { call_service, init_service, try_read_body_json, TestRequest } ;
103
175
use actix_web_lab as _;
104
176
use apistos_core as _;
105
- use apistos_models:: OpenApi ;
106
177
use apistos_plugins as _;
107
178
use apistos_rapidoc as _;
108
179
use apistos_redoc as _;
@@ -115,6 +186,4 @@ use log as _;
115
186
use md5 as _;
116
187
use once_cell as _;
117
188
use regex as _;
118
- use schemars as _;
119
- use serde as _;
120
189
use serde_json as _;
0 commit comments