@@ -77,12 +77,13 @@ private record ParsedFeedContainer(
7777 "station_status" ,
7878 "free_bike_status" ,
7979 "vehicle_status" ,
80+ "vehicle_availability" ,
81+ "manifest" ,
8082 "system_hours" ,
81- "system_alerts" ,
82- "system_alerts" ,
8383 "system_calendar" ,
8484 "system_regions" ,
8585 "system_pricing_plans" ,
86+ "system_alerts" ,
8687 "geofencing_zones"
8788 );
8889
@@ -110,17 +111,10 @@ public ValidationResult validate(Map<String, InputStream> rawFeeds) {
110111 }
111112
112113 if (parsedContainer .jsonObject () == null ) {
113- // Parsing failed or stream read error
114- FileValidationResult result = new FileValidationResult (
114+ FileValidationResult result = createParsingErrorResult (
115115 feedName ,
116- version .isFileRequired (feedName ),
117- true ,
118- 0 ,
119- version .getSchema (feedName ).toString (),
120- parsedContainer .originalContent (),
121- null ,
122- Collections .emptyList (),
123- parsedContainer .parsingErrors ()
116+ parsedContainer ,
117+ version
124118 );
125119 fileValidations .put (feedName , result );
126120 } else {
@@ -183,19 +177,10 @@ public FileValidationResult validateFile(String fileName, InputStream file) {
183177 ParsedFeedContainer parsedContainer = parseFeed (fileName , file );
184178
185179 if (parsedContainer .jsonObject () == null ) {
186- // Determine version for schema and requirement - this is tricky for a single file
187- // For now, using default version. A more robust approach might require context.
188- Version tempVersion = VersionFactory .createVersion (DEFAULT_VERSION );
189- return new FileValidationResult (
180+ return createParsingErrorResult (
190181 fileName ,
191- tempVersion .isFileRequired (fileName ),
192- true , // File was provided
193- 0 ,
194- tempVersion .getSchema (fileName ).toString (),
195- parsedContainer .originalContent (),
196- null , // File specific version unknown
197- Collections .emptyList (),
198- parsedContainer .parsingErrors ()
182+ parsedContainer ,
183+ VersionFactory .createVersion (DEFAULT_VERSION )
199184 );
200185 } else {
201186 return validateFile (
@@ -350,4 +335,58 @@ private ParsedFeedContainer parseFeed(String name, InputStream raw) {
350335 );
351336 }
352337 }
338+
339+ /**
340+ * Creates a validation result for a file that could not be parsed. Parsing can fail before
341+ * the exact version for a single file is known, so this resolves the best schema version
342+ * available and still returns file metadata alongside the parse errors.
343+ *
344+ * @param feedName The GBFS feed name
345+ * @param parsedContainer The parsed container holding original content and parse errors
346+ * @param preferredVersion The initially preferred GBFS version
347+ * @return A file validation result containing parse errors and any schema metadata that could be resolved
348+ */
349+ private FileValidationResult createParsingErrorResult (
350+ String feedName ,
351+ ParsedFeedContainer parsedContainer ,
352+ Version preferredVersion
353+ ) {
354+ Version schemaVersion = resolveVersionForFeed (feedName , preferredVersion );
355+ boolean supportedFeed = schemaVersion .getFileNames ().contains (feedName );
356+
357+ return new FileValidationResult (
358+ feedName ,
359+ supportedFeed && schemaVersion .isFileRequired (feedName ),
360+ true ,
361+ 0 ,
362+ supportedFeed ? schemaVersion .getSchema (feedName ).toString () : null ,
363+ parsedContainer .originalContent (),
364+ null ,
365+ Collections .emptyList (),
366+ parsedContainer .parsingErrors ()
367+ );
368+ }
369+
370+ /**
371+ * Resolves the version to use for a feed when building parse-error results. Some feed types
372+ * may not exist in the initially detected version, so this falls back to the newest version
373+ * that supports the feed in order to point the error result at a schema when possible.
374+ *
375+ * @param feedName The GBFS feed name
376+ * @param preferredVersion The initially detected or preferred GBFS version
377+ * @return The preferred version when it supports the feed, otherwise the newest version that does
378+ */
379+ private Version resolveVersionForFeed (
380+ String feedName ,
381+ Version preferredVersion
382+ ) {
383+ if (preferredVersion .getFileNames ().contains (feedName )) {
384+ return preferredVersion ;
385+ }
386+
387+ return VersionFactory .createLatestVersionSupportingFeed (
388+ feedName ,
389+ preferredVersion .getVersionString ()
390+ );
391+ }
353392}
0 commit comments