Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeString causes yaml.representer.RepresenterError for SpectacularAPIView and SpectacularRedocView #802

Closed
fancydancing opened this issue Aug 30, 2022 · 2 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@fancydancing
Copy link

We use format_html("somestring") as help_text in some of our models which returns an object of django.utils.safestring.SafeString type.

SpectacularAPIView and SpectacularRedocView both fail to build schema for these models, failing with the same error:
yaml.representer.RepresenterError: ('cannot represent an object', 'somestring')

SpectacularSwaggerView handles this object properly and does not produce any errors.

I have found the related issue in the drf-yasg project. Maybe this could help.

@tfranzel
Copy link
Owner

great catch! YAML will bail on unknown classes. Added a representener for the SafeString class.

SpectacularSwaggerView handles this object properly and does not produce any errors.

probably because it request the schema in JSON? This should fail for both Redoc and Swagger if schema is requested as a YAML.

@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Aug 30, 2022
@tfranzel
Copy link
Owner

closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants