mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 23:50:26 +01:00
Merge pull request #55 from fa0311/dev
add removeLegacyDiscriminatorBehavior option
This commit is contained in:
commit
68237b3cd9
3 changed files with 6176 additions and 4 deletions
6140
dist/compatible_discriminator/openapi-3.0.yaml
vendored
Normal file
6140
dist/compatible_discriminator/openapi-3.0.yaml
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,11 +1,23 @@
|
||||||
from hooks import *
|
from hooks import (
|
||||||
|
AddParametersOnBody,
|
||||||
|
AddParametersOnContent,
|
||||||
|
AddParametersOnParameters,
|
||||||
|
AddPathQueryIdOnParameters,
|
||||||
|
AddSecuritySchemesOnSecuritySchemes,
|
||||||
|
RemoveErrorHandle,
|
||||||
|
SetResponsesHeader,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
OUTPUT_DIR = "dist/{0}"
|
OUTPUT_DIR = "dist/{0}"
|
||||||
INPUT_DIR = "src/openapi"
|
INPUT_DIR = "src/openapi"
|
||||||
|
|
||||||
def hooks_generator(self, queryParameterJson=True):
|
def hooks_generator(
|
||||||
|
self,
|
||||||
|
queryParameterJson=True,
|
||||||
|
removeLegacyDiscriminatorBehavior=False,
|
||||||
|
):
|
||||||
# https://stackoverflow.com/questions/34820064/defining-an-api-with-swagger-get-call-that-uses-json-in-parameters/45223964
|
# https://stackoverflow.com/questions/34820064/defining-an-api-with-swagger-get-call-that-uses-json-in-parameters/45223964
|
||||||
if queryParameterJson:
|
if queryParameterJson:
|
||||||
# ["parameters"][0]["content"]["application/json"]["schema"]
|
# ["parameters"][0]["content"]["application/json"]["schema"]
|
||||||
|
|
@ -22,6 +34,11 @@ class Config:
|
||||||
ignoreKeys=["queryId"],
|
ignoreKeys=["queryId"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# https://github.com/OpenAPITools/openapi-generator/issues/15373
|
||||||
|
additionalHooks = []
|
||||||
|
if removeLegacyDiscriminatorBehavior:
|
||||||
|
additionalHooks.append(RemoveErrorHandle())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||||
"schemas": [],
|
"schemas": [],
|
||||||
|
|
@ -31,6 +48,7 @@ class Config:
|
||||||
SetResponsesHeader(suffix=None),
|
SetResponsesHeader(suffix=None),
|
||||||
AddPathQueryIdOnParameters(split=-1),
|
AddPathQueryIdOnParameters(split=-1),
|
||||||
getParamHook,
|
getParamHook,
|
||||||
|
*additionalHooks,
|
||||||
]
|
]
|
||||||
for key in ["default", "user", "users", "user-list", "tweet"]
|
for key in ["default", "user", "users", "user-list", "tweet"]
|
||||||
}
|
}
|
||||||
|
|
@ -70,5 +88,11 @@ class Config:
|
||||||
def main(self):
|
def main(self):
|
||||||
return {
|
return {
|
||||||
"docs": self.hooks_generator(),
|
"docs": self.hooks_generator(),
|
||||||
"compatible": self.hooks_generator(queryParameterJson=False),
|
"compatible": self.hooks_generator(
|
||||||
|
queryParameterJson=False,
|
||||||
|
),
|
||||||
|
"compatible_discriminator": self.hooks_generator(
|
||||||
|
queryParameterJson=False,
|
||||||
|
removelegacyDiscriminatorBehavior=True,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import yaml
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class HookBase:
|
class HookBase:
|
||||||
PLACEHOLDER: dict
|
PLACEHOLDER: dict
|
||||||
|
|
@ -193,6 +194,13 @@ class AddPathQueryIdOnParameters(RequestHookBase):
|
||||||
return path, value
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveErrorHandle(RequestHookBase):
|
||||||
|
def hook(self, path: str, value: dict):
|
||||||
|
content = value["responses"]["200"]["content"]["application/json"]
|
||||||
|
content["schema"] = content["schema"]["oneOf"][0]
|
||||||
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
# OnParameters
|
# OnParameters
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue