-
Notifications
You must be signed in to change notification settings - Fork 90
About swagger specification don't support key "oneOf" and "anyOf" of schema object. #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, could you clarify your requirement and why would you use "oneOf"/"anyOf"? If you want to bypass those parts, then there is nothing much different between using pyswagger and making raw http requests. |
Hi, mission when the "obj_type" is "plan", the content type of "objects" array for request is like this: So that means we need the schema object in swagger definition support any type description of the content of "objects" array. But now, if we design the schema of swagger definition according to the "plan" object_type, pyswagger can't validate the request data of "iplist" correctly. And the reverse is also true. So, we need schema object description support 'anyOf' or "oneOf" the type, but swagger specification not support any type. It only support "allOf". So, we need a workaround for this. Thanks, |
Hi mission,
"test": { Or can I set nothing in the properties of Object_instance? So, I can give the true data whatever I want. Thanks, |
Hi, As you already know, Swagger (OpenAPI) wouldn't support "oneOf" or "anyOf" mainly because they encourage deterministic design of APIs. My suggestion to support "oneOf" or "anyOf" is to set your type as "string" and parse its content by yourself. (Or just make separated APIs for different types). |
@mission-liao A sample swagger object is like this:
Add the following code in _model.py. I believe this change has no side-effect.
What do you think? |
Hi, your code-snippet reminds me that you can try "additionalProperties: true" "definitions":{
"workaround_anyof":{
"type":"object",
"additionalProperties": true
}
} Although you can't find this usage on current spec of Swagger, but it was there and pyswagger supports it. Interestingly, the way we support this part is just like the code-snippet you provided. (refer to pyswagger.primitives._model.Model.cleanup). |
Hi, mission |
Hi, @WillaLuo it's based on my wrong understanding about json-schema. According to this issue and current schema.json, the only valid value of additionalProperties is "false", true is forbidden. There would be no validation performed against those values matched by "additionalProperties: true", that's the only reason why this "backdoor" exists (and why other guys tries to restrict its usage) I will fix this invalid default value in next release but still allow "additionalProperties: true" to make your workaround possible. |
Hi mission
Can pyswagger provide an option for using client to do request with independent input parameter as body data, not according the schema object definitions? Because swagger specification not support "oneOf" and "anyOf" key, it is difficult for us to design schema object for input parameters.
Thanks a lot!
The text was updated successfully, but these errors were encountered: