@@ -12,15 +12,16 @@ use serde_json::{json, Value};
1212pub struct OpenApiGenerator < ' a > {
1313 schema : & ' a dozer_types:: types:: Schema ,
1414 secondary_indexes : & ' a [ IndexDefinition ] ,
15+ table_name : String ,
1516 endpoint : ApiEndpoint ,
1617 server_host : Vec < String > ,
1718}
1819impl < ' a > OpenApiGenerator < ' a > {
1920 fn get_singular_name ( & self ) -> String {
20- self . endpoint . name . to_string ( )
21+ self . table_name . to_string ( )
2122 }
2223 fn get_plural_name ( & self ) -> String {
23- format ! ( "{}_array" , self . endpoint . name )
24+ format ! ( "{}_array" , self . table_name )
2425 }
2526
2627 // Generate first secondary_index as an example
@@ -80,18 +81,18 @@ impl<'a> OpenApiGenerator<'a> {
8081 let responses = Responses {
8182 responses : indexmap:: indexmap! {
8283 StatusCode :: Code ( 200 ) =>
83- ReferenceOr :: Item ( create_reference_response( format!( "Get by id {}" , self . endpoint . name ) , format!( "#/components/schemas/{}" , self . get_singular_name( ) ) ) )
84+ ReferenceOr :: Item ( create_reference_response( format!( "Get by id {}" , self . table_name ) , format!( "#/components/schemas/{}" , self . get_singular_name( ) ) ) )
8485 } ,
8586 ..Default :: default ( )
8687 } ;
8788 let get_operation = Some ( Operation {
88- tags : vec ! [ format!( "{}" , self . endpoint . name ) ] ,
89+ tags : vec ! [ format!( "{}" , self . table_name ) ] ,
8990 summary : Some ( "Fetch a single document record by primary key" . to_owned ( ) ) ,
9091 description : Some (
9192 "Generated API to fetch a single record. Primary key specified will be used for lookup"
9293 . to_owned ( ) ,
9394 ) ,
94- operation_id : Some ( format ! ( "{}-by-id" , self . endpoint . name ) ) ,
95+ operation_id : Some ( format ! ( "{}-by-id" , self . table_name ) ) ,
9596 parameters : vec ! [ ReferenceOr :: Item ( Parameter :: Path {
9697 parameter_data: ParameterData {
9798 name: "id" . to_owned( ) ,
@@ -123,17 +124,17 @@ impl<'a> OpenApiGenerator<'a> {
123124 fn generate_list_route ( & self ) -> ReferenceOr < PathItem > {
124125 let responses = Responses {
125126 responses : indexmap:: indexmap! {
126- StatusCode :: Code ( 200 ) => ReferenceOr :: Item ( create_reference_response( format!( "A page array of {}" , self . endpoint . name . to_owned( ) ) , format!( "#/components/schemas/{}" , self . get_plural_name( ) ) ) )
127+ StatusCode :: Code ( 200 ) => ReferenceOr :: Item ( create_reference_response( format!( "A page array of {}" , self . table_name . to_owned( ) ) , format!( "#/components/schemas/{}" , self . get_plural_name( ) ) ) )
127128 } ,
128129 ..Default :: default ( )
129130 } ;
130131 let operation = Some ( Operation {
131- tags : vec ! [ format!( "{}" , self . endpoint . name ) ] ,
132+ tags : vec ! [ format!( "{}" , self . table_name ) ] ,
132133 summary : Some ( "Fetch multiple documents in the default sort order" . to_owned ( ) ) ,
133134 description : Some (
134135 "This is used when no filter expression or sort is needed." . to_owned ( ) ,
135136 ) ,
136- operation_id : Some ( format ! ( "list-{}" , self . endpoint . name . to_owned( ) ) ) ,
137+ operation_id : Some ( format ! ( "list-{}" , self . table_name . to_owned( ) ) ) ,
137138 responses,
138139 ..Default :: default ( )
139140 } ) ;
@@ -170,10 +171,10 @@ impl<'a> OpenApiGenerator<'a> {
170171 ..Default :: default ( )
171172 } ;
172173 let operation = Some ( Operation {
173- tags : vec ! [ format!( "{}" , self . endpoint . name ) ] ,
174+ tags : vec ! [ format!( "{}" , self . table_name ) ] ,
174175 summary : Some ( "Count documents based on an expression" . to_string ( ) ) ,
175176 description : Some ( "Count documents based on an expression" . to_string ( ) ) ,
176- operation_id : Some ( format ! ( "count-{}" , self . endpoint . name ) ) ,
177+ operation_id : Some ( format ! ( "count-{}" , self . table_name ) ) ,
177178 request_body : Some ( ReferenceOr :: Item ( request_body) ) ,
178179 responses,
179180 ..Default :: default ( )
@@ -194,17 +195,17 @@ impl<'a> OpenApiGenerator<'a> {
194195 } ;
195196 let responses = Responses {
196197 responses : indexmap:: indexmap! {
197- StatusCode :: Code ( 200 ) => ReferenceOr :: Item ( create_reference_response( format!( "A page array of {}" , self . endpoint . name . to_owned( ) ) , format!( "#/components/schemas/{}" , self . get_plural_name( ) ) ) )
198+ StatusCode :: Code ( 200 ) => ReferenceOr :: Item ( create_reference_response( format!( "A page array of {}" , self . table_name . to_owned( ) ) , format!( "#/components/schemas/{}" , self . get_plural_name( ) ) ) )
198199 } ,
199200 ..Default :: default ( )
200201 } ;
201202 let operation = Some ( Operation {
202- tags : vec ! [ format!( "{}" , self . endpoint . name ) ] ,
203+ tags : vec ! [ format!( "{}" , self . table_name ) ] ,
203204 summary : Some ( "Query documents based on an expression" . to_owned ( ) ) ,
204205 description : Some (
205206 "Documents can be queried based on a simple or a composite expression" . to_owned ( ) ,
206207 ) ,
207- operation_id : Some ( format ! ( "query-{}" , self . endpoint . name ) ) ,
208+ operation_id : Some ( format ! ( "query-{}" , self . table_name ) ) ,
208209 request_body : Some ( ReferenceOr :: Item ( request_body) ) ,
209210 responses,
210211 ..Default :: default ( )
@@ -234,13 +235,13 @@ impl<'a> OpenApiGenerator<'a> {
234235
235236 fn generate_component_schema ( & self ) -> Components {
236237 let generated_schema =
237- convert_cache_to_oapi_schema ( self . schema . to_owned ( ) , & self . endpoint . name ) ;
238+ convert_cache_to_oapi_schema ( self . schema . to_owned ( ) , & self . table_name ) ;
238239
239240 let schemas = indexmap:: indexmap! {
240241 self . get_singular_name( ) => ReferenceOr :: Item ( generated_schema) ,
241242 self . get_plural_name( ) => ReferenceOr :: Item ( Schema {
242243 schema_data: SchemaData {
243- description: Some ( format!( "Array of {}" , & self . endpoint . name ) ) ,
244+ description: Some ( format!( "Array of {}" , & self . table_name ) ) ,
244245 ..Default :: default ( )
245246 } ,
246247 schema_kind: SchemaKind :: Type ( Type :: Array ( ArrayType {
@@ -267,17 +268,17 @@ impl<'a> OpenApiGenerator<'a> {
267268 OpenAPI {
268269 openapi : "3.0.0" . to_owned ( ) ,
269270 info : Info {
270- title : self . endpoint . name . to_uppercase ( ) ,
271+ title : self . table_name . to_uppercase ( ) ,
271272 description : Some ( format ! (
272273 "API documentation for {}. Powered by Dozer Data." ,
273- self . endpoint . name . to_lowercase( )
274+ self . table_name . to_lowercase( )
274275 ) ) ,
275276 version : "1.0.0" . to_owned ( ) ,
276277 contact : create_contact_info ( ) ,
277278 ..Default :: default ( )
278279 } ,
279280 tags : vec ! [ Tag {
280- name: self . endpoint . name . to_string( ) ,
281+ name: self . table_name . to_string( ) ,
281282 ..Default :: default ( )
282283 } ] ,
283284 servers : self
@@ -297,12 +298,14 @@ impl<'a> OpenApiGenerator<'a> {
297298 pub fn new (
298299 schema : & ' a dozer_types:: types:: Schema ,
299300 secondary_indexes : & ' a [ IndexDefinition ] ,
301+ table_name : String ,
300302 endpoint : ApiEndpoint ,
301303 server_host : Vec < String > ,
302304 ) -> Self {
303305 Self {
304306 schema,
305307 secondary_indexes,
308+ table_name,
306309 endpoint,
307310 server_host,
308311 }
0 commit comments