Closed Agalin closed 3 years ago
Thanks a lot @Agalin for your issue and proposal!
Could be a correct approach this solution?
Add this parameters to swagger config: validate_responses
and validator_map
swagger:
path: ""
file: "swagger.yaml"
url: "ws-doc/"
....
validate_responses: [True|False]
validator_map: "[path.to.your.CustomResponseValidator]"
and import validate_responses
and validator_map
like:
app = connexion.App(__name__,
specification_dir=specification_dir,
resolver=RestyResolver(self.project_dir)
validator_map={'response': importlib.import_module(self.validator_map)}
^^^^
)
params = {
....
"options": {"swagger_url": self.url},
"validate_responses": self.validate_responses
^^^^
}
Validator map should be passed per add_api
call if I understand docs correctly (can't check implementation atm.) but it's exactly the way I'd like to see.
Sorry, you are right :+1:
params = {
....
"options": {"swagger_url": self.url},
"validator_map": {'response': importlib.import_module(self.validator_map)},
"validate_responses": self.validate_responses
}
Might as well add custom body
and parameter
validators - those cannot be set from the schema either and implementation would be the same.
ok! do you mean multiple custom valdations? :+1: in example....
swagger:
path: ""
file: "swagger.yaml"
url: "ws-doc/"
....
validate_responses: [True|False]
validator_map:
....
response : "[path.to.your.CustomResponseValidator]"
body : "[path.to.your.CustomResponseValidator]"
parameter : "[path.to.your.CustomResponseValidator]"
validator_map = {k: importlib.import_module(v) for k, v in self.validator_map.items()}
params = {
....
"options": {"swagger_url": self.url},
"validator_map": validator_map,
"validate_responses": self.validate_responses
}
Yeah. Although body
and parameter
are actually request validators. Those 3 can easily be placed under the same optional key in config.
Te lo pido!!!
Is your feature request related to a problem? Please describe. I've recently wanted to use Connexion's feature that validates responses according to API schema. Then found that parameters described in
config.yml
docs are ALL that can be used and there seem to be absolutely no way of passing any additional value to the API.Describe the solution you'd like Either there should be additional settings available in
config.yml
or at least some kind of a callback that could be overriden to easily pass additional parameters to API constructor. Maybe a mappingCUSTOM_OPTIONS
or similar that would just be passed as unpacked kwargs toadd_api
? Even if not, there aren't that many parameters supporrted by this method so possibly all of them could be moved toconfig.yml
.Describe alternatives you've considered Currently end user needs to basically copy whole
init_app
of the Swagger service - and who knows how much of the Microservice class to support custom service.