ory-client 1.9.0__py3-none-any.whl → 1.11.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (565) hide show
  1. ory_client/__init__.py +279 -10
  2. ory_client/api/__init__.py +16 -3
  3. ory_client/api/courier_api.py +576 -287
  4. ory_client/api/events_api.py +1147 -576
  5. ory_client/api/frontend_api.py +8736 -4145
  6. ory_client/api/identity_api.py +5219 -2605
  7. ory_client/api/jwk_api.py +1881 -939
  8. ory_client/api/metadata_api.py +245 -376
  9. ory_client/api/o_auth2_api.py +7763 -3858
  10. ory_client/api/oidc_api.py +2071 -1034
  11. ory_client/api/permission_api.py +1675 -776
  12. ory_client/api/project_api.py +5314 -2638
  13. ory_client/api/relationship_api.py +1844 -860
  14. ory_client/api/wellknown_api.py +250 -131
  15. ory_client/api_client.py +520 -658
  16. ory_client/api_response.py +21 -0
  17. ory_client/configuration.py +65 -75
  18. ory_client/exceptions.py +73 -32
  19. ory_client/models/__init__.py +266 -291
  20. ory_client/models/accept_o_auth2_consent_request.py +118 -0
  21. ory_client/models/accept_o_auth2_consent_request_session.py +113 -0
  22. ory_client/models/accept_o_auth2_login_request.py +117 -0
  23. ory_client/models/active_project_in_console.py +101 -0
  24. ory_client/models/attribute.py +103 -0
  25. ory_client/models/attribute_filter.py +115 -0
  26. ory_client/models/attributes_count_datapoint.py +103 -0
  27. ory_client/models/authenticator_assurance_level.py +40 -0
  28. ory_client/models/batch_patch_identities_response.py +109 -0
  29. ory_client/models/check_opl_syntax_result.py +109 -0
  30. ory_client/models/check_permission_result.py +101 -0
  31. ory_client/models/cloud_account.py +105 -0
  32. ory_client/models/consistency_request_parameters.py +111 -0
  33. ory_client/models/continue_with.py +214 -0
  34. ory_client/models/continue_with_recovery_ui.py +114 -0
  35. ory_client/models/continue_with_recovery_ui_flow.py +103 -0
  36. ory_client/models/continue_with_set_ory_session_token.py +110 -0
  37. ory_client/models/continue_with_settings_ui.py +114 -0
  38. ory_client/models/continue_with_settings_ui_flow.py +101 -0
  39. ory_client/models/continue_with_verification_ui.py +114 -0
  40. ory_client/models/continue_with_verification_ui_flow.py +105 -0
  41. ory_client/models/courier_message_status.py +40 -0
  42. ory_client/models/courier_message_type.py +38 -0
  43. ory_client/models/create_custom_domain_body.py +109 -0
  44. ory_client/models/create_event_stream_body.py +112 -0
  45. ory_client/models/create_identity_body.py +155 -0
  46. ory_client/models/create_invite_response.py +114 -0
  47. ory_client/models/create_json_web_key_set.py +105 -0
  48. ory_client/models/create_project_api_key_request.py +101 -0
  49. ory_client/models/create_project_body.py +112 -0
  50. ory_client/models/create_project_branding.py +115 -0
  51. ory_client/models/create_project_member_invite_body.py +101 -0
  52. ory_client/models/create_project_normalized_payload.py +685 -0
  53. ory_client/models/create_recovery_code_for_identity_body.py +114 -0
  54. ory_client/models/create_recovery_link_for_identity_body.py +114 -0
  55. ory_client/models/create_relationship_body.py +113 -0
  56. ory_client/models/create_subscription_body.py +126 -0
  57. ory_client/models/create_subscription_common.py +124 -0
  58. ory_client/models/create_verifiable_credential_request_body.py +109 -0
  59. ory_client/models/create_workspace_member_invite_body.py +101 -0
  60. ory_client/models/create_workspace_payload.py +101 -0
  61. ory_client/models/create_workspace_subscription_body.py +124 -0
  62. ory_client/models/credential_supported_draft00.py +107 -0
  63. ory_client/models/custom_domain.py +132 -0
  64. ory_client/models/delete_my_sessions_count.py +101 -0
  65. ory_client/models/email_template_data.py +107 -0
  66. ory_client/models/email_template_data_body.py +103 -0
  67. ory_client/models/error_authenticator_assurance_level_not_satisfied.py +107 -0
  68. ory_client/models/error_browser_location_change_required.py +107 -0
  69. ory_client/models/error_flow_replaced.py +107 -0
  70. ory_client/models/error_generic.py +105 -0
  71. ory_client/models/error_o_auth2.py +109 -0
  72. ory_client/models/event_stream.py +112 -0
  73. ory_client/models/expanded_permission_tree.py +125 -0
  74. ory_client/models/flow_error.py +108 -0
  75. ory_client/models/generic_error.py +126 -0
  76. ory_client/models/generic_error_content.py +109 -0
  77. ory_client/models/generic_usage.py +103 -0
  78. ory_client/models/get_attributes_count_response.py +111 -0
  79. ory_client/models/get_managed_identity_schema_location.py +101 -0
  80. ory_client/models/get_metrics_event_attributes_response.py +103 -0
  81. ory_client/models/get_metrics_event_types_response.py +103 -0
  82. ory_client/models/get_organization_response.py +105 -0
  83. ory_client/models/get_project_events_body.py +120 -0
  84. ory_client/models/get_project_events_response.py +115 -0
  85. ory_client/models/get_project_metrics_response.py +111 -0
  86. ory_client/models/get_session_activity_response.py +111 -0
  87. ory_client/models/get_version200_response.py +101 -0
  88. ory_client/models/health_not_ready_status.py +101 -0
  89. ory_client/models/health_status.py +101 -0
  90. ory_client/models/identity.py +187 -0
  91. ory_client/models/identity_credentials.py +122 -0
  92. ory_client/models/identity_credentials_code.py +109 -0
  93. ory_client/models/identity_credentials_oidc.py +109 -0
  94. ory_client/models/identity_credentials_oidc_provider.py +111 -0
  95. ory_client/models/identity_credentials_password.py +101 -0
  96. ory_client/models/identity_patch.py +107 -0
  97. ory_client/models/identity_patch_response.py +115 -0
  98. ory_client/models/identity_schema_container.py +103 -0
  99. ory_client/models/identity_schema_preset.py +103 -0
  100. ory_client/models/identity_with_credentials.py +111 -0
  101. ory_client/models/identity_with_credentials_oidc.py +105 -0
  102. ory_client/models/identity_with_credentials_oidc_config.py +115 -0
  103. ory_client/models/identity_with_credentials_oidc_config_provider.py +103 -0
  104. ory_client/models/identity_with_credentials_password.py +105 -0
  105. ory_client/models/identity_with_credentials_password_config.py +103 -0
  106. ory_client/models/internal_get_project_branding_body.py +101 -0
  107. ory_client/models/internal_is_ax_welcome_screen_enabled_for_project_body.py +103 -0
  108. ory_client/models/internal_is_owner_for_project_by_slug_body.py +114 -0
  109. ory_client/models/internal_is_owner_for_project_by_slug_response.py +101 -0
  110. ory_client/models/introspected_o_auth2_token.py +127 -0
  111. ory_client/models/is_owner_for_project_by_slug.py +103 -0
  112. ory_client/models/json_patch.py +119 -0
  113. ory_client/models/json_web_key.py +133 -0
  114. ory_client/models/json_web_key_set.py +109 -0
  115. ory_client/models/keto_namespace.py +103 -0
  116. ory_client/models/list_event_streams.py +109 -0
  117. ory_client/models/list_my_workspaces_response.py +113 -0
  118. ory_client/models/list_organizations_response.py +109 -0
  119. ory_client/models/list_workspace_projects_response.py +113 -0
  120. ory_client/models/login_flow.py +165 -0
  121. ory_client/models/login_flow_state.py +39 -0
  122. ory_client/models/logout_flow.py +103 -0
  123. ory_client/models/managed_identity_schema.py +120 -0
  124. ory_client/models/managed_identity_schema_validation_result.py +103 -0
  125. ory_client/models/member_invite.py +148 -0
  126. ory_client/models/message.py +141 -0
  127. ory_client/models/message_dispatch.py +119 -0
  128. ory_client/models/metrics_datapoint.py +104 -0
  129. ory_client/models/migration_options.py +117 -0
  130. ory_client/models/namespace.py +101 -0
  131. ory_client/models/needs_privileged_session_error.py +107 -0
  132. ory_client/models/normalized_project.py +171 -0
  133. ory_client/models/normalized_project_revision.py +674 -0
  134. ory_client/models/normalized_project_revision_courier_channel.py +145 -0
  135. ory_client/models/normalized_project_revision_hook.py +140 -0
  136. ory_client/models/normalized_project_revision_identity_schema.py +133 -0
  137. ory_client/models/normalized_project_revision_third_party_provider.py +187 -0
  138. ory_client/models/normalized_project_revision_tokenizer_template.py +133 -0
  139. ory_client/models/o_auth2_client.py +352 -0
  140. ory_client/models/o_auth2_client_token_lifespans.py +270 -0
  141. ory_client/models/o_auth2_consent_request.py +133 -0
  142. ory_client/models/o_auth2_consent_request_open_id_connect_context.py +109 -0
  143. ory_client/models/o_auth2_consent_session.py +130 -0
  144. ory_client/models/o_auth2_consent_session_expires_at.py +110 -0
  145. ory_client/models/o_auth2_login_request.py +125 -0
  146. ory_client/models/o_auth2_logout_request.py +115 -0
  147. ory_client/models/o_auth2_redirect_to.py +101 -0
  148. ory_client/models/o_auth2_token_exchange.py +111 -0
  149. ory_client/models/oidc_configuration.py +169 -0
  150. ory_client/models/oidc_user_info.py +137 -0
  151. ory_client/models/organization.py +116 -0
  152. ory_client/models/organization_body.py +103 -0
  153. ory_client/models/pagination.py +104 -0
  154. ory_client/models/pagination_headers.py +103 -0
  155. ory_client/models/parse_error.py +112 -0
  156. ory_client/models/patch_identities_body.py +109 -0
  157. ory_client/models/perform_native_logout_body.py +101 -0
  158. ory_client/models/permissions_on_workpace_response.py +101 -0
  159. ory_client/models/plan.py +103 -0
  160. ory_client/models/plan_details.py +128 -0
  161. ory_client/models/post_check_permission_body.py +113 -0
  162. ory_client/models/post_check_permission_or_error_body.py +113 -0
  163. ory_client/models/project.py +148 -0
  164. ory_client/models/project_api_key.py +126 -0
  165. ory_client/models/project_branding.py +129 -0
  166. ory_client/models/project_branding_colors.py +157 -0
  167. ory_client/models/project_branding_theme.py +182 -0
  168. ory_client/models/project_cors.py +103 -0
  169. ory_client/models/project_events_datapoint.py +114 -0
  170. ory_client/models/project_host.py +107 -0
  171. ory_client/models/project_member.py +107 -0
  172. ory_client/models/project_metadata.py +161 -0
  173. ory_client/models/project_service_identity.py +101 -0
  174. ory_client/models/project_service_o_auth2.py +101 -0
  175. ory_client/models/project_service_permission.py +101 -0
  176. ory_client/models/project_services.py +117 -0
  177. ory_client/models/quota_usage.py +118 -0
  178. ory_client/models/recovery_code_for_identity.py +106 -0
  179. ory_client/models/recovery_flow.py +139 -0
  180. ory_client/models/recovery_flow_state.py +39 -0
  181. ory_client/models/recovery_identity_address.py +110 -0
  182. ory_client/models/recovery_link_for_identity.py +104 -0
  183. ory_client/models/registration_flow.py +156 -0
  184. ory_client/models/registration_flow_state.py +39 -0
  185. ory_client/models/reject_o_auth2_request.py +109 -0
  186. ory_client/models/relation_query.py +113 -0
  187. ory_client/models/relationship.py +113 -0
  188. ory_client/models/relationship_namespaces.py +109 -0
  189. ory_client/models/relationship_patch.py +117 -0
  190. ory_client/models/relationships.py +111 -0
  191. ory_client/models/rfc6749_error_json.py +109 -0
  192. ory_client/models/schema_patch.py +103 -0
  193. ory_client/models/self_service_flow_expired_error.py +112 -0
  194. ory_client/models/session.py +141 -0
  195. ory_client/models/session_activity_datapoint.py +105 -0
  196. ory_client/models/session_authentication_method.py +121 -0
  197. ory_client/models/session_device.py +107 -0
  198. ory_client/models/set_active_project_in_console_body.py +101 -0
  199. ory_client/models/set_custom_domain_body.py +109 -0
  200. ory_client/models/set_event_stream_body.py +112 -0
  201. ory_client/models/set_project.py +118 -0
  202. ory_client/models/set_project_branding_theme_body.py +115 -0
  203. ory_client/models/settings_flow.py +145 -0
  204. ory_client/models/settings_flow_state.py +38 -0
  205. ory_client/models/source_position.py +103 -0
  206. ory_client/models/subject_set.py +105 -0
  207. ory_client/models/subscription.py +179 -0
  208. ory_client/models/successful_code_exchange_response.py +107 -0
  209. ory_client/models/successful_native_login.py +117 -0
  210. ory_client/models/successful_native_registration.py +123 -0
  211. ory_client/models/successful_project_update.py +115 -0
  212. ory_client/models/token_pagination.py +104 -0
  213. ory_client/models/token_pagination_headers.py +103 -0
  214. ory_client/models/token_pagination_request_parameters.py +104 -0
  215. ory_client/models/token_pagination_response_headers.py +103 -0
  216. ory_client/models/trust_o_auth2_jwt_grant_issuer.py +116 -0
  217. ory_client/models/trusted_o_auth2_jwt_grant_issuer.py +120 -0
  218. ory_client/models/trusted_o_auth2_jwt_grant_json_web_key.py +103 -0
  219. ory_client/models/ui_container.py +123 -0
  220. ory_client/models/ui_node.py +139 -0
  221. ory_client/models/ui_node_anchor_attributes.py +118 -0
  222. ory_client/models/ui_node_attributes.py +238 -0
  223. ory_client/models/ui_node_image_attributes.py +116 -0
  224. ory_client/models/ui_node_input_attributes.py +154 -0
  225. ory_client/models/ui_node_meta.py +105 -0
  226. ory_client/models/ui_node_script_attributes.py +124 -0
  227. ory_client/models/ui_node_text_attributes.py +116 -0
  228. ory_client/models/ui_text.py +114 -0
  229. ory_client/models/update_identity_body.py +132 -0
  230. ory_client/models/update_login_flow_body.py +286 -0
  231. ory_client/models/update_login_flow_with_code_method.py +111 -0
  232. ory_client/models/update_login_flow_with_lookup_secret_method.py +105 -0
  233. ory_client/models/update_login_flow_with_oidc_method.py +115 -0
  234. ory_client/models/update_login_flow_with_passkey_method.py +105 -0
  235. ory_client/models/update_login_flow_with_password_method.py +111 -0
  236. ory_client/models/update_login_flow_with_totp_method.py +107 -0
  237. ory_client/models/update_login_flow_with_web_authn_method.py +109 -0
  238. ory_client/models/update_recovery_flow_body.py +166 -0
  239. ory_client/models/update_recovery_flow_with_code_method.py +116 -0
  240. ory_client/models/update_recovery_flow_with_link_method.py +114 -0
  241. ory_client/models/update_registration_flow_body.py +238 -0
  242. ory_client/models/update_registration_flow_with_code_method.py +111 -0
  243. ory_client/models/update_registration_flow_with_oidc_method.py +115 -0
  244. ory_client/models/update_registration_flow_with_passkey_method.py +109 -0
  245. ory_client/models/update_registration_flow_with_password_method.py +109 -0
  246. ory_client/models/update_registration_flow_with_profile_method.py +109 -0
  247. ory_client/models/update_registration_flow_with_web_authn_method.py +111 -0
  248. ory_client/models/update_settings_flow_body.py +286 -0
  249. ory_client/models/update_settings_flow_with_lookup_method.py +113 -0
  250. ory_client/models/update_settings_flow_with_oidc_method.py +113 -0
  251. ory_client/models/update_settings_flow_with_passkey_method.py +107 -0
  252. ory_client/models/update_settings_flow_with_password_method.py +107 -0
  253. ory_client/models/update_settings_flow_with_profile_method.py +107 -0
  254. ory_client/models/update_settings_flow_with_totp_method.py +109 -0
  255. ory_client/models/update_settings_flow_with_web_authn_method.py +111 -0
  256. ory_client/models/update_subscription_body.py +112 -0
  257. ory_client/models/update_verification_flow_body.py +166 -0
  258. ory_client/models/update_verification_flow_with_code_method.py +116 -0
  259. ory_client/models/update_verification_flow_with_link_method.py +114 -0
  260. ory_client/models/update_workspace_payload.py +101 -0
  261. ory_client/models/usage.py +105 -0
  262. ory_client/models/verifiable_credential_priming_response.py +115 -0
  263. ory_client/models/verifiable_credential_proof.py +103 -0
  264. ory_client/models/verifiable_credential_response.py +103 -0
  265. ory_client/models/verifiable_identity_address.py +123 -0
  266. ory_client/models/verification_flow.py +129 -0
  267. ory_client/models/verification_flow_state.py +39 -0
  268. ory_client/models/version.py +101 -0
  269. ory_client/models/warning.py +103 -0
  270. ory_client/models/workspace.py +115 -0
  271. ory_client/models/workspace_meta.py +122 -0
  272. ory_client/py.typed +0 -0
  273. ory_client/rest.py +139 -236
  274. {ory_client-1.9.0.dist-info → ory_client-1.11.6.dist-info}/METADATA +6 -4
  275. ory_client-1.11.6.dist-info/RECORD +278 -0
  276. ory_client/apis/__init__.py +0 -28
  277. ory_client/model/__init__.py +0 -5
  278. ory_client/model/accept_o_auth2_consent_request.py +0 -296
  279. ory_client/model/accept_o_auth2_consent_request_session.py +0 -268
  280. ory_client/model/accept_o_auth2_login_request.py +0 -308
  281. ory_client/model/active_project_in_console.py +0 -264
  282. ory_client/model/attribute.py +0 -268
  283. ory_client/model/attribute_filter.py +0 -282
  284. ory_client/model/attributes_count_datapoint.py +0 -276
  285. ory_client/model/authenticator_assurance_level.py +0 -293
  286. ory_client/model/batch_patch_identities_response.py +0 -270
  287. ory_client/model/check_opl_syntax_result.py +0 -270
  288. ory_client/model/check_permission_result.py +0 -270
  289. ory_client/model/cloud_account.py +0 -282
  290. ory_client/model/consistency_request_parameters.py +0 -269
  291. ory_client/model/continue_with.py +0 -356
  292. ory_client/model/continue_with_recovery_ui.py +0 -287
  293. ory_client/model/continue_with_recovery_ui_flow.py +0 -274
  294. ory_client/model/continue_with_set_ory_session_token.py +0 -281
  295. ory_client/model/continue_with_settings_ui.py +0 -287
  296. ory_client/model/continue_with_settings_ui_flow.py +0 -270
  297. ory_client/model/continue_with_verification_ui.py +0 -287
  298. ory_client/model/continue_with_verification_ui_flow.py +0 -280
  299. ory_client/model/courier_message_status.py +0 -293
  300. ory_client/model/courier_message_type.py +0 -291
  301. ory_client/model/create_custom_domain_body.py +0 -280
  302. ory_client/model/create_event_stream_body.py +0 -287
  303. ory_client/model/create_identity_body.py +0 -314
  304. ory_client/model/create_invite_response.py +0 -282
  305. ory_client/model/create_json_web_key_set.py +0 -282
  306. ory_client/model/create_member_invite_response.py +0 -287
  307. ory_client/model/create_project_api_key_request.py +0 -270
  308. ory_client/model/create_project_body.py +0 -284
  309. ory_client/model/create_project_branding.py +0 -290
  310. ory_client/model/create_project_member_invite_body.py +0 -264
  311. ory_client/model/create_project_normalized_payload.py +0 -1119
  312. ory_client/model/create_recovery_code_for_identity_body.py +0 -279
  313. ory_client/model/create_recovery_link_for_identity_body.py +0 -279
  314. ory_client/model/create_relationship_body.py +0 -286
  315. ory_client/model/create_subscription_body.py +0 -298
  316. ory_client/model/create_subscription_common.py +0 -292
  317. ory_client/model/create_verifiable_credential_request_body.py +0 -278
  318. ory_client/model/create_workspace_member_invite_body.py +0 -264
  319. ory_client/model/create_workspace_payload.py +0 -270
  320. ory_client/model/create_workspace_subscription_body.py +0 -292
  321. ory_client/model/credential_supported_draft00.py +0 -276
  322. ory_client/model/custom_domain.py +0 -334
  323. ory_client/model/delete_my_sessions_count.py +0 -264
  324. ory_client/model/email_template_data.py +0 -282
  325. ory_client/model/email_template_data_body.py +0 -276
  326. ory_client/model/error_authenticator_assurance_level_not_satisfied.py +0 -274
  327. ory_client/model/error_browser_location_change_required.py +0 -274
  328. ory_client/model/error_flow_replaced.py +0 -274
  329. ory_client/model/error_generic.py +0 -276
  330. ory_client/model/error_o_auth2.py +0 -280
  331. ory_client/model/event_stream.py +0 -284
  332. ory_client/model/expanded_permission_tree.py +0 -294
  333. ory_client/model/flow_error.py +0 -282
  334. ory_client/model/generic_error.py +0 -308
  335. ory_client/model/generic_error_content.py +0 -280
  336. ory_client/model/generic_usage.py +0 -276
  337. ory_client/model/get_attributes_count_response.py +0 -273
  338. ory_client/model/get_managed_identity_schema_location.py +0 -264
  339. ory_client/model/get_metrics_event_attributes_response.py +0 -267
  340. ory_client/model/get_metrics_event_types_response.py +0 -267
  341. ory_client/model/get_organization_response.py +0 -276
  342. ory_client/model/get_project_events_body.py +0 -298
  343. ory_client/model/get_project_events_response.py +0 -278
  344. ory_client/model/get_project_metrics_response.py +0 -273
  345. ory_client/model/get_session_activity_response.py +0 -273
  346. ory_client/model/get_version200_response.py +0 -270
  347. ory_client/model/health_not_ready_status.py +0 -264
  348. ory_client/model/health_status.py +0 -264
  349. ory_client/model/identity.py +0 -342
  350. ory_client/model/identity_credentials.py +0 -294
  351. ory_client/model/identity_credentials_code.py +0 -268
  352. ory_client/model/identity_credentials_oidc.py +0 -270
  353. ory_client/model/identity_credentials_oidc_provider.py +0 -284
  354. ory_client/model/identity_credentials_password.py +0 -264
  355. ory_client/model/identity_patch.py +0 -274
  356. ory_client/model/identity_patch_response.py +0 -275
  357. ory_client/model/identity_schema_container.py +0 -268
  358. ory_client/model/identity_schema_preset.py +0 -276
  359. ory_client/model/identity_schema_presets.py +0 -292
  360. ory_client/model/identity_schemas.py +0 -292
  361. ory_client/model/identity_with_credentials.py +0 -276
  362. ory_client/model/identity_with_credentials_oidc.py +0 -270
  363. ory_client/model/identity_with_credentials_oidc_config.py +0 -276
  364. ory_client/model/identity_with_credentials_oidc_config_provider.py +0 -276
  365. ory_client/model/identity_with_credentials_password.py +0 -270
  366. ory_client/model/identity_with_credentials_password_config.py +0 -268
  367. ory_client/model/internal_get_project_branding_body.py +0 -264
  368. ory_client/model/internal_is_ax_welcome_screen_enabled_for_project_body.py +0 -276
  369. ory_client/model/internal_is_owner_for_project_by_slug_body.py +0 -290
  370. ory_client/model/internal_is_owner_for_project_by_slug_response.py +0 -270
  371. ory_client/model/introspected_o_auth2_token.py +0 -322
  372. ory_client/model/is_owner_for_project_by_slug.py +0 -276
  373. ory_client/model/is_ready200_response.py +0 -270
  374. ory_client/model/is_ready503_response.py +0 -270
  375. ory_client/model/json_patch.py +0 -292
  376. ory_client/model/json_patch_document.py +0 -292
  377. ory_client/model/json_web_key.py +0 -340
  378. ory_client/model/json_web_key_set.py +0 -270
  379. ory_client/model/keto_namespace.py +0 -268
  380. ory_client/model/keto_namespaces.py +0 -292
  381. ory_client/model/list_custom_domains.py +0 -292
  382. ory_client/model/list_event_streams.py +0 -270
  383. ory_client/model/list_my_workspaces_response.py +0 -288
  384. ory_client/model/list_organizations_response.py +0 -276
  385. ory_client/model/list_workspace_projects_response.py +0 -288
  386. ory_client/model/login_flow.py +0 -370
  387. ory_client/model/login_flow_state.py +0 -292
  388. ory_client/model/logout_flow.py +0 -276
  389. ory_client/model/managed_identity_schema.py +0 -300
  390. ory_client/model/managed_identity_schema_validation_result.py +0 -268
  391. ory_client/model/managed_identity_schemas.py +0 -292
  392. ory_client/model/member_invite.py +0 -321
  393. ory_client/model/member_invites.py +0 -292
  394. ory_client/model/message.py +0 -355
  395. ory_client/model/message_dispatch.py +0 -302
  396. ory_client/model/metrics_datapoint.py +0 -276
  397. ory_client/model/migration_options.py +0 -284
  398. ory_client/model/namespace.py +0 -264
  399. ory_client/model/needs_privileged_session_error.py +0 -280
  400. ory_client/model/normalized_project.py +0 -337
  401. ory_client/model/normalized_project_revision.py +0 -1105
  402. ory_client/model/normalized_project_revision_courier_channel.py +0 -328
  403. ory_client/model/normalized_project_revision_hook.py +0 -342
  404. ory_client/model/normalized_project_revision_identity_schema.py +0 -308
  405. ory_client/model/normalized_project_revision_identity_schemas.py +0 -292
  406. ory_client/model/normalized_project_revision_third_party_provider.py +0 -368
  407. ory_client/model/normalized_project_revision_tokenizer_template.py +0 -300
  408. ory_client/model/normalized_project_revision_tokenizer_templates.py +0 -292
  409. ory_client/model/normalized_projects.py +0 -292
  410. ory_client/model/null_duration.py +0 -292
  411. ory_client/model/o_auth2_client.py +0 -460
  412. ory_client/model/o_auth2_client_token_lifespans.py +0 -306
  413. ory_client/model/o_auth2_consent_request.py +0 -328
  414. ory_client/model/o_auth2_consent_request_open_id_connect_context.py +0 -280
  415. ory_client/model/o_auth2_consent_session.py +0 -308
  416. ory_client/model/o_auth2_consent_session_expires_at.py +0 -280
  417. ory_client/model/o_auth2_consent_sessions.py +0 -292
  418. ory_client/model/o_auth2_login_request.py +0 -320
  419. ory_client/model/o_auth2_logout_request.py +0 -290
  420. ory_client/model/o_auth2_redirect_to.py +0 -270
  421. ory_client/model/o_auth2_token_exchange.py +0 -284
  422. ory_client/model/oidc_configuration.py +0 -412
  423. ory_client/model/oidc_user_info.py +0 -336
  424. ory_client/model/organization.py +0 -302
  425. ory_client/model/organization_body.py +0 -268
  426. ory_client/model/pagination.py +0 -274
  427. ory_client/model/pagination_headers.py +0 -268
  428. ory_client/model/parse_error.py +0 -278
  429. ory_client/model/patch_identities_body.py +0 -270
  430. ory_client/model/perform_native_logout_body.py +0 -270
  431. ory_client/model/permissions_on_project.py +0 -260
  432. ory_client/model/permissions_on_workpace_response.py +0 -264
  433. ory_client/model/plan.py +0 -276
  434. ory_client/model/plan_details.py +0 -316
  435. ory_client/model/plan_features.py +0 -266
  436. ory_client/model/plans.py +0 -287
  437. ory_client/model/post_check_permission_body.py +0 -286
  438. ory_client/model/post_check_permission_or_error_body.py +0 -286
  439. ory_client/model/pricing.py +0 -292
  440. ory_client/model/project.py +0 -319
  441. ory_client/model/project_api_key.py +0 -298
  442. ory_client/model/project_api_keys.py +0 -292
  443. ory_client/model/project_branding.py +0 -303
  444. ory_client/model/project_branding_colors.py +0 -376
  445. ory_client/model/project_branding_theme.py +0 -421
  446. ory_client/model/project_branding_themes.py +0 -292
  447. ory_client/model/project_cors.py +0 -268
  448. ory_client/model/project_events_datapoint.py +0 -288
  449. ory_client/model/project_host.py +0 -281
  450. ory_client/model/project_member.py +0 -288
  451. ory_client/model/project_members.py +0 -292
  452. ory_client/model/project_metadata.py +0 -337
  453. ory_client/model/project_metadata_list.py +0 -292
  454. ory_client/model/project_revision_hooks.py +0 -292
  455. ory_client/model/project_revision_identity_schemas.py +0 -292
  456. ory_client/model/project_revision_third_party_login_providers.py +0 -292
  457. ory_client/model/project_revisions.py +0 -292
  458. ory_client/model/project_service_identity.py +0 -270
  459. ory_client/model/project_service_o_auth2.py +0 -270
  460. ory_client/model/project_service_permission.py +0 -270
  461. ory_client/model/project_services.py +0 -282
  462. ory_client/model/projects.py +0 -292
  463. ory_client/model/quota_usage.py +0 -328
  464. ory_client/model/recovery_code_for_identity.py +0 -280
  465. ory_client/model/recovery_flow.py +0 -330
  466. ory_client/model/recovery_flow_state.py +0 -292
  467. ory_client/model/recovery_identity_address.py +0 -290
  468. ory_client/model/recovery_link_for_identity.py +0 -274
  469. ory_client/model/registration_flow.py +0 -352
  470. ory_client/model/registration_flow_state.py +0 -292
  471. ory_client/model/reject_o_auth2_request.py +0 -280
  472. ory_client/model/relation_query.py +0 -286
  473. ory_client/model/relationship.py +0 -296
  474. ory_client/model/relationship_namespaces.py +0 -270
  475. ory_client/model/relationship_patch.py +0 -278
  476. ory_client/model/relationships.py +0 -274
  477. ory_client/model/revision_courier_channels.py +0 -292
  478. ory_client/model/rfc6749_error_json.py +0 -280
  479. ory_client/model/schema_patch.py +0 -276
  480. ory_client/model/self_service_flow_expired_error.py +0 -282
  481. ory_client/model/session.py +0 -318
  482. ory_client/model/session_activity_datapoint.py +0 -282
  483. ory_client/model/session_authentication_method.py +0 -297
  484. ory_client/model/session_authentication_methods.py +0 -292
  485. ory_client/model/session_device.py +0 -282
  486. ory_client/model/set_active_project_in_console_body.py +0 -270
  487. ory_client/model/set_custom_domain_body.py +0 -280
  488. ory_client/model/set_event_stream_body.py +0 -287
  489. ory_client/model/set_project.py +0 -296
  490. ory_client/model/set_project_branding_theme_body.py +0 -290
  491. ory_client/model/settings_flow.py +0 -338
  492. ory_client/model/settings_flow_state.py +0 -291
  493. ory_client/model/source_position.py +0 -268
  494. ory_client/model/string_slice_json_format.py +0 -287
  495. ory_client/model/subject_set.py +0 -282
  496. ory_client/model/subscription.py +0 -350
  497. ory_client/model/successful_code_exchange_response.py +0 -280
  498. ory_client/model/successful_native_login.py +0 -280
  499. ory_client/model/successful_native_registration.py +0 -292
  500. ory_client/model/successful_project_update.py +0 -284
  501. ory_client/model/token_pagination.py +0 -274
  502. ory_client/model/token_pagination_headers.py +0 -268
  503. ory_client/model/token_pagination_request_parameters.py +0 -274
  504. ory_client/model/token_pagination_response_headers.py +0 -268
  505. ory_client/model/trust_o_auth2_jwt_grant_issuer.py +0 -302
  506. ory_client/model/trusted_o_auth2_jwt_grant_issuer.py +0 -298
  507. ory_client/model/trusted_o_auth2_jwt_grant_issuers.py +0 -292
  508. ory_client/model/trusted_o_auth2_jwt_grant_json_web_key.py +0 -268
  509. ory_client/model/ui_container.py +0 -294
  510. ory_client/model/ui_node.py +0 -322
  511. ory_client/model/ui_node_anchor_attributes.py +0 -294
  512. ory_client/model/ui_node_attributes.py +0 -440
  513. ory_client/model/ui_node_image_attributes.py +0 -294
  514. ory_client/model/ui_node_input_attributes.py +0 -340
  515. ory_client/model/ui_node_meta.py +0 -270
  516. ory_client/model/ui_node_script_attributes.py +0 -318
  517. ory_client/model/ui_node_text_attributes.py +0 -288
  518. ory_client/model/ui_nodes.py +0 -292
  519. ory_client/model/ui_text.py +0 -291
  520. ory_client/model/ui_texts.py +0 -292
  521. ory_client/model/update_identity_body.py +0 -304
  522. ory_client/model/update_login_flow_body.py +0 -411
  523. ory_client/model/update_login_flow_with_code_method.py +0 -292
  524. ory_client/model/update_login_flow_with_lookup_secret_method.py +0 -280
  525. ory_client/model/update_login_flow_with_oidc_method.py +0 -300
  526. ory_client/model/update_login_flow_with_password_method.py +0 -294
  527. ory_client/model/update_login_flow_with_totp_method.py +0 -284
  528. ory_client/model/update_login_flow_with_web_authn_method.py +0 -288
  529. ory_client/model/update_recovery_flow_body.py +0 -351
  530. ory_client/model/update_recovery_flow_with_code_method.py +0 -290
  531. ory_client/model/update_recovery_flow_with_link_method.py +0 -288
  532. ory_client/model/update_registration_flow_body.py +0 -389
  533. ory_client/model/update_registration_flow_with_code_method.py +0 -292
  534. ory_client/model/update_registration_flow_with_oidc_method.py +0 -300
  535. ory_client/model/update_registration_flow_with_password_method.py +0 -290
  536. ory_client/model/update_registration_flow_with_web_authn_method.py +0 -292
  537. ory_client/model/update_settings_flow_body.py +0 -419
  538. ory_client/model/update_settings_flow_with_lookup_method.py +0 -294
  539. ory_client/model/update_settings_flow_with_oidc_method.py +0 -294
  540. ory_client/model/update_settings_flow_with_password_method.py +0 -284
  541. ory_client/model/update_settings_flow_with_profile_method.py +0 -284
  542. ory_client/model/update_settings_flow_with_totp_method.py +0 -286
  543. ory_client/model/update_settings_flow_with_web_authn_method.py +0 -290
  544. ory_client/model/update_subscription_body.py +0 -284
  545. ory_client/model/update_verification_flow_body.py +0 -351
  546. ory_client/model/update_verification_flow_with_code_method.py +0 -290
  547. ory_client/model/update_verification_flow_with_link_method.py +0 -288
  548. ory_client/model/update_workspace_payload.py +0 -270
  549. ory_client/model/usage.py +0 -270
  550. ory_client/model/verifiable_credential_priming_response.py +0 -292
  551. ory_client/model/verifiable_credential_proof.py +0 -268
  552. ory_client/model/verifiable_credential_response.py +0 -268
  553. ory_client/model/verifiable_identity_address.py +0 -308
  554. ory_client/model/verification_flow.py +0 -318
  555. ory_client/model/verification_flow_state.py +0 -292
  556. ory_client/model/version.py +0 -264
  557. ory_client/model/warning.py +0 -268
  558. ory_client/model/workspace.py +0 -292
  559. ory_client/model/workspace_meta.py +0 -296
  560. ory_client/model/workspaces.py +0 -292
  561. ory_client/model_utils.py +0 -2059
  562. ory_client-1.9.0.dist-info/RECORD +0 -310
  563. {ory_client-1.9.0.dist-info → ory_client-1.11.6.dist-info}/LICENSE +0 -0
  564. {ory_client-1.9.0.dist-info → ory_client-1.11.6.dist-info}/WHEEL +0 -0
  565. {ory_client-1.9.0.dist-info → ory_client-1.11.6.dist-info}/top_level.txt +0 -0
ory_client/model_utils.py DELETED
@@ -1,2059 +0,0 @@
1
- """
2
- Ory APIs
3
-
4
- Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers. # noqa: E501
5
-
6
- The version of the OpenAPI document: v1.9.0
7
- Contact: support@ory.sh
8
- Generated by: https://openapi-generator.tech
9
- """
10
-
11
-
12
- from datetime import date, datetime # noqa: F401
13
- from copy import deepcopy
14
- import inspect
15
- import io
16
- import os
17
- import pprint
18
- import re
19
- import tempfile
20
- import uuid
21
-
22
- from dateutil.parser import parse
23
-
24
- from ory_client.exceptions import (
25
- ApiKeyError,
26
- ApiAttributeError,
27
- ApiTypeError,
28
- ApiValueError,
29
- )
30
-
31
- none_type = type(None)
32
- file_type = io.IOBase
33
-
34
-
35
- def convert_js_args_to_python_args(fn):
36
- from functools import wraps
37
- @wraps(fn)
38
- def wrapped_init(_self, *args, **kwargs):
39
- """
40
- An attribute named `self` received from the api will conflicts with the reserved `self`
41
- parameter of a class method. During generation, `self` attributes are mapped
42
- to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
43
- """
44
- spec_property_naming = kwargs.get('_spec_property_naming', False)
45
- if spec_property_naming:
46
- kwargs = change_keys_js_to_python(
47
- kwargs, _self if isinstance(
48
- _self, type) else _self.__class__)
49
- return fn(_self, *args, **kwargs)
50
- return wrapped_init
51
-
52
-
53
- class cached_property(object):
54
- # this caches the result of the function call for fn with no inputs
55
- # use this as a decorator on function methods that you want converted
56
- # into cached properties
57
- result_key = '_results'
58
-
59
- def __init__(self, fn):
60
- self._fn = fn
61
-
62
- def __get__(self, instance, cls=None):
63
- if self.result_key in vars(self):
64
- return vars(self)[self.result_key]
65
- else:
66
- result = self._fn()
67
- setattr(self, self.result_key, result)
68
- return result
69
-
70
-
71
- PRIMITIVE_TYPES = (list, float, int, bool, datetime, date, str, file_type)
72
-
73
-
74
- def allows_single_value_input(cls):
75
- """
76
- This function returns True if the input composed schema model or any
77
- descendant model allows a value only input
78
- This is true for cases where oneOf contains items like:
79
- oneOf:
80
- - float
81
- - NumberWithValidation
82
- - StringEnum
83
- - ArrayModel
84
- - null
85
- TODO: lru_cache this
86
- """
87
- if (
88
- issubclass(cls, ModelSimple) or
89
- cls in PRIMITIVE_TYPES
90
- ):
91
- return True
92
- elif issubclass(cls, ModelComposed):
93
- if not cls._composed_schemas['oneOf']:
94
- return False
95
- return any(allows_single_value_input(c) for c in cls._composed_schemas['oneOf'])
96
- return False
97
-
98
-
99
- def composed_model_input_classes(cls):
100
- """
101
- This function returns a list of the possible models that can be accepted as
102
- inputs.
103
- TODO: lru_cache this
104
- """
105
- if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
106
- return [cls]
107
- elif issubclass(cls, ModelNormal):
108
- if cls.discriminator is None:
109
- return [cls]
110
- else:
111
- return get_discriminated_classes(cls)
112
- elif issubclass(cls, ModelComposed):
113
- if not cls._composed_schemas['oneOf']:
114
- return []
115
- if cls.discriminator is None:
116
- input_classes = []
117
- for c in cls._composed_schemas['oneOf']:
118
- input_classes.extend(composed_model_input_classes(c))
119
- return input_classes
120
- else:
121
- return get_discriminated_classes(cls)
122
- return []
123
-
124
-
125
- class OpenApiModel(object):
126
- """The base class for all OpenAPIModels"""
127
-
128
- def set_attribute(self, name, value):
129
- # this is only used to set properties on self
130
-
131
- path_to_item = []
132
- if self._path_to_item:
133
- path_to_item.extend(self._path_to_item)
134
- path_to_item.append(name)
135
-
136
- if name in self.openapi_types:
137
- required_types_mixed = self.openapi_types[name]
138
- elif self.additional_properties_type is None:
139
- raise ApiAttributeError(
140
- "{0} has no attribute '{1}'".format(
141
- type(self).__name__, name),
142
- path_to_item
143
- )
144
- elif self.additional_properties_type is not None:
145
- required_types_mixed = self.additional_properties_type
146
-
147
- if get_simple_class(name) != str:
148
- error_msg = type_error_message(
149
- var_name=name,
150
- var_value=name,
151
- valid_classes=(str,),
152
- key_type=True
153
- )
154
- raise ApiTypeError(
155
- error_msg,
156
- path_to_item=path_to_item,
157
- valid_classes=(str,),
158
- key_type=True
159
- )
160
-
161
- if self._check_type:
162
- value = validate_and_convert_types(
163
- value, required_types_mixed, path_to_item, self._spec_property_naming,
164
- self._check_type, configuration=self._configuration)
165
- if (name,) in self.allowed_values:
166
- check_allowed_values(
167
- self.allowed_values,
168
- (name,),
169
- value
170
- )
171
- if (name,) in self.validations:
172
- check_validations(
173
- self.validations,
174
- (name,),
175
- value,
176
- self._configuration
177
- )
178
- self.__dict__['_data_store'][name] = value
179
-
180
- def __repr__(self):
181
- """For `print` and `pprint`"""
182
- return self.to_str()
183
-
184
- def __ne__(self, other):
185
- """Returns true if both objects are not equal"""
186
- return not self == other
187
-
188
- def __setattr__(self, attr, value):
189
- """set the value of an attribute using dot notation: `instance.attr = val`"""
190
- self[attr] = value
191
-
192
- def __getattr__(self, attr):
193
- """get the value of an attribute using dot notation: `instance.attr`"""
194
- return self.__getitem__(attr)
195
-
196
- def __copy__(self):
197
- cls = self.__class__
198
- if self.get("_spec_property_naming", False):
199
- return cls._new_from_openapi_data(**self.__dict__)
200
- else:
201
- return cls.__new__(cls, **self.__dict__)
202
-
203
- def __deepcopy__(self, memo):
204
- cls = self.__class__
205
-
206
- if self.get("_spec_property_naming", False):
207
- new_inst = cls._new_from_openapi_data()
208
- else:
209
- new_inst = cls.__new__(cls)
210
-
211
- for k, v in self.__dict__.items():
212
- setattr(new_inst, k, deepcopy(v, memo))
213
- return new_inst
214
-
215
-
216
- def __new__(cls, *args, **kwargs):
217
- # this function uses the discriminator to
218
- # pick a new schema/class to instantiate because a discriminator
219
- # propertyName value was passed in
220
-
221
- if len(args) == 1:
222
- arg = args[0]
223
- if arg is None and is_type_nullable(cls):
224
- # The input data is the 'null' value and the type is nullable.
225
- return None
226
-
227
- if issubclass(cls, ModelComposed) and allows_single_value_input(cls):
228
- model_kwargs = {}
229
- oneof_instance = get_oneof_instance(cls, model_kwargs, kwargs, model_arg=arg)
230
- return oneof_instance
231
-
232
- visited_composed_classes = kwargs.get('_visited_composed_classes', ())
233
- if (
234
- cls.discriminator is None or
235
- cls in visited_composed_classes
236
- ):
237
- # Use case 1: this openapi schema (cls) does not have a discriminator
238
- # Use case 2: we have already visited this class before and are sure that we
239
- # want to instantiate it this time. We have visited this class deserializing
240
- # a payload with a discriminator. During that process we traveled through
241
- # this class but did not make an instance of it. Now we are making an
242
- # instance of a composed class which contains cls in it, so this time make an instance of cls.
243
- #
244
- # Here's an example of use case 2: If Animal has a discriminator
245
- # petType and we pass in "Dog", and the class Dog
246
- # allOf includes Animal, we move through Animal
247
- # once using the discriminator, and pick Dog.
248
- # Then in the composed schema dog Dog, we will make an instance of the
249
- # Animal class (because Dal has allOf: Animal) but this time we won't travel
250
- # through Animal's discriminator because we passed in
251
- # _visited_composed_classes = (Animal,)
252
-
253
- return super(OpenApiModel, cls).__new__(cls)
254
-
255
- # Get the name and value of the discriminator property.
256
- # The discriminator name is obtained from the discriminator meta-data
257
- # and the discriminator value is obtained from the input data.
258
- discr_propertyname_py = list(cls.discriminator.keys())[0]
259
- discr_propertyname_js = cls.attribute_map[discr_propertyname_py]
260
- if discr_propertyname_js in kwargs:
261
- discr_value = kwargs[discr_propertyname_js]
262
- elif discr_propertyname_py in kwargs:
263
- discr_value = kwargs[discr_propertyname_py]
264
- else:
265
- # The input data does not contain the discriminator property.
266
- path_to_item = kwargs.get('_path_to_item', ())
267
- raise ApiValueError(
268
- "Cannot deserialize input data due to missing discriminator. "
269
- "The discriminator property '%s' is missing at path: %s" %
270
- (discr_propertyname_js, path_to_item)
271
- )
272
-
273
- # Implementation note: the last argument to get_discriminator_class
274
- # is a list of visited classes. get_discriminator_class may recursively
275
- # call itself and update the list of visited classes, and the initial
276
- # value must be an empty list. Hence not using 'visited_composed_classes'
277
- new_cls = get_discriminator_class(
278
- cls, discr_propertyname_py, discr_value, [])
279
- if new_cls is None:
280
- path_to_item = kwargs.get('_path_to_item', ())
281
- disc_prop_value = kwargs.get(
282
- discr_propertyname_js, kwargs.get(discr_propertyname_py))
283
- raise ApiValueError(
284
- "Cannot deserialize input data due to invalid discriminator "
285
- "value. The OpenAPI document has no mapping for discriminator "
286
- "property '%s'='%s' at path: %s" %
287
- (discr_propertyname_js, disc_prop_value, path_to_item)
288
- )
289
-
290
- if new_cls in visited_composed_classes:
291
- # if we are making an instance of a composed schema Descendent
292
- # which allOf includes Ancestor, then Ancestor contains
293
- # a discriminator that includes Descendent.
294
- # So if we make an instance of Descendent, we have to make an
295
- # instance of Ancestor to hold the allOf properties.
296
- # This code detects that use case and makes the instance of Ancestor
297
- # For example:
298
- # When making an instance of Dog, _visited_composed_classes = (Dog,)
299
- # then we make an instance of Animal to include in dog._composed_instances
300
- # so when we are here, cls is Animal
301
- # cls.discriminator != None
302
- # cls not in _visited_composed_classes
303
- # new_cls = Dog
304
- # but we know we know that we already have Dog
305
- # because it is in visited_composed_classes
306
- # so make Animal here
307
- return super(OpenApiModel, cls).__new__(cls)
308
-
309
- # Build a list containing all oneOf and anyOf descendants.
310
- oneof_anyof_classes = None
311
- if cls._composed_schemas is not None:
312
- oneof_anyof_classes = (
313
- cls._composed_schemas.get('oneOf', ()) +
314
- cls._composed_schemas.get('anyOf', ()))
315
- oneof_anyof_child = new_cls in oneof_anyof_classes
316
- kwargs['_visited_composed_classes'] = visited_composed_classes + (cls,)
317
-
318
- if cls._composed_schemas.get('allOf') and oneof_anyof_child:
319
- # Validate that we can make self because when we make the
320
- # new_cls it will not include the allOf validations in self
321
- self_inst = super(OpenApiModel, cls).__new__(cls)
322
- self_inst.__init__(*args, **kwargs)
323
-
324
- if kwargs.get("_spec_property_naming", False):
325
- # when true, implies new is from deserialization
326
- new_inst = new_cls._new_from_openapi_data(*args, **kwargs)
327
- else:
328
- new_inst = new_cls.__new__(new_cls, *args, **kwargs)
329
- new_inst.__init__(*args, **kwargs)
330
-
331
- return new_inst
332
-
333
- @classmethod
334
- @convert_js_args_to_python_args
335
- def _new_from_openapi_data(cls, *args, **kwargs):
336
- # this function uses the discriminator to
337
- # pick a new schema/class to instantiate because a discriminator
338
- # propertyName value was passed in
339
-
340
- if len(args) == 1:
341
- arg = args[0]
342
- if arg is None and is_type_nullable(cls):
343
- # The input data is the 'null' value and the type is nullable.
344
- return None
345
-
346
- if issubclass(cls, ModelComposed) and allows_single_value_input(cls):
347
- model_kwargs = {}
348
- oneof_instance = get_oneof_instance(cls, model_kwargs, kwargs, model_arg=arg)
349
- return oneof_instance
350
-
351
- visited_composed_classes = kwargs.get('_visited_composed_classes', ())
352
- if (
353
- cls.discriminator is None or
354
- cls in visited_composed_classes
355
- ):
356
- # Use case 1: this openapi schema (cls) does not have a discriminator
357
- # Use case 2: we have already visited this class before and are sure that we
358
- # want to instantiate it this time. We have visited this class deserializing
359
- # a payload with a discriminator. During that process we traveled through
360
- # this class but did not make an instance of it. Now we are making an
361
- # instance of a composed class which contains cls in it, so this time make an instance of cls.
362
- #
363
- # Here's an example of use case 2: If Animal has a discriminator
364
- # petType and we pass in "Dog", and the class Dog
365
- # allOf includes Animal, we move through Animal
366
- # once using the discriminator, and pick Dog.
367
- # Then in the composed schema dog Dog, we will make an instance of the
368
- # Animal class (because Dal has allOf: Animal) but this time we won't travel
369
- # through Animal's discriminator because we passed in
370
- # _visited_composed_classes = (Animal,)
371
-
372
- return cls._from_openapi_data(*args, **kwargs)
373
-
374
- # Get the name and value of the discriminator property.
375
- # The discriminator name is obtained from the discriminator meta-data
376
- # and the discriminator value is obtained from the input data.
377
- discr_propertyname_py = list(cls.discriminator.keys())[0]
378
- discr_propertyname_js = cls.attribute_map[discr_propertyname_py]
379
- if discr_propertyname_js in kwargs:
380
- discr_value = kwargs[discr_propertyname_js]
381
- elif discr_propertyname_py in kwargs:
382
- discr_value = kwargs[discr_propertyname_py]
383
- else:
384
- # The input data does not contain the discriminator property.
385
- path_to_item = kwargs.get('_path_to_item', ())
386
- raise ApiValueError(
387
- "Cannot deserialize input data due to missing discriminator. "
388
- "The discriminator property '%s' is missing at path: %s" %
389
- (discr_propertyname_js, path_to_item)
390
- )
391
-
392
- # Implementation note: the last argument to get_discriminator_class
393
- # is a list of visited classes. get_discriminator_class may recursively
394
- # call itself and update the list of visited classes, and the initial
395
- # value must be an empty list. Hence not using 'visited_composed_classes'
396
- new_cls = get_discriminator_class(
397
- cls, discr_propertyname_py, discr_value, [])
398
- if new_cls is None:
399
- path_to_item = kwargs.get('_path_to_item', ())
400
- disc_prop_value = kwargs.get(
401
- discr_propertyname_js, kwargs.get(discr_propertyname_py))
402
- raise ApiValueError(
403
- "Cannot deserialize input data due to invalid discriminator "
404
- "value. The OpenAPI document has no mapping for discriminator "
405
- "property '%s'='%s' at path: %s" %
406
- (discr_propertyname_js, disc_prop_value, path_to_item)
407
- )
408
-
409
- if new_cls in visited_composed_classes:
410
- # if we are making an instance of a composed schema Descendent
411
- # which allOf includes Ancestor, then Ancestor contains
412
- # a discriminator that includes Descendent.
413
- # So if we make an instance of Descendent, we have to make an
414
- # instance of Ancestor to hold the allOf properties.
415
- # This code detects that use case and makes the instance of Ancestor
416
- # For example:
417
- # When making an instance of Dog, _visited_composed_classes = (Dog,)
418
- # then we make an instance of Animal to include in dog._composed_instances
419
- # so when we are here, cls is Animal
420
- # cls.discriminator != None
421
- # cls not in _visited_composed_classes
422
- # new_cls = Dog
423
- # but we know we know that we already have Dog
424
- # because it is in visited_composed_classes
425
- # so make Animal here
426
- return cls._from_openapi_data(*args, **kwargs)
427
-
428
- # Build a list containing all oneOf and anyOf descendants.
429
- oneof_anyof_classes = None
430
- if cls._composed_schemas is not None:
431
- oneof_anyof_classes = (
432
- cls._composed_schemas.get('oneOf', ()) +
433
- cls._composed_schemas.get('anyOf', ()))
434
- oneof_anyof_child = new_cls in oneof_anyof_classes
435
- kwargs['_visited_composed_classes'] = visited_composed_classes + (cls,)
436
-
437
- if cls._composed_schemas.get('allOf') and oneof_anyof_child:
438
- # Validate that we can make self because when we make the
439
- # new_cls it will not include the allOf validations in self
440
- self_inst = cls._from_openapi_data(*args, **kwargs)
441
-
442
- new_inst = new_cls._new_from_openapi_data(*args, **kwargs)
443
- return new_inst
444
-
445
-
446
- class ModelSimple(OpenApiModel):
447
- """the parent class of models whose type != object in their
448
- swagger/openapi"""
449
-
450
- def __setitem__(self, name, value):
451
- """set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
452
- if name in self.required_properties:
453
- self.__dict__[name] = value
454
- return
455
-
456
- self.set_attribute(name, value)
457
-
458
- def get(self, name, default=None):
459
- """returns the value of an attribute or some default value if the attribute was not set"""
460
- if name in self.required_properties:
461
- return self.__dict__[name]
462
-
463
- return self.__dict__['_data_store'].get(name, default)
464
-
465
- def __getitem__(self, name):
466
- """get the value of an attribute using square-bracket notation: `instance[attr]`"""
467
- if name in self:
468
- return self.get(name)
469
-
470
- raise ApiAttributeError(
471
- "{0} has no attribute '{1}'".format(
472
- type(self).__name__, name),
473
- [e for e in [self._path_to_item, name] if e]
474
- )
475
-
476
- def __contains__(self, name):
477
- """used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`"""
478
- if name in self.required_properties:
479
- return name in self.__dict__
480
-
481
- return name in self.__dict__['_data_store']
482
-
483
- def to_str(self):
484
- """Returns the string representation of the model"""
485
- return str(self.value)
486
-
487
- def __eq__(self, other):
488
- """Returns true if both objects are equal"""
489
- if not isinstance(other, self.__class__):
490
- return False
491
-
492
- this_val = self._data_store['value']
493
- that_val = other._data_store['value']
494
- types = set()
495
- types.add(this_val.__class__)
496
- types.add(that_val.__class__)
497
- vals_equal = this_val == that_val
498
- return vals_equal
499
-
500
-
501
- class ModelNormal(OpenApiModel):
502
- """the parent class of models whose type == object in their
503
- swagger/openapi"""
504
-
505
- def __setitem__(self, name, value):
506
- """set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
507
- if name in self.required_properties:
508
- self.__dict__[name] = value
509
- return
510
-
511
- self.set_attribute(name, value)
512
-
513
- def get(self, name, default=None):
514
- """returns the value of an attribute or some default value if the attribute was not set"""
515
- if name in self.required_properties:
516
- return self.__dict__[name]
517
-
518
- return self.__dict__['_data_store'].get(name, default)
519
-
520
- def __getitem__(self, name):
521
- """get the value of an attribute using square-bracket notation: `instance[attr]`"""
522
- if name in self:
523
- return self.get(name)
524
-
525
- raise ApiAttributeError(
526
- "{0} has no attribute '{1}'".format(
527
- type(self).__name__, name),
528
- [e for e in [self._path_to_item, name] if e]
529
- )
530
-
531
- def __contains__(self, name):
532
- """used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`"""
533
- if name in self.required_properties:
534
- return name in self.__dict__
535
-
536
- return name in self.__dict__['_data_store']
537
-
538
- def to_dict(self):
539
- """Returns the model properties as a dict"""
540
- return model_to_dict(self, serialize=False)
541
-
542
- def to_str(self):
543
- """Returns the string representation of the model"""
544
- return pprint.pformat(self.to_dict())
545
-
546
- def __eq__(self, other):
547
- """Returns true if both objects are equal"""
548
- if not isinstance(other, self.__class__):
549
- return False
550
-
551
- if not set(self._data_store.keys()) == set(other._data_store.keys()):
552
- return False
553
- for _var_name, this_val in self._data_store.items():
554
- that_val = other._data_store[_var_name]
555
- types = set()
556
- types.add(this_val.__class__)
557
- types.add(that_val.__class__)
558
- vals_equal = this_val == that_val
559
- if not vals_equal:
560
- return False
561
- return True
562
-
563
-
564
- class ModelComposed(OpenApiModel):
565
- """the parent class of models whose type == object in their
566
- swagger/openapi and have oneOf/allOf/anyOf
567
-
568
- When one sets a property we use var_name_to_model_instances to store the value in
569
- the correct class instances + run any type checking + validation code.
570
- When one gets a property we use var_name_to_model_instances to get the value
571
- from the correct class instances.
572
- This allows multiple composed schemas to contain the same property with additive
573
- constraints on the value.
574
-
575
- _composed_schemas (dict) stores the anyOf/allOf/oneOf classes
576
- key (str): allOf/oneOf/anyOf
577
- value (list): the classes in the XOf definition.
578
- Note: none_type can be included when the openapi document version >= 3.1.0
579
- _composed_instances (list): stores a list of instances of the composed schemas
580
- defined in _composed_schemas. When properties are accessed in the self instance,
581
- they are returned from the self._data_store or the data stores in the instances
582
- in self._composed_schemas
583
- _var_name_to_model_instances (dict): maps between a variable name on self and
584
- the composed instances (self included) which contain that data
585
- key (str): property name
586
- value (list): list of class instances, self or instances in _composed_instances
587
- which contain the value that the key is referring to.
588
- """
589
-
590
- def __setitem__(self, name, value):
591
- """set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
592
- if name in self.required_properties:
593
- self.__dict__[name] = value
594
- return
595
-
596
- """
597
- Use cases:
598
- 1. additional_properties_type is None (additionalProperties == False in spec)
599
- Check for property presence in self.openapi_types
600
- if not present then throw an error
601
- if present set in self, set attribute
602
- always set on composed schemas
603
- 2. additional_properties_type exists
604
- set attribute on self
605
- always set on composed schemas
606
- """
607
- if self.additional_properties_type is None:
608
- """
609
- For an attribute to exist on a composed schema it must:
610
- - fulfill schema_requirements in the self composed schema not considering oneOf/anyOf/allOf schemas AND
611
- - fulfill schema_requirements in each oneOf/anyOf/allOf schemas
612
-
613
- schema_requirements:
614
- For an attribute to exist on a schema it must:
615
- - be present in properties at the schema OR
616
- - have additionalProperties unset (defaults additionalProperties = any type) OR
617
- - have additionalProperties set
618
- """
619
- if name not in self.openapi_types:
620
- raise ApiAttributeError(
621
- "{0} has no attribute '{1}'".format(
622
- type(self).__name__, name),
623
- [e for e in [self._path_to_item, name] if e]
624
- )
625
- # attribute must be set on self and composed instances
626
- self.set_attribute(name, value)
627
- for model_instance in self._composed_instances:
628
- setattr(model_instance, name, value)
629
- if name not in self._var_name_to_model_instances:
630
- # we assigned an additional property
631
- self.__dict__['_var_name_to_model_instances'][name] = self._composed_instances + [self]
632
- return None
633
-
634
- __unset_attribute_value__ = object()
635
-
636
- def get(self, name, default=None):
637
- """returns the value of an attribute or some default value if the attribute was not set"""
638
- if name in self.required_properties:
639
- return self.__dict__[name]
640
-
641
- # get the attribute from the correct instance
642
- model_instances = self._var_name_to_model_instances.get(name)
643
- values = []
644
- # A composed model stores self and child (oneof/anyOf/allOf) models under
645
- # self._var_name_to_model_instances.
646
- # Any property must exist in self and all model instances
647
- # The value stored in all model instances must be the same
648
- if model_instances:
649
- for model_instance in model_instances:
650
- if name in model_instance._data_store:
651
- v = model_instance._data_store[name]
652
- if v not in values:
653
- values.append(v)
654
- len_values = len(values)
655
- if len_values == 0:
656
- return default
657
- elif len_values == 1:
658
- return values[0]
659
- elif len_values > 1:
660
- raise ApiValueError(
661
- "Values stored for property {0} in {1} differ when looking "
662
- "at self and self's composed instances. All values must be "
663
- "the same".format(name, type(self).__name__),
664
- [e for e in [self._path_to_item, name] if e]
665
- )
666
-
667
- def __getitem__(self, name):
668
- """get the value of an attribute using square-bracket notation: `instance[attr]`"""
669
- value = self.get(name, self.__unset_attribute_value__)
670
- if value is self.__unset_attribute_value__:
671
- raise ApiAttributeError(
672
- "{0} has no attribute '{1}'".format(
673
- type(self).__name__, name),
674
- [e for e in [self._path_to_item, name] if e]
675
- )
676
- return value
677
-
678
- def __contains__(self, name):
679
- """used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`"""
680
-
681
- if name in self.required_properties:
682
- return name in self.__dict__
683
-
684
- model_instances = self._var_name_to_model_instances.get(
685
- name, self._additional_properties_model_instances)
686
-
687
- if model_instances:
688
- for model_instance in model_instances:
689
- if name in model_instance._data_store:
690
- return True
691
-
692
- return False
693
-
694
- def to_dict(self):
695
- """Returns the model properties as a dict"""
696
- return model_to_dict(self, serialize=False)
697
-
698
- def to_str(self):
699
- """Returns the string representation of the model"""
700
- return pprint.pformat(self.to_dict())
701
-
702
- def __eq__(self, other):
703
- """Returns true if both objects are equal"""
704
- if not isinstance(other, self.__class__):
705
- return False
706
-
707
- if not set(self._data_store.keys()) == set(other._data_store.keys()):
708
- return False
709
- for _var_name, this_val in self._data_store.items():
710
- that_val = other._data_store[_var_name]
711
- types = set()
712
- types.add(this_val.__class__)
713
- types.add(that_val.__class__)
714
- vals_equal = this_val == that_val
715
- if not vals_equal:
716
- return False
717
- return True
718
-
719
-
720
- COERCION_INDEX_BY_TYPE = {
721
- ModelComposed: 0,
722
- ModelNormal: 1,
723
- ModelSimple: 2,
724
- none_type: 3, # The type of 'None'.
725
- list: 4,
726
- dict: 5,
727
- float: 6,
728
- int: 7,
729
- bool: 8,
730
- datetime: 9,
731
- date: 10,
732
- str: 11,
733
- file_type: 12, # 'file_type' is an alias for the built-in 'file' or 'io.IOBase' type.
734
- }
735
-
736
- # these are used to limit what type conversions we try to do
737
- # when we have a valid type already and we want to try converting
738
- # to another type
739
- UPCONVERSION_TYPE_PAIRS = (
740
- (str, datetime),
741
- (str, date),
742
- # A float may be serialized as an integer, e.g. '3' is a valid serialized float.
743
- (int, float),
744
- (list, ModelComposed),
745
- (dict, ModelComposed),
746
- (str, ModelComposed),
747
- (int, ModelComposed),
748
- (float, ModelComposed),
749
- (list, ModelComposed),
750
- (list, ModelNormal),
751
- (dict, ModelNormal),
752
- (str, ModelSimple),
753
- (int, ModelSimple),
754
- (float, ModelSimple),
755
- (list, ModelSimple),
756
- )
757
-
758
- COERCIBLE_TYPE_PAIRS = {
759
- False: ( # client instantiation of a model with client data
760
- # (dict, ModelComposed),
761
- # (list, ModelComposed),
762
- # (dict, ModelNormal),
763
- # (list, ModelNormal),
764
- # (str, ModelSimple),
765
- # (int, ModelSimple),
766
- # (float, ModelSimple),
767
- # (list, ModelSimple),
768
- # (str, int),
769
- # (str, float),
770
- # (str, datetime),
771
- # (str, date),
772
- # (int, str),
773
- # (float, str),
774
- ),
775
- True: ( # server -> client data
776
- (dict, ModelComposed),
777
- (list, ModelComposed),
778
- (dict, ModelNormal),
779
- (list, ModelNormal),
780
- (str, ModelSimple),
781
- (int, ModelSimple),
782
- (float, ModelSimple),
783
- (list, ModelSimple),
784
- # (str, int),
785
- # (str, float),
786
- (str, datetime),
787
- (str, date),
788
- # (int, str),
789
- # (float, str),
790
- (str, file_type)
791
- ),
792
- }
793
-
794
-
795
- def get_simple_class(input_value):
796
- """Returns an input_value's simple class that we will use for type checking
797
- Python2:
798
- float and int will return int, where int is the python3 int backport
799
- str and unicode will return str, where str is the python3 str backport
800
- Note: float and int ARE both instances of int backport
801
- Note: str_py2 and unicode_py2 are NOT both instances of str backport
802
-
803
- Args:
804
- input_value (class/class_instance): the item for which we will return
805
- the simple class
806
- """
807
- if isinstance(input_value, type):
808
- # input_value is a class
809
- return input_value
810
- elif isinstance(input_value, tuple):
811
- return tuple
812
- elif isinstance(input_value, list):
813
- return list
814
- elif isinstance(input_value, dict):
815
- return dict
816
- elif isinstance(input_value, none_type):
817
- return none_type
818
- elif isinstance(input_value, file_type):
819
- return file_type
820
- elif isinstance(input_value, bool):
821
- # this must be higher than the int check because
822
- # isinstance(True, int) == True
823
- return bool
824
- elif isinstance(input_value, int):
825
- return int
826
- elif isinstance(input_value, datetime):
827
- # this must be higher than the date check because
828
- # isinstance(datetime_instance, date) == True
829
- return datetime
830
- elif isinstance(input_value, date):
831
- return date
832
- elif isinstance(input_value, str):
833
- return str
834
- return type(input_value)
835
-
836
-
837
- def check_allowed_values(allowed_values, input_variable_path, input_values):
838
- """Raises an exception if the input_values are not allowed
839
-
840
- Args:
841
- allowed_values (dict): the allowed_values dict
842
- input_variable_path (tuple): the path to the input variable
843
- input_values (list/str/int/float/date/datetime): the values that we
844
- are checking to see if they are in allowed_values
845
- """
846
- these_allowed_values = list(allowed_values[input_variable_path].values())
847
- if (isinstance(input_values, list)
848
- and not set(input_values).issubset(
849
- set(these_allowed_values))):
850
- invalid_values = ", ".join(
851
- map(str, set(input_values) - set(these_allowed_values))),
852
- raise ApiValueError(
853
- "Invalid values for `%s` [%s], must be a subset of [%s]" %
854
- (
855
- input_variable_path[0],
856
- invalid_values,
857
- ", ".join(map(str, these_allowed_values))
858
- )
859
- )
860
- elif (isinstance(input_values, dict)
861
- and not set(
862
- input_values.keys()).issubset(set(these_allowed_values))):
863
- invalid_values = ", ".join(
864
- map(str, set(input_values.keys()) - set(these_allowed_values)))
865
- raise ApiValueError(
866
- "Invalid keys in `%s` [%s], must be a subset of [%s]" %
867
- (
868
- input_variable_path[0],
869
- invalid_values,
870
- ", ".join(map(str, these_allowed_values))
871
- )
872
- )
873
- elif (not isinstance(input_values, (list, dict))
874
- and input_values not in these_allowed_values):
875
- raise ApiValueError(
876
- "Invalid value for `%s` (%s), must be one of %s" %
877
- (
878
- input_variable_path[0],
879
- input_values,
880
- these_allowed_values
881
- )
882
- )
883
-
884
-
885
- def is_json_validation_enabled(schema_keyword, configuration=None):
886
- """Returns true if JSON schema validation is enabled for the specified
887
- validation keyword. This can be used to skip JSON schema structural validation
888
- as requested in the configuration.
889
-
890
- Args:
891
- schema_keyword (string): the name of a JSON schema validation keyword.
892
- configuration (Configuration): the configuration class.
893
- """
894
-
895
- return (configuration is None or
896
- not hasattr(configuration, '_disabled_client_side_validations') or
897
- schema_keyword not in configuration._disabled_client_side_validations)
898
-
899
-
900
- def check_validations(
901
- validations, input_variable_path, input_values,
902
- configuration=None):
903
- """Raises an exception if the input_values are invalid
904
-
905
- Args:
906
- validations (dict): the validation dictionary.
907
- input_variable_path (tuple): the path to the input variable.
908
- input_values (list/str/int/float/date/datetime): the values that we
909
- are checking.
910
- configuration (Configuration): the configuration class.
911
- """
912
-
913
- if input_values is None:
914
- return
915
-
916
- current_validations = validations[input_variable_path]
917
- if (is_json_validation_enabled('multipleOf', configuration) and
918
- 'multiple_of' in current_validations and
919
- isinstance(input_values, (int, float)) and
920
- not (float(input_values) / current_validations['multiple_of']).is_integer()):
921
- # Note 'multipleOf' will be as good as the floating point arithmetic.
922
- raise ApiValueError(
923
- "Invalid value for `%s`, value must be a multiple of "
924
- "`%s`" % (
925
- input_variable_path[0],
926
- current_validations['multiple_of']
927
- )
928
- )
929
-
930
- if (is_json_validation_enabled('maxLength', configuration) and
931
- 'max_length' in current_validations and
932
- len(input_values) > current_validations['max_length']):
933
- raise ApiValueError(
934
- "Invalid value for `%s`, length must be less than or equal to "
935
- "`%s`" % (
936
- input_variable_path[0],
937
- current_validations['max_length']
938
- )
939
- )
940
-
941
- if (is_json_validation_enabled('minLength', configuration) and
942
- 'min_length' in current_validations and
943
- len(input_values) < current_validations['min_length']):
944
- raise ApiValueError(
945
- "Invalid value for `%s`, length must be greater than or equal to "
946
- "`%s`" % (
947
- input_variable_path[0],
948
- current_validations['min_length']
949
- )
950
- )
951
-
952
- if (is_json_validation_enabled('maxItems', configuration) and
953
- 'max_items' in current_validations and
954
- len(input_values) > current_validations['max_items']):
955
- raise ApiValueError(
956
- "Invalid value for `%s`, number of items must be less than or "
957
- "equal to `%s`" % (
958
- input_variable_path[0],
959
- current_validations['max_items']
960
- )
961
- )
962
-
963
- if (is_json_validation_enabled('minItems', configuration) and
964
- 'min_items' in current_validations and
965
- len(input_values) < current_validations['min_items']):
966
- raise ValueError(
967
- "Invalid value for `%s`, number of items must be greater than or "
968
- "equal to `%s`" % (
969
- input_variable_path[0],
970
- current_validations['min_items']
971
- )
972
- )
973
-
974
- items = ('exclusive_maximum', 'inclusive_maximum', 'exclusive_minimum',
975
- 'inclusive_minimum')
976
- if (any(item in current_validations for item in items)):
977
- if isinstance(input_values, list):
978
- max_val = max(input_values)
979
- min_val = min(input_values)
980
- elif isinstance(input_values, dict):
981
- max_val = max(input_values.values())
982
- min_val = min(input_values.values())
983
- else:
984
- max_val = input_values
985
- min_val = input_values
986
-
987
- if (is_json_validation_enabled('exclusiveMaximum', configuration) and
988
- 'exclusive_maximum' in current_validations and
989
- max_val >= current_validations['exclusive_maximum']):
990
- raise ApiValueError(
991
- "Invalid value for `%s`, must be a value less than `%s`" % (
992
- input_variable_path[0],
993
- current_validations['exclusive_maximum']
994
- )
995
- )
996
-
997
- if (is_json_validation_enabled('maximum', configuration) and
998
- 'inclusive_maximum' in current_validations and
999
- max_val > current_validations['inclusive_maximum']):
1000
- raise ApiValueError(
1001
- "Invalid value for `%s`, must be a value less than or equal to "
1002
- "`%s`" % (
1003
- input_variable_path[0],
1004
- current_validations['inclusive_maximum']
1005
- )
1006
- )
1007
-
1008
- if (is_json_validation_enabled('exclusiveMinimum', configuration) and
1009
- 'exclusive_minimum' in current_validations and
1010
- min_val <= current_validations['exclusive_minimum']):
1011
- raise ApiValueError(
1012
- "Invalid value for `%s`, must be a value greater than `%s`" %
1013
- (
1014
- input_variable_path[0],
1015
- current_validations['exclusive_maximum']
1016
- )
1017
- )
1018
-
1019
- if (is_json_validation_enabled('minimum', configuration) and
1020
- 'inclusive_minimum' in current_validations and
1021
- min_val < current_validations['inclusive_minimum']):
1022
- raise ApiValueError(
1023
- "Invalid value for `%s`, must be a value greater than or equal "
1024
- "to `%s`" % (
1025
- input_variable_path[0],
1026
- current_validations['inclusive_minimum']
1027
- )
1028
- )
1029
- flags = current_validations.get('regex', {}).get('flags', 0)
1030
- if (is_json_validation_enabled('pattern', configuration) and
1031
- 'regex' in current_validations and
1032
- not re.search(current_validations['regex']['pattern'],
1033
- input_values, flags=flags)):
1034
- err_msg = r"Invalid value for `%s`, must match regular expression `%s`" % (
1035
- input_variable_path[0],
1036
- current_validations['regex']['pattern']
1037
- )
1038
- if flags != 0:
1039
- # Don't print the regex flags if the flags are not
1040
- # specified in the OAS document.
1041
- err_msg = r"%s with flags=`%s`" % (err_msg, flags)
1042
- raise ApiValueError(err_msg)
1043
-
1044
-
1045
- def order_response_types(required_types):
1046
- """Returns the required types sorted in coercion order
1047
-
1048
- Args:
1049
- required_types (list/tuple): collection of classes or instance of
1050
- list or dict with class information inside it.
1051
-
1052
- Returns:
1053
- (list): coercion order sorted collection of classes or instance
1054
- of list or dict with class information inside it.
1055
- """
1056
-
1057
- def index_getter(class_or_instance):
1058
- if isinstance(class_or_instance, list):
1059
- return COERCION_INDEX_BY_TYPE[list]
1060
- elif isinstance(class_or_instance, dict):
1061
- return COERCION_INDEX_BY_TYPE[dict]
1062
- elif (inspect.isclass(class_or_instance)
1063
- and issubclass(class_or_instance, ModelComposed)):
1064
- return COERCION_INDEX_BY_TYPE[ModelComposed]
1065
- elif (inspect.isclass(class_or_instance)
1066
- and issubclass(class_or_instance, ModelNormal)):
1067
- return COERCION_INDEX_BY_TYPE[ModelNormal]
1068
- elif (inspect.isclass(class_or_instance)
1069
- and issubclass(class_or_instance, ModelSimple)):
1070
- return COERCION_INDEX_BY_TYPE[ModelSimple]
1071
- elif class_or_instance in COERCION_INDEX_BY_TYPE:
1072
- return COERCION_INDEX_BY_TYPE[class_or_instance]
1073
- raise ApiValueError("Unsupported type: %s" % class_or_instance)
1074
-
1075
- sorted_types = sorted(
1076
- required_types,
1077
- key=lambda class_or_instance: index_getter(class_or_instance)
1078
- )
1079
- return sorted_types
1080
-
1081
-
1082
- def remove_uncoercible(required_types_classes, current_item, spec_property_naming,
1083
- must_convert=True):
1084
- """Only keeps the type conversions that are possible
1085
-
1086
- Args:
1087
- required_types_classes (tuple): tuple of classes that are required
1088
- these should be ordered by COERCION_INDEX_BY_TYPE
1089
- spec_property_naming (bool): True if the variable names in the input
1090
- data are serialized names as specified in the OpenAPI document.
1091
- False if the variables names in the input data are python
1092
- variable names in PEP-8 snake case.
1093
- current_item (any): the current item (input data) to be converted
1094
-
1095
- Keyword Args:
1096
- must_convert (bool): if True the item to convert is of the wrong
1097
- type and we want a big list of coercibles
1098
- if False, we want a limited list of coercibles
1099
-
1100
- Returns:
1101
- (list): the remaining coercible required types, classes only
1102
- """
1103
- current_type_simple = get_simple_class(current_item)
1104
-
1105
- results_classes = []
1106
- for required_type_class in required_types_classes:
1107
- # convert our models to OpenApiModel
1108
- required_type_class_simplified = required_type_class
1109
- if isinstance(required_type_class_simplified, type):
1110
- if issubclass(required_type_class_simplified, ModelComposed):
1111
- required_type_class_simplified = ModelComposed
1112
- elif issubclass(required_type_class_simplified, ModelNormal):
1113
- required_type_class_simplified = ModelNormal
1114
- elif issubclass(required_type_class_simplified, ModelSimple):
1115
- required_type_class_simplified = ModelSimple
1116
-
1117
- if required_type_class_simplified == current_type_simple:
1118
- # don't consider converting to one's own class
1119
- continue
1120
-
1121
- class_pair = (current_type_simple, required_type_class_simplified)
1122
- if must_convert and class_pair in COERCIBLE_TYPE_PAIRS[spec_property_naming]:
1123
- results_classes.append(required_type_class)
1124
- elif class_pair in UPCONVERSION_TYPE_PAIRS:
1125
- results_classes.append(required_type_class)
1126
- return results_classes
1127
-
1128
-
1129
- def get_discriminated_classes(cls):
1130
- """
1131
- Returns all the classes that a discriminator converts to
1132
- TODO: lru_cache this
1133
- """
1134
- possible_classes = []
1135
- key = list(cls.discriminator.keys())[0]
1136
- if is_type_nullable(cls):
1137
- possible_classes.append(cls)
1138
- for discr_cls in cls.discriminator[key].values():
1139
- if hasattr(discr_cls, 'discriminator') and discr_cls.discriminator is not None:
1140
- possible_classes.extend(get_discriminated_classes(discr_cls))
1141
- else:
1142
- possible_classes.append(discr_cls)
1143
- return possible_classes
1144
-
1145
-
1146
- def get_possible_classes(cls, from_server_context):
1147
- # TODO: lru_cache this
1148
- possible_classes = [cls]
1149
- if from_server_context:
1150
- return possible_classes
1151
- if hasattr(cls, 'discriminator') and cls.discriminator is not None:
1152
- possible_classes = []
1153
- possible_classes.extend(get_discriminated_classes(cls))
1154
- elif issubclass(cls, ModelComposed):
1155
- possible_classes.extend(composed_model_input_classes(cls))
1156
- return possible_classes
1157
-
1158
-
1159
- def get_required_type_classes(required_types_mixed, spec_property_naming):
1160
- """Converts the tuple required_types into a tuple and a dict described
1161
- below
1162
-
1163
- Args:
1164
- required_types_mixed (tuple/list): will contain either classes or
1165
- instance of list or dict
1166
- spec_property_naming (bool): if True these values came from the
1167
- server, and we use the data types in our endpoints.
1168
- If False, we are client side and we need to include
1169
- oneOf and discriminator classes inside the data types in our endpoints
1170
-
1171
- Returns:
1172
- (valid_classes, dict_valid_class_to_child_types_mixed):
1173
- valid_classes (tuple): the valid classes that the current item
1174
- should be
1175
- dict_valid_class_to_child_types_mixed (dict):
1176
- valid_class (class): this is the key
1177
- child_types_mixed (list/dict/tuple): describes the valid child
1178
- types
1179
- """
1180
- valid_classes = []
1181
- child_req_types_by_current_type = {}
1182
- for required_type in required_types_mixed:
1183
- if isinstance(required_type, list):
1184
- valid_classes.append(list)
1185
- child_req_types_by_current_type[list] = required_type
1186
- elif isinstance(required_type, tuple):
1187
- valid_classes.append(tuple)
1188
- child_req_types_by_current_type[tuple] = required_type
1189
- elif isinstance(required_type, dict):
1190
- valid_classes.append(dict)
1191
- child_req_types_by_current_type[dict] = required_type[str]
1192
- else:
1193
- valid_classes.extend(get_possible_classes(required_type, spec_property_naming))
1194
- return tuple(valid_classes), child_req_types_by_current_type
1195
-
1196
-
1197
- def change_keys_js_to_python(input_dict, model_class):
1198
- """
1199
- Converts from javascript_key keys in the input_dict to python_keys in
1200
- the output dict using the mapping in model_class.
1201
- If the input_dict contains a key which does not declared in the model_class,
1202
- the key is added to the output dict as is. The assumption is the model_class
1203
- may have undeclared properties (additionalProperties attribute in the OAS
1204
- document).
1205
- """
1206
-
1207
- if getattr(model_class, 'attribute_map', None) is None:
1208
- return input_dict
1209
- output_dict = {}
1210
- reversed_attr_map = {value: key for key, value in
1211
- model_class.attribute_map.items()}
1212
- for javascript_key, value in input_dict.items():
1213
- python_key = reversed_attr_map.get(javascript_key)
1214
- if python_key is None:
1215
- # if the key is unknown, it is in error or it is an
1216
- # additionalProperties variable
1217
- python_key = javascript_key
1218
- output_dict[python_key] = value
1219
- return output_dict
1220
-
1221
-
1222
- def get_type_error(var_value, path_to_item, valid_classes, key_type=False):
1223
- error_msg = type_error_message(
1224
- var_name=path_to_item[-1],
1225
- var_value=var_value,
1226
- valid_classes=valid_classes,
1227
- key_type=key_type
1228
- )
1229
- return ApiTypeError(
1230
- error_msg,
1231
- path_to_item=path_to_item,
1232
- valid_classes=valid_classes,
1233
- key_type=key_type
1234
- )
1235
-
1236
-
1237
- def deserialize_primitive(data, klass, path_to_item):
1238
- """Deserializes string to primitive type.
1239
-
1240
- :param data: str/int/float
1241
- :param klass: str/class the class to convert to
1242
-
1243
- :return: int, float, str, bool, date, datetime
1244
- """
1245
- additional_message = ""
1246
- try:
1247
- if klass in {datetime, date}:
1248
- additional_message = (
1249
- "If you need your parameter to have a fallback "
1250
- "string value, please set its type as `type: {}` in your "
1251
- "spec. That allows the value to be any type. "
1252
- )
1253
- if klass == datetime:
1254
- if len(data) < 8:
1255
- raise ValueError("This is not a datetime")
1256
- # The string should be in iso8601 datetime format.
1257
- parsed_datetime = parse(data)
1258
- date_only = (
1259
- parsed_datetime.hour == 0 and
1260
- parsed_datetime.minute == 0 and
1261
- parsed_datetime.second == 0 and
1262
- parsed_datetime.tzinfo is None and
1263
- 8 <= len(data) <= 10
1264
- )
1265
- if date_only:
1266
- raise ValueError("This is a date, not a datetime")
1267
- return parsed_datetime
1268
- elif klass == date:
1269
- if len(data) < 8:
1270
- raise ValueError("This is not a date")
1271
- return parse(data).date()
1272
- else:
1273
- converted_value = klass(data)
1274
- if isinstance(data, str) and klass == float:
1275
- if str(converted_value) != data:
1276
- # '7' -> 7.0 -> '7.0' != '7'
1277
- raise ValueError('This is not a float')
1278
- return converted_value
1279
- except (OverflowError, ValueError) as ex:
1280
- # parse can raise OverflowError
1281
- raise ApiValueError(
1282
- "{0}Failed to parse {1} as {2}".format(
1283
- additional_message, repr(data), klass.__name__
1284
- ),
1285
- path_to_item=path_to_item
1286
- ) from ex
1287
-
1288
-
1289
- def get_discriminator_class(model_class,
1290
- discr_name,
1291
- discr_value, cls_visited):
1292
- """Returns the child class specified by the discriminator.
1293
-
1294
- Args:
1295
- model_class (OpenApiModel): the model class.
1296
- discr_name (string): the name of the discriminator property.
1297
- discr_value (any): the discriminator value.
1298
- cls_visited (list): list of model classes that have been visited.
1299
- Used to determine the discriminator class without
1300
- visiting circular references indefinitely.
1301
-
1302
- Returns:
1303
- used_model_class (class/None): the chosen child class that will be used
1304
- to deserialize the data, for example dog.Dog.
1305
- If a class is not found, None is returned.
1306
- """
1307
-
1308
- if model_class in cls_visited:
1309
- # The class has already been visited and no suitable class was found.
1310
- return None
1311
- cls_visited.append(model_class)
1312
- used_model_class = None
1313
- if discr_name in model_class.discriminator:
1314
- class_name_to_discr_class = model_class.discriminator[discr_name]
1315
- used_model_class = class_name_to_discr_class.get(discr_value)
1316
- if used_model_class is None:
1317
- # We didn't find a discriminated class in class_name_to_discr_class.
1318
- # So look in the ancestor or descendant discriminators
1319
- # The discriminator mapping may exist in a descendant (anyOf, oneOf)
1320
- # or ancestor (allOf).
1321
- # Ancestor example: in the GrandparentAnimal -> ParentPet -> ChildCat
1322
- # hierarchy, the discriminator mappings may be defined at any level
1323
- # in the hierarchy.
1324
- # Descendant example: mammal -> whale/zebra/Pig -> BasquePig/DanishPig
1325
- # if we try to make BasquePig from mammal, we need to travel through
1326
- # the oneOf descendant discriminators to find BasquePig
1327
- descendant_classes = model_class._composed_schemas.get('oneOf', ()) + \
1328
- model_class._composed_schemas.get('anyOf', ())
1329
- ancestor_classes = model_class._composed_schemas.get('allOf', ())
1330
- possible_classes = descendant_classes + ancestor_classes
1331
- for cls in possible_classes:
1332
- # Check if the schema has inherited discriminators.
1333
- if hasattr(cls, 'discriminator') and cls.discriminator is not None:
1334
- used_model_class = get_discriminator_class(
1335
- cls, discr_name, discr_value, cls_visited)
1336
- if used_model_class is not None:
1337
- return used_model_class
1338
- return used_model_class
1339
-
1340
-
1341
- def deserialize_model(model_data, model_class, path_to_item, check_type,
1342
- configuration, spec_property_naming):
1343
- """Deserializes model_data to model instance.
1344
-
1345
- Args:
1346
- model_data (int/str/float/bool/none_type/list/dict): data to instantiate the model
1347
- model_class (OpenApiModel): the model class
1348
- path_to_item (list): path to the model in the received data
1349
- check_type (bool): whether to check the data tupe for the values in
1350
- the model
1351
- configuration (Configuration): the instance to use to convert files
1352
- spec_property_naming (bool): True if the variable names in the input
1353
- data are serialized names as specified in the OpenAPI document.
1354
- False if the variables names in the input data are python
1355
- variable names in PEP-8 snake case.
1356
-
1357
- Returns:
1358
- model instance
1359
-
1360
- Raise:
1361
- ApiTypeError
1362
- ApiValueError
1363
- ApiKeyError
1364
- """
1365
-
1366
- kw_args = dict(_check_type=check_type,
1367
- _path_to_item=path_to_item,
1368
- _configuration=configuration,
1369
- _spec_property_naming=spec_property_naming)
1370
-
1371
- if issubclass(model_class, ModelSimple):
1372
- return model_class._new_from_openapi_data(model_data, **kw_args)
1373
- elif isinstance(model_data, list):
1374
- return model_class._new_from_openapi_data(*model_data, **kw_args)
1375
- if isinstance(model_data, dict):
1376
- kw_args.update(model_data)
1377
- return model_class._new_from_openapi_data(**kw_args)
1378
- elif isinstance(model_data, PRIMITIVE_TYPES):
1379
- return model_class._new_from_openapi_data(model_data, **kw_args)
1380
-
1381
-
1382
- def deserialize_file(response_data, configuration, content_disposition=None):
1383
- """Deserializes body to file
1384
-
1385
- Saves response body into a file in a temporary folder,
1386
- using the filename from the `Content-Disposition` header if provided.
1387
-
1388
- Args:
1389
- param response_data (str): the file data to write
1390
- configuration (Configuration): the instance to use to convert files
1391
-
1392
- Keyword Args:
1393
- content_disposition (str): the value of the Content-Disposition
1394
- header
1395
-
1396
- Returns:
1397
- (file_type): the deserialized file which is open
1398
- The user is responsible for closing and reading the file
1399
- """
1400
- fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path)
1401
- os.close(fd)
1402
- os.remove(path)
1403
-
1404
- if content_disposition:
1405
- filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
1406
- content_disposition,
1407
- flags=re.I)
1408
- if filename is not None:
1409
- filename = filename.group(1)
1410
- else:
1411
- filename = "default_" + str(uuid.uuid4())
1412
-
1413
- path = os.path.join(os.path.dirname(path), filename)
1414
-
1415
- with open(path, "wb") as f:
1416
- if isinstance(response_data, str):
1417
- # change str to bytes so we can write it
1418
- response_data = response_data.encode('utf-8')
1419
- f.write(response_data)
1420
-
1421
- f = open(path, "rb")
1422
- return f
1423
-
1424
-
1425
- def attempt_convert_item(input_value, valid_classes, path_to_item,
1426
- configuration, spec_property_naming, key_type=False,
1427
- must_convert=False, check_type=True):
1428
- """
1429
- Args:
1430
- input_value (any): the data to convert
1431
- valid_classes (any): the classes that are valid
1432
- path_to_item (list): the path to the item to convert
1433
- configuration (Configuration): the instance to use to convert files
1434
- spec_property_naming (bool): True if the variable names in the input
1435
- data are serialized names as specified in the OpenAPI document.
1436
- False if the variables names in the input data are python
1437
- variable names in PEP-8 snake case.
1438
- key_type (bool): if True we need to convert a key type (not supported)
1439
- must_convert (bool): if True we must convert
1440
- check_type (bool): if True we check the type or the returned data in
1441
- ModelComposed/ModelNormal/ModelSimple instances
1442
-
1443
- Returns:
1444
- instance (any) the fixed item
1445
-
1446
- Raises:
1447
- ApiTypeError
1448
- ApiValueError
1449
- ApiKeyError
1450
- """
1451
- valid_classes_ordered = order_response_types(valid_classes)
1452
- valid_classes_coercible = remove_uncoercible(
1453
- valid_classes_ordered, input_value, spec_property_naming)
1454
- if not valid_classes_coercible or key_type:
1455
- # we do not handle keytype errors, json will take care
1456
- # of this for us
1457
- if configuration is None or not configuration.discard_unknown_keys:
1458
- raise get_type_error(input_value, path_to_item, valid_classes,
1459
- key_type=key_type)
1460
- for valid_class in valid_classes_coercible:
1461
- try:
1462
- if issubclass(valid_class, OpenApiModel):
1463
- return deserialize_model(input_value, valid_class,
1464
- path_to_item, check_type,
1465
- configuration, spec_property_naming)
1466
- elif valid_class == file_type:
1467
- return deserialize_file(input_value, configuration)
1468
- return deserialize_primitive(input_value, valid_class,
1469
- path_to_item)
1470
- except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc:
1471
- if must_convert:
1472
- raise conversion_exc
1473
- # if we have conversion errors when must_convert == False
1474
- # we ignore the exception and move on to the next class
1475
- continue
1476
- # we were unable to convert, must_convert == False
1477
- return input_value
1478
-
1479
-
1480
- def is_type_nullable(input_type):
1481
- """
1482
- Returns true if None is an allowed value for the specified input_type.
1483
-
1484
- A type is nullable if at least one of the following conditions is true:
1485
- 1. The OAS 'nullable' attribute has been specified,
1486
- 1. The type is the 'null' type,
1487
- 1. The type is a anyOf/oneOf composed schema, and a child schema is
1488
- the 'null' type.
1489
- Args:
1490
- input_type (type): the class of the input_value that we are
1491
- checking
1492
- Returns:
1493
- bool
1494
- """
1495
- if input_type is none_type:
1496
- return True
1497
- if issubclass(input_type, OpenApiModel) and input_type._nullable:
1498
- return True
1499
- if issubclass(input_type, ModelComposed):
1500
- # If oneOf/anyOf, check if the 'null' type is one of the allowed types.
1501
- for t in input_type._composed_schemas.get('oneOf', ()):
1502
- if is_type_nullable(t):
1503
- return True
1504
- for t in input_type._composed_schemas.get('anyOf', ()):
1505
- if is_type_nullable(t):
1506
- return True
1507
- return False
1508
-
1509
-
1510
- def is_valid_type(input_class_simple, valid_classes):
1511
- """
1512
- Args:
1513
- input_class_simple (class): the class of the input_value that we are
1514
- checking
1515
- valid_classes (tuple): the valid classes that the current item
1516
- should be
1517
- Returns:
1518
- bool
1519
- """
1520
- if issubclass(input_class_simple, OpenApiModel) and \
1521
- valid_classes == (bool, date, datetime, dict, float, int, list, str, none_type,):
1522
- return True
1523
- valid_type = input_class_simple in valid_classes
1524
- if not valid_type and (
1525
- issubclass(input_class_simple, OpenApiModel) or
1526
- input_class_simple is none_type):
1527
- for valid_class in valid_classes:
1528
- if input_class_simple is none_type and is_type_nullable(valid_class):
1529
- # Schema is oneOf/anyOf and the 'null' type is one of the allowed types.
1530
- return True
1531
- if not (issubclass(valid_class, OpenApiModel) and valid_class.discriminator):
1532
- continue
1533
- discr_propertyname_py = list(valid_class.discriminator.keys())[0]
1534
- discriminator_classes = (
1535
- valid_class.discriminator[discr_propertyname_py].values()
1536
- )
1537
- valid_type = is_valid_type(input_class_simple, discriminator_classes)
1538
- if valid_type:
1539
- return True
1540
- return valid_type
1541
-
1542
-
1543
- def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
1544
- spec_property_naming, _check_type, configuration=None):
1545
- """Raises a TypeError is there is a problem, otherwise returns value
1546
-
1547
- Args:
1548
- input_value (any): the data to validate/convert
1549
- required_types_mixed (list/dict/tuple): A list of
1550
- valid classes, or a list tuples of valid classes, or a dict where
1551
- the value is a tuple of value classes
1552
- path_to_item: (list) the path to the data being validated
1553
- this stores a list of keys or indices to get to the data being
1554
- validated
1555
- spec_property_naming (bool): True if the variable names in the input
1556
- data are serialized names as specified in the OpenAPI document.
1557
- False if the variables names in the input data are python
1558
- variable names in PEP-8 snake case.
1559
- _check_type: (boolean) if true, type will be checked and conversion
1560
- will be attempted.
1561
- configuration: (Configuration): the configuration class to use
1562
- when converting file_type items.
1563
- If passed, conversion will be attempted when possible
1564
- If not passed, no conversions will be attempted and
1565
- exceptions will be raised
1566
-
1567
- Returns:
1568
- the correctly typed value
1569
-
1570
- Raises:
1571
- ApiTypeError
1572
- """
1573
- results = get_required_type_classes(required_types_mixed, spec_property_naming)
1574
- valid_classes, child_req_types_by_current_type = results
1575
-
1576
- input_class_simple = get_simple_class(input_value)
1577
- valid_type = is_valid_type(input_class_simple, valid_classes)
1578
- if not valid_type:
1579
- if (configuration
1580
- or (input_class_simple == dict
1581
- and dict not in valid_classes)):
1582
- # if input_value is not valid_type try to convert it
1583
- converted_instance = attempt_convert_item(
1584
- input_value,
1585
- valid_classes,
1586
- path_to_item,
1587
- configuration,
1588
- spec_property_naming,
1589
- key_type=False,
1590
- must_convert=True,
1591
- check_type=_check_type
1592
- )
1593
- return converted_instance
1594
- else:
1595
- raise get_type_error(input_value, path_to_item, valid_classes,
1596
- key_type=False)
1597
-
1598
- # input_value's type is in valid_classes
1599
- if len(valid_classes) > 1 and configuration:
1600
- # there are valid classes which are not the current class
1601
- valid_classes_coercible = remove_uncoercible(
1602
- valid_classes, input_value, spec_property_naming, must_convert=False)
1603
- if valid_classes_coercible:
1604
- converted_instance = attempt_convert_item(
1605
- input_value,
1606
- valid_classes_coercible,
1607
- path_to_item,
1608
- configuration,
1609
- spec_property_naming,
1610
- key_type=False,
1611
- must_convert=False,
1612
- check_type=_check_type
1613
- )
1614
- return converted_instance
1615
-
1616
- if child_req_types_by_current_type == {}:
1617
- # all types are of the required types and there are no more inner
1618
- # variables left to look at
1619
- return input_value
1620
- inner_required_types = child_req_types_by_current_type.get(
1621
- type(input_value)
1622
- )
1623
- if inner_required_types is None:
1624
- # for this type, there are not more inner variables left to look at
1625
- return input_value
1626
- if isinstance(input_value, list):
1627
- if input_value == []:
1628
- # allow an empty list
1629
- return input_value
1630
- for index, inner_value in enumerate(input_value):
1631
- inner_path = list(path_to_item)
1632
- inner_path.append(index)
1633
- input_value[index] = validate_and_convert_types(
1634
- inner_value,
1635
- inner_required_types,
1636
- inner_path,
1637
- spec_property_naming,
1638
- _check_type,
1639
- configuration=configuration
1640
- )
1641
- elif isinstance(input_value, dict):
1642
- if input_value == {}:
1643
- # allow an empty dict
1644
- return input_value
1645
- for inner_key, inner_val in input_value.items():
1646
- inner_path = list(path_to_item)
1647
- inner_path.append(inner_key)
1648
- if get_simple_class(inner_key) != str:
1649
- raise get_type_error(inner_key, inner_path, valid_classes,
1650
- key_type=True)
1651
- input_value[inner_key] = validate_and_convert_types(
1652
- inner_val,
1653
- inner_required_types,
1654
- inner_path,
1655
- spec_property_naming,
1656
- _check_type,
1657
- configuration=configuration
1658
- )
1659
- return input_value
1660
-
1661
-
1662
- def model_to_dict(model_instance, serialize=True):
1663
- """Returns the model properties as a dict
1664
-
1665
- Args:
1666
- model_instance (one of your model instances): the model instance that
1667
- will be converted to a dict.
1668
-
1669
- Keyword Args:
1670
- serialize (bool): if True, the keys in the dict will be values from
1671
- attribute_map
1672
- """
1673
- result = {}
1674
-
1675
- def extract_item(item): return (
1676
- item[0], model_to_dict(
1677
- item[1], serialize=serialize)) if hasattr(
1678
- item[1], '_data_store') else item
1679
-
1680
- model_instances = [model_instance]
1681
- if model_instance._composed_schemas:
1682
- model_instances.extend(model_instance._composed_instances)
1683
- seen_json_attribute_names = set()
1684
- used_fallback_python_attribute_names = set()
1685
- py_to_json_map = {}
1686
- for model_instance in model_instances:
1687
- for attr, value in model_instance._data_store.items():
1688
- if serialize:
1689
- # we use get here because additional property key names do not
1690
- # exist in attribute_map
1691
- try:
1692
- attr = model_instance.attribute_map[attr]
1693
- py_to_json_map.update(model_instance.attribute_map)
1694
- seen_json_attribute_names.add(attr)
1695
- except KeyError:
1696
- used_fallback_python_attribute_names.add(attr)
1697
- if isinstance(value, list):
1698
- if not value:
1699
- # empty list or None
1700
- result[attr] = value
1701
- else:
1702
- res = []
1703
- for v in value:
1704
- if isinstance(v, PRIMITIVE_TYPES) or v is None:
1705
- res.append(v)
1706
- elif isinstance(v, ModelSimple):
1707
- res.append(v.value)
1708
- elif isinstance(v, dict):
1709
- res.append(dict(map(
1710
- extract_item,
1711
- v.items()
1712
- )))
1713
- else:
1714
- res.append(model_to_dict(v, serialize=serialize))
1715
- result[attr] = res
1716
- elif isinstance(value, dict):
1717
- result[attr] = dict(map(
1718
- extract_item,
1719
- value.items()
1720
- ))
1721
- elif isinstance(value, ModelSimple):
1722
- result[attr] = value.value
1723
- elif hasattr(value, '_data_store'):
1724
- result[attr] = model_to_dict(value, serialize=serialize)
1725
- else:
1726
- result[attr] = value
1727
- if serialize:
1728
- for python_key in used_fallback_python_attribute_names:
1729
- json_key = py_to_json_map.get(python_key)
1730
- if json_key is None:
1731
- continue
1732
- if python_key == json_key:
1733
- continue
1734
- json_key_assigned_no_need_for_python_key = json_key in seen_json_attribute_names
1735
- if json_key_assigned_no_need_for_python_key:
1736
- del result[python_key]
1737
-
1738
- return result
1739
-
1740
-
1741
- def type_error_message(var_value=None, var_name=None, valid_classes=None,
1742
- key_type=None):
1743
- """
1744
- Keyword Args:
1745
- var_value (any): the variable which has the type_error
1746
- var_name (str): the name of the variable which has the typ error
1747
- valid_classes (tuple): the accepted classes for current_item's
1748
- value
1749
- key_type (bool): False if our value is a value in a dict
1750
- True if it is a key in a dict
1751
- False if our item is an item in a list
1752
- """
1753
- key_or_value = 'value'
1754
- if key_type:
1755
- key_or_value = 'key'
1756
- valid_classes_phrase = get_valid_classes_phrase(valid_classes)
1757
- msg = (
1758
- "Invalid type for variable '{0}'. Required {1} type {2} and "
1759
- "passed type was {3}".format(
1760
- var_name,
1761
- key_or_value,
1762
- valid_classes_phrase,
1763
- type(var_value).__name__,
1764
- )
1765
- )
1766
- return msg
1767
-
1768
-
1769
- def get_valid_classes_phrase(input_classes):
1770
- """Returns a string phrase describing what types are allowed
1771
- """
1772
- all_classes = list(input_classes)
1773
- all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
1774
- all_class_names = [cls.__name__ for cls in all_classes]
1775
- if len(all_class_names) == 1:
1776
- return 'is {0}'.format(all_class_names[0])
1777
- return "is one of [{0}]".format(", ".join(all_class_names))
1778
-
1779
-
1780
- def get_allof_instances(self, model_args, constant_args):
1781
- """
1782
- Args:
1783
- self: the class we are handling
1784
- model_args (dict): var_name to var_value
1785
- used to make instances
1786
- constant_args (dict):
1787
- metadata arguments:
1788
- _check_type
1789
- _path_to_item
1790
- _spec_property_naming
1791
- _configuration
1792
- _visited_composed_classes
1793
-
1794
- Returns
1795
- composed_instances (list)
1796
- """
1797
- composed_instances = []
1798
- for allof_class in self._composed_schemas['allOf']:
1799
-
1800
- try:
1801
- if constant_args.get('_spec_property_naming'):
1802
- allof_instance = allof_class._from_openapi_data(**model_args, **constant_args)
1803
- else:
1804
- allof_instance = allof_class(**model_args, **constant_args)
1805
- composed_instances.append(allof_instance)
1806
- except Exception as ex:
1807
- raise ApiValueError(
1808
- "Invalid inputs given to generate an instance of '%s'. The "
1809
- "input data was invalid for the allOf schema '%s' in the composed "
1810
- "schema '%s'. Error=%s" % (
1811
- allof_class.__name__,
1812
- allof_class.__name__,
1813
- self.__class__.__name__,
1814
- str(ex)
1815
- )
1816
- ) from ex
1817
- return composed_instances
1818
-
1819
-
1820
- def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
1821
- """
1822
- Find the oneOf schema that matches the input data (e.g. payload).
1823
- If exactly one schema matches the input data, an instance of that schema
1824
- is returned.
1825
- If zero or more than one schema match the input data, an exception is raised.
1826
- In OAS 3.x, the payload MUST, by validation, match exactly one of the
1827
- schemas described by oneOf.
1828
-
1829
- Args:
1830
- cls: the class we are handling
1831
- model_kwargs (dict): var_name to var_value
1832
- The input data, e.g. the payload that must match a oneOf schema
1833
- in the OpenAPI document.
1834
- constant_kwargs (dict): var_name to var_value
1835
- args that every model requires, including configuration, server
1836
- and path to item.
1837
-
1838
- Kwargs:
1839
- model_arg: (int, float, bool, str, date, datetime, ModelSimple, None):
1840
- the value to assign to a primitive class or ModelSimple class
1841
- Notes:
1842
- - this is only passed in when oneOf includes types which are not object
1843
- - None is used to suppress handling of model_arg, nullable models are handled in __new__
1844
-
1845
- Returns
1846
- oneof_instance (instance)
1847
- """
1848
- if len(cls._composed_schemas['oneOf']) == 0:
1849
- return None
1850
-
1851
- oneof_instances = []
1852
- # Iterate over each oneOf schema and determine if the input data
1853
- # matches the oneOf schemas.
1854
- for oneof_class in cls._composed_schemas['oneOf']:
1855
- # The composed oneOf schema allows the 'null' type and the input data
1856
- # is the null value. This is a OAS >= 3.1 feature.
1857
- if oneof_class is none_type:
1858
- # skip none_types because we are deserializing dict data.
1859
- # none_type deserialization is handled in the __new__ method
1860
- continue
1861
-
1862
- single_value_input = allows_single_value_input(oneof_class)
1863
-
1864
- try:
1865
- if not single_value_input:
1866
- if constant_kwargs.get('_spec_property_naming'):
1867
- oneof_instance = oneof_class._from_openapi_data(
1868
- **model_kwargs, **constant_kwargs)
1869
- else:
1870
- oneof_instance = oneof_class(**model_kwargs, **constant_kwargs)
1871
- else:
1872
- if issubclass(oneof_class, ModelSimple):
1873
- if constant_kwargs.get('_spec_property_naming'):
1874
- oneof_instance = oneof_class._from_openapi_data(
1875
- model_arg, **constant_kwargs)
1876
- else:
1877
- oneof_instance = oneof_class(model_arg, **constant_kwargs)
1878
- elif oneof_class in PRIMITIVE_TYPES:
1879
- oneof_instance = validate_and_convert_types(
1880
- model_arg,
1881
- (oneof_class,),
1882
- constant_kwargs['_path_to_item'],
1883
- constant_kwargs['_spec_property_naming'],
1884
- constant_kwargs['_check_type'],
1885
- configuration=constant_kwargs['_configuration']
1886
- )
1887
- oneof_instances.append(oneof_instance)
1888
- except Exception:
1889
- pass
1890
- if len(oneof_instances) == 0:
1891
- raise ApiValueError(
1892
- "Invalid inputs given to generate an instance of %s. None "
1893
- "of the oneOf schemas matched the input data." %
1894
- cls.__name__
1895
- )
1896
- elif len(oneof_instances) > 1:
1897
- raise ApiValueError(
1898
- "Invalid inputs given to generate an instance of %s. Multiple "
1899
- "oneOf schemas matched the inputs, but a max of one is allowed." %
1900
- cls.__name__
1901
- )
1902
- return oneof_instances[0]
1903
-
1904
-
1905
- def get_anyof_instances(self, model_args, constant_args):
1906
- """
1907
- Args:
1908
- self: the class we are handling
1909
- model_args (dict): var_name to var_value
1910
- The input data, e.g. the payload that must match at least one
1911
- anyOf child schema in the OpenAPI document.
1912
- constant_args (dict): var_name to var_value
1913
- args that every model requires, including configuration, server
1914
- and path to item.
1915
-
1916
- Returns
1917
- anyof_instances (list)
1918
- """
1919
- anyof_instances = []
1920
- if len(self._composed_schemas['anyOf']) == 0:
1921
- return anyof_instances
1922
-
1923
- for anyof_class in self._composed_schemas['anyOf']:
1924
- # The composed oneOf schema allows the 'null' type and the input data
1925
- # is the null value. This is a OAS >= 3.1 feature.
1926
- if anyof_class is none_type:
1927
- # skip none_types because we are deserializing dict data.
1928
- # none_type deserialization is handled in the __new__ method
1929
- continue
1930
-
1931
- try:
1932
- if constant_args.get('_spec_property_naming'):
1933
- anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args)
1934
- else:
1935
- anyof_instance = anyof_class(**model_args, **constant_args)
1936
- anyof_instances.append(anyof_instance)
1937
- except Exception:
1938
- pass
1939
- if len(anyof_instances) == 0:
1940
- raise ApiValueError(
1941
- "Invalid inputs given to generate an instance of %s. None of the "
1942
- "anyOf schemas matched the inputs." %
1943
- self.__class__.__name__
1944
- )
1945
- return anyof_instances
1946
-
1947
-
1948
- def get_discarded_args(self, composed_instances, model_args):
1949
- """
1950
- Gathers the args that were discarded by configuration.discard_unknown_keys
1951
- """
1952
- model_arg_keys = model_args.keys()
1953
- discarded_args = set()
1954
- # arguments passed to self were already converted to python names
1955
- # before __init__ was called
1956
- for instance in composed_instances:
1957
- if instance.__class__ in self._composed_schemas['allOf']:
1958
- try:
1959
- keys = instance.to_dict().keys()
1960
- discarded_keys = model_args - keys
1961
- discarded_args.update(discarded_keys)
1962
- except Exception:
1963
- # allOf integer schema will throw exception
1964
- pass
1965
- else:
1966
- try:
1967
- all_keys = set(model_to_dict(instance, serialize=False).keys())
1968
- js_keys = model_to_dict(instance, serialize=True).keys()
1969
- all_keys.update(js_keys)
1970
- discarded_keys = model_arg_keys - all_keys
1971
- discarded_args.update(discarded_keys)
1972
- except Exception:
1973
- # allOf integer schema will throw exception
1974
- pass
1975
- return discarded_args
1976
-
1977
-
1978
- def validate_get_composed_info(constant_args, model_args, self):
1979
- """
1980
- For composed schemas, generate schema instances for
1981
- all schemas in the oneOf/anyOf/allOf definition. If additional
1982
- properties are allowed, also assign those properties on
1983
- all matched schemas that contain additionalProperties.
1984
- Openapi schemas are python classes.
1985
-
1986
- Exceptions are raised if:
1987
- - 0 or > 1 oneOf schema matches the model_args input data
1988
- - no anyOf schema matches the model_args input data
1989
- - any of the allOf schemas do not match the model_args input data
1990
-
1991
- Args:
1992
- constant_args (dict): these are the args that every model requires
1993
- model_args (dict): these are the required and optional spec args that
1994
- were passed in to make this model
1995
- self (class): the class that we are instantiating
1996
- This class contains self._composed_schemas
1997
-
1998
- Returns:
1999
- composed_info (list): length three
2000
- composed_instances (list): the composed instances which are not
2001
- self
2002
- var_name_to_model_instances (dict): a dict going from var_name
2003
- to the model_instance which holds that var_name
2004
- the model_instance may be self or an instance of one of the
2005
- classes in self.composed_instances()
2006
- additional_properties_model_instances (list): a list of the
2007
- model instances which have the property
2008
- additional_properties_type. This list can include self
2009
- """
2010
- # create composed_instances
2011
- composed_instances = []
2012
- allof_instances = get_allof_instances(self, model_args, constant_args)
2013
- composed_instances.extend(allof_instances)
2014
- oneof_instance = get_oneof_instance(self.__class__, model_args, constant_args)
2015
- if oneof_instance is not None:
2016
- composed_instances.append(oneof_instance)
2017
- anyof_instances = get_anyof_instances(self, model_args, constant_args)
2018
- composed_instances.extend(anyof_instances)
2019
- """
2020
- set additional_properties_model_instances
2021
- additional properties must be evaluated at the schema level
2022
- so self's additional properties are most important
2023
- If self is a composed schema with:
2024
- - no properties defined in self
2025
- - additionalProperties: False
2026
- Then for object payloads every property is an additional property
2027
- and they are not allowed, so only empty dict is allowed
2028
-
2029
- Properties must be set on all matching schemas
2030
- so when a property is assigned toa composed instance, it must be set on all
2031
- composed instances regardless of additionalProperties presence
2032
- keeping it to prevent breaking changes in v5.0.1
2033
- TODO remove cls._additional_properties_model_instances in 6.0.0
2034
- """
2035
- additional_properties_model_instances = []
2036
- if self.additional_properties_type is not None:
2037
- additional_properties_model_instances = [self]
2038
-
2039
- """
2040
- no need to set properties on self in here, they will be set in __init__
2041
- By here all composed schema oneOf/anyOf/allOf instances have their properties set using
2042
- model_args
2043
- """
2044
- discarded_args = get_discarded_args(self, composed_instances, model_args)
2045
-
2046
- # map variable names to composed_instances
2047
- var_name_to_model_instances = {}
2048
- for prop_name in model_args:
2049
- if prop_name not in discarded_args:
2050
- var_name_to_model_instances[prop_name] = [self] + list(
2051
- filter(
2052
- lambda x: prop_name in x.openapi_types, composed_instances))
2053
-
2054
- return [
2055
- composed_instances,
2056
- var_name_to_model_instances,
2057
- additional_properties_model_instances,
2058
- discarded_args
2059
- ]