Skip to content

Commit e259f50

Browse files
authored
feat: add deprecated notices to documentation (#1990)
1 parent 612e046 commit e259f50

File tree

13 files changed

+308
-30
lines changed

13 files changed

+308
-30
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.mobilitydata.gtfsvalidator.notice;
2+
3+
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.INFO;
4+
5+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
6+
7+
/**
8+
* Unused station.
9+
*
10+
* <p>A stop has `location_type` STATION (1) but does not appear in any stop's `parent_station`.
11+
*/
12+
@GtfsValidationNotice(severity = INFO)
13+
public class UnusedStationNotice extends ValidationNotice {
14+
/** The row number of the faulty record. */
15+
private final int csvRowNumber;
16+
17+
/** The id of the faulty stop. */
18+
private final String stopId;
19+
20+
/** The name of the faulty stop. */
21+
private final String stopName;
22+
23+
public UnusedStationNotice(int csvRowNumber, String stopId, String stopName) {
24+
this.csvRowNumber = csvRowNumber;
25+
this.stopId = stopId;
26+
this.stopName = stopName;
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mobilitydata.gtfsvalidator.notice.deprecated;
17+
18+
import static org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.SectionRef.TERM_DEFINITIONS;
19+
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.WARNING;
20+
21+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
22+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.SectionRefs;
23+
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
24+
25+
/** A recommended column is missing in the input file. */
26+
@GtfsValidationNotice(
27+
severity = WARNING,
28+
sections = @SectionRefs(TERM_DEFINITIONS),
29+
deprecated = true,
30+
deprecationVersion = "7.0.0",
31+
deprecationReason = "Unused validation notice")
32+
public class MissingRecommendedColumnNotice extends ValidationNotice {
33+
/** The name of the faulty file. */
34+
private final String filename;
35+
36+
/** The name of the missing column. */
37+
private final String fieldName;
38+
39+
public MissingRecommendedColumnNotice(String filename, String fieldName) {
40+
this.filename = filename;
41+
this.fieldName = fieldName;
42+
}
43+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.mobilitydata.gtfsvalidator.notice.deprecated;
2+
3+
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.INFO;
4+
5+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
6+
import org.mobilitydata.gtfsvalidator.notice.UnusedStationNotice;
7+
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
8+
9+
/**
10+
* Unused parent station.
11+
*
12+
* <p>A stop has `location_type` STATION (1) but does not appear in any stop's `parent_station`.
13+
*/
14+
@GtfsValidationNotice(
15+
severity = INFO,
16+
deprecated = true,
17+
deprecationVersion = "7.0.0",
18+
deprecationReason = "Renamed to `unused_station`",
19+
replacementNotice = UnusedStationNotice.class)
20+
class UnusedParentStationNotice extends ValidationNotice {
21+
/** The row number of the faulty record. */
22+
private final int csvRowNumber;
23+
24+
/** The id of the faulty stop. */
25+
private final String stopId;
26+
27+
/** The name of the faulty stop. */
28+
private final String stopName;
29+
30+
UnusedParentStationNotice(int csvRowNumber, String stopId, String stopName) {
31+
this.csvRowNumber = csvRowNumber;
32+
this.stopId = stopId;
33+
this.stopName = stopName;
34+
}
35+
}

core/src/main/java/org/mobilitydata/gtfsvalidator/notice/schema/NoticeSchema.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ public class NoticeSchema {
3838
*/
3939
private Map<String, FieldSchema> properties = new TreeMap<>();
4040

41+
/**
42+
* Whether the notice is deprecated. Deprecated notices are not used in the validator, but are
43+
* still supported in the documentation.
44+
*/
45+
private boolean deprecated = false;
46+
47+
/**
48+
* Reason for the deprecation of the notice. This field is only used if {@link #deprecated} is
49+
* true.
50+
*/
51+
@Nullable private String deprecationReason;
52+
53+
/**
54+
* Version on which the notice was deprecated. This field is only used if {@link #deprecated} is
55+
* true.
56+
*/
57+
@Nullable private String deprecationVersion;
58+
59+
/**
60+
* Replacement notice code for the deprecated notice. This field is only used if {@link
61+
* #deprecated} is true and the notice has a replacement.
62+
*/
63+
@Nullable private String replacementNoticeCode;
64+
4165
public NoticeSchema(String code, SeverityLevel severityLevel) {
4266
this.code = code;
4367
this.severityLevel = severityLevel;
@@ -83,4 +107,39 @@ public void addField(FieldSchema field) {
83107
public Map<String, FieldSchema> getFields() {
84108
return properties;
85109
}
110+
111+
public boolean isDeprecated() {
112+
return deprecated;
113+
}
114+
115+
public void setDeprecated(boolean deprecated) {
116+
this.deprecated = deprecated;
117+
}
118+
119+
@Nullable
120+
public String getDeprecationReason() {
121+
return deprecationReason;
122+
}
123+
124+
public void setDeprecationReason(@Nullable String deprecationReason) {
125+
this.deprecationReason = deprecationReason;
126+
}
127+
128+
@Nullable
129+
public String getDeprecationVersion() {
130+
return deprecationVersion;
131+
}
132+
133+
public void setDeprecationVersion(@Nullable String deprecationVersion) {
134+
this.deprecationVersion = deprecationVersion;
135+
}
136+
137+
@Nullable
138+
public String getReplacementNoticeCode() {
139+
return replacementNoticeCode;
140+
}
141+
142+
public void setReplacementNoticeCode(@Nullable String replacementNoticeCode) {
143+
this.replacementNoticeCode = replacementNoticeCode;
144+
}
86145
}

core/src/main/java/org/mobilitydata/gtfsvalidator/notice/schema/NoticeSchemaGenerator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.mobilitydata.gtfsvalidator.notice.Notice;
4141
import org.mobilitydata.gtfsvalidator.notice.NoticeDocComments;
4242
import org.mobilitydata.gtfsvalidator.notice.SeverityLevel;
43+
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
4344
import org.mobilitydata.gtfsvalidator.notice.schema.ReferencesSchema.UrlReference;
4445
import org.mobilitydata.gtfsvalidator.table.GtfsEntity;
4546
import org.mobilitydata.gtfsvalidator.table.GtfsEnum;
@@ -82,6 +83,21 @@ static NoticeSchema generateSchemaForNotice(Class<? extends Notice> noticeClass)
8283

8384
NoticeSchema schema = new NoticeSchema(Notice.getCode(noticeClass), severity);
8485

86+
if (noticeAnnotation != null) {
87+
if (noticeAnnotation.deprecated()) {
88+
schema.setDeprecated(true);
89+
schema.setDeprecationReason(noticeAnnotation.deprecationReason());
90+
schema.setDeprecationVersion(noticeAnnotation.deprecationVersion());
91+
// Validate that replacement notice is not Void.class and that it extends ValidationNotice
92+
if (noticeAnnotation.replacementNotice() != Void.class
93+
&& ValidationNotice.class.isAssignableFrom(noticeAnnotation.replacementNotice())) {
94+
String replacementNoticeCode =
95+
Notice.getCode(noticeAnnotation.replacementNotice().asSubclass(Notice.class));
96+
schema.setReplacementNoticeCode(replacementNoticeCode);
97+
}
98+
}
99+
}
100+
85101
NoticeDocComments comments = loadComments(noticeClass);
86102
if (comments.getShortSummary() != null) {
87103
schema.setShortSummary(comments.getShortSummary());

core/src/test/resources/org/mobilitydata/gtfsvalidator/notice/schema/NoticeSchemaGeneratorTest-generateJsonSchemaForNotice_duplicateKeyNotice.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@
5353
"description": "The row of the first occurrence.",
5454
"type": "integer"
5555
}
56-
}
56+
},
57+
"deprecated": false
5758
}

core/src/test/resources/org/mobilitydata/gtfsvalidator/notice/schema/NoticeSchemaGeneratorTest-generateJsonSchemaForNotice_s2LatLngNotice.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"minItems": 2,
1313
"maxItems": 2
1414
}
15-
}
15+
},
16+
"deprecated": false
1617
}

main/src/main/java/org/mobilitydata/gtfsvalidator/validator/ParentStationValidator.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.mobilitydata.gtfsvalidator.validator;
1717

1818
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;
19-
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.INFO;
2019

2120
import java.util.HashSet;
2221
import java.util.Optional;
@@ -26,6 +25,7 @@
2625
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs;
2726
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
2827
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
28+
import org.mobilitydata.gtfsvalidator.notice.UnusedStationNotice;
2929
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
3030
import org.mobilitydata.gtfsvalidator.table.GtfsLocationType;
3131
import org.mobilitydata.gtfsvalidator.table.GtfsStop;
@@ -188,27 +188,4 @@ static class WrongParentLocationTypeNotice extends ValidationNotice {
188188
this.expectedLocationType = expectedLocationType;
189189
}
190190
}
191-
192-
/**
193-
* Unused station.
194-
*
195-
* <p>A stop has `location_type` STATION (1) but does not appear in any stop's `parent_station`.
196-
*/
197-
@GtfsValidationNotice(severity = INFO, files = @FileRefs({GtfsStopSchema.class}))
198-
static class UnusedStationNotice extends ValidationNotice {
199-
/** The row number of the faulty record. */
200-
private final int csvRowNumber;
201-
202-
/** The id of the faulty stop. */
203-
private final String stopId;
204-
205-
/** The name of the faulty stop. */
206-
private final String stopName;
207-
208-
UnusedStationNotice(int csvRowNumber, String stopId, String stopName) {
209-
this.csvRowNumber = csvRowNumber;
210-
this.stopId = stopId;
211-
this.stopName = stopName;
212-
}
213-
}
214191
}

main/src/test/java/org/mobilitydata/gtfsvalidator/validator/ParentStationValidatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import org.junit.runner.RunWith;
2525
import org.junit.runners.JUnit4;
2626
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
27+
import org.mobilitydata.gtfsvalidator.notice.UnusedStationNotice;
2728
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
2829
import org.mobilitydata.gtfsvalidator.table.GtfsLocationType;
2930
import org.mobilitydata.gtfsvalidator.table.GtfsStop;
3031
import org.mobilitydata.gtfsvalidator.table.GtfsStopTableContainer;
31-
import org.mobilitydata.gtfsvalidator.validator.ParentStationValidator.UnusedStationNotice;
3232
import org.mobilitydata.gtfsvalidator.validator.ParentStationValidator.WrongParentLocationTypeNotice;
3333

3434
@RunWith(JUnit4.class)

model/src/main/java/org/mobilitydata/gtfsvalidator/annotation/GtfsValidationNotice.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@
2121
*/
2222
SeverityLevel severity();
2323

24+
/**
25+
* Whether the notice is deprecated. Deprecated notices are still supported in the documentation
26+
* but are not actively used in validation.
27+
*/
28+
boolean deprecated() default false;
29+
30+
/**
31+
* Reason for the deprecation of the notice. This field is only used if {@link #deprecated()} is
32+
* true.
33+
*/
34+
String deprecationReason() default "";
35+
36+
/**
37+
* Version on which the notice was deprecated. This field is only used if {@link #deprecated()} is
38+
* true.
39+
*/
40+
String deprecationVersion() default "";
41+
42+
/**
43+
* Replacement notice class for the deprecated notice. This field is only used if {@link
44+
* #deprecated()} is true and the notice has a replacement.
45+
*/
46+
Class<?> replacementNotice() default Void.class;
47+
2448
/**
2549
* GTFS specification section references. For specific file references, use {@link #files()}
2650
* instead.

0 commit comments

Comments
 (0)