nipyapi
nipyapi copied to clipboard
Fix parameter_sensitivities checking the values instead of the keys
This PR fixes creation of ParameterContexts.
The swagger-codegen package adds a validation on the keys instead of the values. See https://github.com/swagger-api/swagger-codegen/issues/9138.
Luckily, the default templates from the swagger-codegen package are overridden in this repo, so we can make the change here. Looking at the age of the issue, it doesn't seem they are interested in changing their default templates.
Hold on with this... I do still see a case where NiFi returns with null as sensitivity.
It seems to happen when calling the fetch_parameters API.
ValueError: Invalid values in parameter_sensitivities [None], must be a subset of [SENSITIVE, NON_SENSITIVE]
EDIT:
I've noticed something wrong with the Swagger API docs for the /parameter-providers/{id}/parameters/fetch-requests endpoint.
The docs states that the reply is a ParameterProviderEntity. Going further, it contains a .component.parameterGroupConfigurations[0].parameterSensitivities of the type ParameterSensitivity. This ParameterSensitivity only allows to be SENSITIVE or NON_SENSITIVE:
...
"parameterSensitivities" : {
"type" : "object",
"description" : "All fetched parameter names that should be applied.",
"additionalProperties" : {
"type" : "string",
"enum" : [ "SENSITIVE", "NON_SENSITIVE" ]
}
},
...
However, the /parameter-providers/{id}/parameters/fetch-requests endpoint returns null as a sensitivity if it hasn't been setup yet.
This causes the parsing of the reply to fail.
I had to add None to the allowed_values. This is not optimal, since a codegen will override this from the swagger file, however, it seems that it isn't possible to specify a null value in Swagger 2.0.
NiFI does return null on purpose here: https://github.com/apache/nifi/blob/rel/nifi-1.26.0/nifi-api/src/main/java/org/apache/nifi/parameter/ParameterGroupConfiguration.java#L68
On Swagger 3.0, the following should be possible, but when running the codegen here, it doesn't update the models.
"parameterSensitivities" : {
"type" : "object",
"description" : "All fetched parameter names that should be applied.",
"additionalProperties" : {
"type" : "string",
"nullable": true,
"enum" : [ "SENSITIVE", "NON_SENSITIVE", null ]
}
},
I'm not sure how to proceed here.
I've created a ticket at the NiFi Jira here: https://issues.apache.org/jira/browse/NIFI-13419
+1