mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 15:40: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:
|
||||
OUTPUT_DIR = "dist/{0}"
|
||||
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
|
||||
if queryParameterJson:
|
||||
# ["parameters"][0]["content"]["application/json"]["schema"]
|
||||
|
|
@ -22,6 +34,11 @@ class Config:
|
|||
ignoreKeys=["queryId"],
|
||||
)
|
||||
|
||||
# https://github.com/OpenAPITools/openapi-generator/issues/15373
|
||||
additionalHooks = []
|
||||
if removeLegacyDiscriminatorBehavior:
|
||||
additionalHooks.append(RemoveErrorHandle())
|
||||
|
||||
return {
|
||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||
"schemas": [],
|
||||
|
|
@ -31,6 +48,7 @@ class Config:
|
|||
SetResponsesHeader(suffix=None),
|
||||
AddPathQueryIdOnParameters(split=-1),
|
||||
getParamHook,
|
||||
*additionalHooks,
|
||||
]
|
||||
for key in ["default", "user", "users", "user-list", "tweet"]
|
||||
}
|
||||
|
|
@ -70,5 +88,11 @@ class Config:
|
|||
def main(self):
|
||||
return {
|
||||
"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 yaml
|
||||
|
||||
|
||||
class HookBase:
|
||||
PLACEHOLDER: dict
|
||||
|
|
@ -193,6 +194,13 @@ class AddPathQueryIdOnParameters(RequestHookBase):
|
|||
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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue