-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fix schema name that has end with space for redoc ui and elements ui #856
Conversation
AFAIU, the space in the schema name a user error that may be a bit tricky to spot but that should be easily fixed. I may be convinced otherwise but I don't think apispec should engage in this. We can't workaround all typos. |
You have point out that maybe it's a user error, I did try named a schema like "Pet In Schema" and the error occur, cause after remove postfix "Schema" in that name, it's stay "Pet In " and this does not look like user error or typo. Even I can simply fix this by replace the name with "Pet In" or "Pet InSchema" but the second way may looks like typo error. |
Good point. We could improve the schema name generator to strip spaces there. How do you create the schema? Schemas are generally created as classes so you can't have spaces in their names. class PetSchema(Schema):
... |
Sorry about delay. I used from marshmallow.fields import String
pet_schema = Schema.from_dict({"name": String()}, name="Pet In Schema") |
OK. Users probably shouldn't give names with spaces in the first place but since it is not forbidden, I have no objection to stripping the generated name in the default name resolver: apispec/src/apispec/ext/marshmallow/__init__.py Lines 87 to 93 in cb90ed2
|
Thanks for your consider. Would the branch be merge? |
pre-commit.ci run |
Made some minor fixups so it's ready to merge. Thanks for the PR! |
I strip
component_id
before register a new schema when to prevent its name has some bad space, generated spec has schama name that end with space like 'Schema name ' doesn't work withredoc
ui (by ReDoc) andelements
ui (by Stoplight)