Skip to content

Commit

Permalink
Allow docs-2.json to reference shapes not present in API without fail…
Browse files Browse the repository at this point in the history
…ure. (#4107)
  • Loading branch information
skmcgrail committed Sep 22, 2021
1 parent 9f2d852 commit f6af9ec
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
3 changes: 1 addition & 2 deletions private/model/api/docstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func (d *apiDocumentation) setup(a *API) error {

for opName, doc := range d.Operations {
if _, ok := a.Operations[opName]; !ok {
return fmt.Errorf("%s, doc op %q not found in API op set",
a.name, opName)
continue
}
a.Operations[opName].Documentation = docstring(doc)
}
Expand Down
49 changes: 49 additions & 0 deletions private/model/api/docstring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,52 @@ func TestDocstring(t *testing.T) {
})
}
}

func TestApiDocumentation_missingShapes(t *testing.T) {
docs := apiDocumentation{
Service: "some service documentation",
Operations: map[string]string{
"OperationOne": "some operation documentation",
"OperationTwo": "some more operation documentation",
},
Shapes: map[string]shapeDocumentation{
"ShapeOne": {
Base: "some shape documentation",
},
"ShapeTwo": {
Base: "some more shape documentation",
Refs: map[string]string{
"ShapeOne$shapeTwo": "shape ref document",
},
},
},
}

api := API{
Operations: map[string]*Operation{
"OperationOne": {},
},
Shapes: map[string]*Shape{
"ShapeOne": {
Type: "structure",
MemberRefs: map[string]*ShapeRef{},
},
},
}

if err := docs.setup(&api); err != nil {
t.Fatalf("expect no error, got %v", err)
}

if _, ok := api.Operations["OperationTwo"]; ok {
t.Errorf("expect operation shape to not be added from document model")
}

if _, ok := api.Shapes["ShapeTwo"]; ok {
t.Errorf("expect shape to not be added from document model")
}

if _, ok := api.Shapes["ShapeOne"].MemberRefs["shapeTwo"]; ok {
t.Errorf("expect shape to not be added from document model")
}
}

0 comments on commit f6af9ec

Please sign in to comment.