11use std:: {
22 collections:: HashMap ,
33 fmt:: { self , Display , Formatter } ,
4- ops:: Deref ,
54} ;
65
76use chrono:: { DateTime , Utc } ;
@@ -149,7 +148,7 @@ impl Display for DelphiReportListOrder {
149148pub struct DelphiReportIssueResult {
150149 pub issue : DBDelphiReportIssue ,
151150 pub report : DBDelphiReport ,
152- pub details : Vec < DBDelphiReportIssueDetails > ,
151+ pub details : Vec < ReportIssueDetail > ,
153152 pub project_id : Option < DBProjectId > ,
154153 pub project_published : Option < DateTime < Utc > > ,
155154}
@@ -195,7 +194,7 @@ impl DBDelphiReportIssue {
195194 json_array(SELECT to_jsonb(delphi_report_issue_details)
196195 FROM delphi_report_issue_details
197196 WHERE issue_id = delphi_report_issues.id
198- ) AS "details: sqlx::types::Json<Vec<DBDelphiReportIssueDetails >>",
197+ ) AS "details: sqlx::types::Json<Vec<ReportIssueDetail >>",
199198 versions.mod_id AS "project_id?", mods.published AS "project_published?"
200199 FROM delphi_report_issues
201200 INNER JOIN delphi_reports ON delphi_reports.id = report_id
@@ -253,18 +252,32 @@ impl DBDelphiReportIssue {
253252/// belongs to a specific issue, and an issue can have zero, one, or
254253/// more details attached to it. (Some issues may be artifact-wide,
255254/// or otherwise not really specific to any particular class.)
256- #[ derive( Debug , Deserialize , Serialize ) ]
257- pub struct DBDelphiReportIssueDetails {
255+ #[ derive(
256+ Debug , Clone , Deserialize , Serialize , utoipa:: ToSchema , sqlx:: FromRow ,
257+ ) ]
258+ pub struct ReportIssueDetail {
259+ /// ID of this issue detail.
258260 pub id : DelphiReportIssueDetailsId ,
259- pub key : String ,
261+ /// ID of the issue this detail belongs to.
260262 pub issue_id : DelphiReportIssueId ,
263+ /// Opaque identifier for where this issue detail is located, relative to
264+ /// the file scanned.
265+ ///
266+ /// This acts as a stable identifier for an issue detail, even across
267+ /// different versions of the same file.
268+ pub key : String ,
269+ /// Name of the Java class path in which this issue was found.
261270 pub file_path : String ,
262- pub decompiled_source : Option < DecompiledJavaClassSource > ,
263- pub data : Json < HashMap < String , serde_json:: Value > > ,
271+ /// Decompiled, pretty-printed source of the Java class.
272+ pub decompiled_source : Option < String > ,
273+ /// Extra detail-specific info for this detail.
274+ #[ sqlx( json) ]
275+ pub data : HashMap < String , serde_json:: Value > ,
276+ /// How important is this issue, as flagged by Delphi?
264277 pub severity : DelphiSeverity ,
265278}
266279
267- impl DBDelphiReportIssueDetails {
280+ impl ReportIssueDetail {
268281 pub async fn insert (
269282 & self ,
270283 transaction : & mut sqlx:: Transaction < ' _ , sqlx:: Postgres > ,
@@ -278,8 +291,8 @@ impl DBDelphiReportIssueDetails {
278291 self . issue_id as DelphiReportIssueId ,
279292 self . key,
280293 self . file_path,
281- self . decompiled_source. as_ref ( ) . map ( |decompiled_source| & decompiled_source . 0 ) ,
282- & self . data as & Json <HashMap <String , serde_json:: Value >>,
294+ self . decompiled_source,
295+ sqlx :: types :: Json ( & self . data) as Json <& HashMap <String , serde_json:: Value >>,
283296 self . severity as DelphiSeverity ,
284297 )
285298 . fetch_one ( & mut * * transaction)
@@ -299,55 +312,3 @@ impl DBDelphiReportIssueDetails {
299312 . rows_affected ( ) )
300313 }
301314}
302-
303- /// A [Java class name] with dots replaced by forward slashes (/).
304- ///
305- /// Because class names are usually the [binary names] passed to a classloader, top level interfaces and classes
306- /// have a binary name that matches its canonical, fully qualified name, such canonical names are prefixed by the
307- /// package path the class is in, and packages usually match the directory structure within a JAR for typical
308- /// classloaders, this usually (but not necessarily) corresponds to the path to the class file within its JAR.
309- ///
310- /// [Java class name]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Class.html#getName()
311- /// [binary names]: https://docs.oracle.com/javase/specs/jls/se21/html/jls-13.html#jls-13.1
312- #[ derive(
313- Deserialize , Serialize , Debug , Clone , PartialEq , Eq , Hash , sqlx:: Type ,
314- ) ]
315- #[ serde( transparent) ]
316- #[ sqlx( transparent) ]
317- pub struct InternalJavaClassName ( String ) ;
318-
319- impl Deref for InternalJavaClassName {
320- type Target = String ;
321-
322- fn deref ( & self ) -> & Self :: Target {
323- & self . 0
324- }
325- }
326-
327- impl Display for InternalJavaClassName {
328- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
329- write ! ( f, "{}" , self . 0 )
330- }
331- }
332-
333- /// The decompiled source code of a Java class.
334- #[ derive(
335- Deserialize , Serialize , Debug , Clone , PartialEq , Eq , Hash , sqlx:: Type ,
336- ) ]
337- #[ serde( transparent) ]
338- #[ sqlx( transparent) ]
339- pub struct DecompiledJavaClassSource ( String ) ;
340-
341- impl Deref for DecompiledJavaClassSource {
342- type Target = String ;
343-
344- fn deref ( & self ) -> & Self :: Target {
345- & self . 0
346- }
347- }
348-
349- impl Display for DecompiledJavaClassSource {
350- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
351- write ! ( f, "{}" , self . 0 )
352- }
353- }
0 commit comments