@@ -86,7 +86,7 @@ enum AstModelLoader {
8686 TYPE , "version" , "operations" , "resources" , TRAITS );
8787
8888 void load (ObjectNode model , LoaderVisitor visitor ) {
89- model . expectNoAdditionalProperties ( TOP_LEVEL_PROPERTIES );
89+ visitor . checkForAdditionalProperties ( model , null , TOP_LEVEL_PROPERTIES );
9090 loadMetadata (model , visitor );
9191 loadShapes (model , visitor );
9292 }
@@ -185,7 +185,7 @@ private void loadShape(ShapeId id, String type, ObjectNode value, LoaderVisitor
185185 loadOperation (id , value , visitor );
186186 break ;
187187 case "apply" :
188- value . expectNoAdditionalProperties ( APPLY_PROPERTIES );
188+ visitor . checkForAdditionalProperties ( value , id , APPLY_PROPERTIES );
189189 applyTraits (id , value .expectObjectMember (TRAITS ), visitor );
190190 break ;
191191 default :
@@ -205,7 +205,7 @@ private void applyShapeTraits(ShapeId id, ObjectNode node, LoaderVisitor visitor
205205 }
206206
207207 private void loadMember (LoaderVisitor visitor , ShapeId id , ObjectNode targetNode ) {
208- targetNode . expectNoAdditionalProperties ( MEMBER_PROPERTIES );
208+ visitor . checkForAdditionalProperties ( targetNode , id , MEMBER_PROPERTIES );
209209 MemberShape .Builder builder = MemberShape .builder ().source (targetNode .getSourceLocation ()).id (id );
210210 ShapeId target = targetNode .expectStringMember (TARGET ).expectShapeId ();
211211 builder .target (target );
@@ -219,52 +219,52 @@ private void loadCollection(
219219 CollectionShape .Builder builder ,
220220 LoaderVisitor visitor
221221 ) {
222- node . expectNoAdditionalProperties ( COLLECTION_PROPERTY_NAMES );
222+ visitor . checkForAdditionalProperties ( node , id , COLLECTION_PROPERTY_NAMES );
223223 applyShapeTraits (id , node , visitor );
224224 loadMember (visitor , id .withMember ("member" ), node .expectObjectMember ("member" ));
225225 visitor .onShape (builder .id (id ).source (node .getSourceLocation ()));
226226 }
227227
228228 private void loadMap (ShapeId id , ObjectNode node , LoaderVisitor visitor ) {
229- node . expectNoAdditionalProperties ( MAP_PROPERTY_NAMES );
229+ visitor . checkForAdditionalProperties ( node , id , MAP_PROPERTY_NAMES );
230230 loadMember (visitor , id .withMember ("key" ), node .expectObjectMember ("key" ));
231231 loadMember (visitor , id .withMember ("value" ), node .expectObjectMember ("value" ));
232232 applyShapeTraits (id , node , visitor );
233233 visitor .onShape (MapShape .builder ().id (id ).source (node .getSourceLocation ()));
234234 }
235235
236- private void loadOperation (ShapeId operationShapeId , ObjectNode node , LoaderVisitor visitor ) {
237- node . expectNoAdditionalProperties ( OPERATION_PROPERTY_NAMES );
238- applyShapeTraits (operationShapeId , node , visitor );
236+ private void loadOperation (ShapeId id , ObjectNode node , LoaderVisitor visitor ) {
237+ visitor . checkForAdditionalProperties ( node , id , OPERATION_PROPERTY_NAMES );
238+ applyShapeTraits (id , node , visitor );
239239 OperationShape .Builder builder = OperationShape .builder ()
240- .id (operationShapeId )
240+ .id (id )
241241 .source (node .getSourceLocation ())
242- .addErrors (loadOptionalTargetList (node , "errors" ));
242+ .addErrors (loadOptionalTargetList (visitor , id , node , "errors" ));
243243
244- loadOptionalTarget (node , "input" ).ifPresent (builder ::input );
245- loadOptionalTarget (node , "output" ).ifPresent (builder ::output );
244+ loadOptionalTarget (visitor , id , node , "input" ).ifPresent (builder ::input );
245+ loadOptionalTarget (visitor , id , node , "output" ).ifPresent (builder ::output );
246246 visitor .onShape (builder );
247247 }
248248
249249 private void loadResource (ShapeId id , ObjectNode node , LoaderVisitor visitor ) {
250- node . expectNoAdditionalProperties ( RESOURCE_PROPERTIES );
250+ visitor . checkForAdditionalProperties ( node , id , RESOURCE_PROPERTIES );
251251 applyShapeTraits (id , node , visitor );
252252 ResourceShape .Builder builder = ResourceShape .builder ().id (id ).source (node .getSourceLocation ());
253- loadOptionalTarget (node , "put" ).ifPresent (builder ::put );
254- loadOptionalTarget (node , "create" ).ifPresent (builder ::create );
255- loadOptionalTarget (node , "read" ).ifPresent (builder ::read );
256- loadOptionalTarget (node , "update" ).ifPresent (builder ::update );
257- loadOptionalTarget (node , "delete" ).ifPresent (builder ::delete );
258- loadOptionalTarget (node , "list" ).ifPresent (builder ::list );
259- builder .operations (loadOptionalTargetList (node , "operations" ));
260- builder .collectionOperations (loadOptionalTargetList (node , "collectionOperations" ));
261- builder .resources (loadOptionalTargetList (node , "resources" ));
253+ loadOptionalTarget (visitor , id , node , "put" ).ifPresent (builder ::put );
254+ loadOptionalTarget (visitor , id , node , "create" ).ifPresent (builder ::create );
255+ loadOptionalTarget (visitor , id , node , "read" ).ifPresent (builder ::read );
256+ loadOptionalTarget (visitor , id , node , "update" ).ifPresent (builder ::update );
257+ loadOptionalTarget (visitor , id , node , "delete" ).ifPresent (builder ::delete );
258+ loadOptionalTarget (visitor , id , node , "list" ).ifPresent (builder ::list );
259+ builder .operations (loadOptionalTargetList (visitor , id , node , "operations" ));
260+ builder .collectionOperations (loadOptionalTargetList (visitor , id , node , "collectionOperations" ));
261+ builder .resources (loadOptionalTargetList (visitor , id , node , "resources" ));
262262
263263 // Load identifiers and resolve forward references.
264264 node .getObjectMember ("identifiers" ).ifPresent (ids -> {
265265 for (Map .Entry <StringNode , Node > entry : ids .getMembers ().entrySet ()) {
266266 String name = entry .getKey ().getValue ();
267- ShapeId target = loadReferenceBody (entry .getValue ());
267+ ShapeId target = loadReferenceBody (visitor , id , entry .getValue ());
268268 builder .addIdentifier (name , target );
269269 }
270270 });
@@ -273,30 +273,30 @@ private void loadResource(ShapeId id, ObjectNode node, LoaderVisitor visitor) {
273273 }
274274
275275 private void loadService (ShapeId id , ObjectNode node , LoaderVisitor visitor ) {
276- node . expectNoAdditionalProperties ( SERVICE_PROPERTIES );
276+ visitor . checkForAdditionalProperties ( node , id , SERVICE_PROPERTIES );
277277 applyShapeTraits (id , node , visitor );
278278 ServiceShape .Builder builder = new ServiceShape .Builder ().id (id ).source (node .getSourceLocation ());
279279 builder .version (node .expectStringMember ("version" ).getValue ());
280- builder .operations (loadOptionalTargetList (node , "operations" ));
281- builder .resources (loadOptionalTargetList (node , "resources" ));
280+ builder .operations (loadOptionalTargetList (visitor , id , node , "operations" ));
281+ builder .resources (loadOptionalTargetList (visitor , id , node , "resources" ));
282282 visitor .onShape (builder );
283283 }
284284
285285 private void loadSimpleShape (
286286 ShapeId id , ObjectNode node , AbstractShapeBuilder builder , LoaderVisitor visitor ) {
287- node . expectNoAdditionalProperties ( SIMPLE_PROPERTY_NAMES );
287+ visitor . checkForAdditionalProperties ( node , id , SIMPLE_PROPERTY_NAMES );
288288 applyShapeTraits (id , node , visitor );
289289 visitor .onShape (builder .id (id ).source (node .getSourceLocation ()));
290290 }
291291
292292 private void loadStructure (ShapeId id , ObjectNode node , LoaderVisitor visitor ) {
293- node . expectNoAdditionalProperties ( STRUCTURE_AND_UNION_PROPERTY_NAMES );
293+ visitor . checkForAdditionalProperties ( node , id , STRUCTURE_AND_UNION_PROPERTY_NAMES );
294294 visitor .onShape (StructureShape .builder ().id (id ).source (node .getSourceLocation ()));
295295 finishLoadingStructOrUnionMembers (id , node , visitor );
296296 }
297297
298298 private void loadUnion (ShapeId id , ObjectNode node , LoaderVisitor visitor ) {
299- node . expectNoAdditionalProperties ( STRUCTURE_AND_UNION_PROPERTY_NAMES );
299+ visitor . checkForAdditionalProperties ( node , id , STRUCTURE_AND_UNION_PROPERTY_NAMES );
300300 visitor .onShape (UnionShape .builder ().id (id ).source (node .getSourceLocation ()));
301301 finishLoadingStructOrUnionMembers (id , node , visitor );
302302 }
@@ -309,20 +309,22 @@ private void finishLoadingStructOrUnionMembers(ShapeId id, ObjectNode node, Load
309309 }
310310 }
311311
312- private Optional <ShapeId > loadOptionalTarget (ObjectNode node , String member ) {
313- return node .getObjectMember (member ).map (this ::loadReferenceBody );
312+ private Optional <ShapeId > loadOptionalTarget (
313+ LoaderVisitor visitor , ShapeId id , ObjectNode node , String member ) {
314+ return node .getObjectMember (member ).map (r -> loadReferenceBody (visitor , id , r ));
314315 }
315316
316- private ShapeId loadReferenceBody (Node reference ) {
317+ private ShapeId loadReferenceBody (LoaderVisitor visitor , ShapeId id , Node reference ) {
317318 ObjectNode referenceObject = reference .expectObjectNode ();
318- referenceObject . expectNoAdditionalProperties ( REFERENCE_PROPERTIES );
319+ visitor . checkForAdditionalProperties ( referenceObject , id , REFERENCE_PROPERTIES );
319320 return referenceObject .expectStringMember (TARGET ).expectShapeId ();
320321 }
321322
322- private List <ShapeId > loadOptionalTargetList (ObjectNode node , String member ) {
323+ private List <ShapeId > loadOptionalTargetList (
324+ LoaderVisitor visitor , ShapeId id , ObjectNode node , String member ) {
323325 return node .getArrayMember (member )
324326 .map (array -> array .getElements ().stream ()
325- .map (this :: loadReferenceBody )
327+ .map (e -> loadReferenceBody ( visitor , id , e ) )
326328 .collect (Collectors .toList ()))
327329 .orElseGet (Collections ::emptyList );
328330 }
0 commit comments