Skip to content

Commit

Permalink
integrate (special case for resources with POST operations that do no…
Browse files Browse the repository at this point in the history
…t expect any input) logic into validateRootPath
  • Loading branch information
dikhan committed Oct 29, 2019
1 parent dfdc4b2 commit 3939a65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions openapi/openapi_v2_spec_analyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,17 @@ func (specAnalyser *specV2Analyser) validateRootPath(resourcePath string) (strin
resourceRootPostSchemaDef, err := specAnalyser.getBodyParameterBodySchema(resourceRootPostOperation)
if err != nil {
bodyParam := specAnalyser.bodyParameterExists(resourceRootPostOperation)
// Use case where resource does not expect any input as part of the POST root operation, and only produces computed properties
if bodyParam == nil {
resourceSchema, _ := specAnalyser.getSuccessfulResponseDefinition(resourceRootPostOperation) // TODO: implement this
err := specAnalyser.validateResourceSchemaDefWithOptions(resourceSchema, true)
resourceSchema, err := specAnalyser.getSuccessfulResponseDefinition(resourceRootPostOperation)
if err != nil {
return "", nil, nil, fmt.Errorf("resource root path '%s' POST operation validation error: %s", resourceRootPath, err)
return "", nil, nil, fmt.Errorf("resource root path '%s' POST operation (without body parameter) error: %s", resourceRootPath, err)
}
// TODO: if we have reached this poiunt, that means that the root path should also be considered valid even though the post does not contain a body param. Hence, the resourceRootPostSchemaDef should instead be assigned to the model returned by getSuccessfulResponseDefinition
// TODO: assign resourceRootPostSchemaDef = resourceSchema
// TODO: return resourceRootPath, &resourceRootPathItem, resourceRootPostSchemaDef, nil
err = specAnalyser.validateResourceSchemaDefWithOptions(resourceSchema, true)
if err != nil {
return "", nil, nil, fmt.Errorf("resource root path '%s' POST operation (without body parameter) validation error: %s", resourceRootPath, err)
}
return resourceRootPath, &resourceRootPathItem, resourceSchema, nil
}
return "", nil, nil, fmt.Errorf("resource root path '%s' POST operation validation error: %s", resourceRootPath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions openapi/openapi_v2_spec_analyser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ definitions:
})
})

Convey("Given an apiSpecAnalyser with a resource instance path such as '/users/{id}' but the root is missing the 'body' parameter", t, func() {
Convey("Given an apiSpecAnalyser with a resource instance path such as '/users/{id}' but the root is missing the 'body' parameter AND it's not a compatible resource without input", t, func() {
swaggerContent := `swagger: "2.0"
paths:
/users:
Expand Down Expand Up @@ -1747,7 +1747,7 @@ definitions:
So(err, ShouldNotBeNil)
})
Convey("And the error message should be", func() {
So(err.Error(), ShouldContainSubstring, "resource root path '/users' POST operation validation error: resource root operation missing the body parameter")
So(err.Error(), ShouldContainSubstring, "resource root path '/users' POST operation (without body parameter) validation error: resource schema contains properties that are not just read only")
})
})
})
Expand Down

0 comments on commit 3939a65

Please sign in to comment.