@@ -39,7 +39,8 @@ def init_openapi_spec(service_name, file_name, protocol):
3939 }
4040
4141def add_info (openapi_spec , service_shape ):
42- openapi_spec ["info" ]["version" ] = service_shape ["version" ]
42+ if "version" in service_shape :
43+ openapi_spec ["info" ]["version" ] = service_shape ["version" ]
4344 openapi_spec ["info" ]["title" ] = service_shape ["traits" ]["smithy.api#title" ]
4445 openapi_spec ["info" ]["description" ] = LiteralStr (html_to_md (service_shape ["traits" ]["smithy.api#documentation" ]))
4546
@@ -507,18 +508,24 @@ def add_operation(openapi_spec, shape_name, shape, shapes):
507508 print (f"adding operation { operation_id } " )
508509
509510 # process traits
510- path = shape ["traits" ]["smithy.api#http" ]["uri" ]
511- verb = shape ["traits" ]["smithy.api#http" ]["method" ].lower ()
512- if "code" in shape ["traits" ]["smithy.api#http" ]:
513- success_code = shape ["traits" ]["smithy.api#http" ]["code" ]
514- else :
515- success_code = 200
511+ traits = shape .get ("traits" , {})
512+ http = traits .get ("smithy.api#http" , {})
513+ path = http .get ("uri" , None )
514+ verb = http .get ("method" , None )
515+ if verb :
516+ verb = verb .lower ()
517+
518+ if path is None or verb is None :
519+ return
520+
521+ success_code = http .get ("code" , 200 )
522+
516523 if path not in openapi_spec ["paths" ]:
517524 openapi_spec ["paths" ][path ] = {}
518525 if verb not in openapi_spec ["paths" ][path ]:
519526 openapi_spec ["paths" ][path ][verb ] = {}
520527 openapi_spec ["paths" ][path ][verb ]["operationId" ] = operation_id
521- if "smithy.api#documentation" in shape [ " traits" ] :
528+ if "smithy.api#documentation" in traits :
522529 description = LiteralStr (html_to_md (shape ["traits" ]["smithy.api#documentation" ]))
523530 openapi_spec ["paths" ][path ][verb ]["description" ] = description
524531
0 commit comments