microsoft / typespec

https://typespec.io/
MIT License
4.1k stars 193 forks source link

[Bug]: Illegal characters in component keys (Swagger) #3889

Open flexwie opened 1 month ago

flexwie commented 1 month ago

Describe the bug

If you define a component with keys that include a character outside of [A-Z a-z 0-9 - . _] the corresponding key in the OpenAPI definition will contain that character even if its not allowed by swagger (paste result here).

Is there some way to remove the characters from the generated key as a workaround?

Reproduction

https://typespec.io/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZb3BlbmFwaTMiOwoKdXNpbmcgVHlwZVNwZWMuSHR0cDsKCgpAc2VydmljZSh7CiAgICB0aXRsZTogIlTEUwp9KQpAcm91dGUoIi8iKQpuYW1lc3BhY2UgRW5kcG9pbnRzIMY3QGdldMYJdGFnKCJsaXN0IinFEW9wIMQOKC4uLkNvbW1vblBhcmFtZXRlcnMpOiBzdHJpbmc7Cn0KCm1vZGVsINAkyGBxdWVyecULJHRha2U%2FOiBpbnQzMjsKfQ%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D

Checklist

timotheeguerin commented 1 month ago

Hi @flexwie can you show where it says having those are not allowed in swagger? You are talking about the parameter called $take?

I pasted the resulting openapi in editor.swagger.io and there was no issues

flexwie commented 1 month ago

Sorry, it seems like the playground link was not up to date. Please try again with this example:

https://typespec.io/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZb3BlbmFwaTMiOwoKdXNpbmcgVHlwZVNwZWMuSHR0cDsKCgpAc2VydmljZSh7CiAgICB0aXRsZTogIlTEUwp9KQpAcm91dGUoIi8iKQpuYW1lc3BhY2UgRW5kcG9pbnRzIMY3QGdldMYJdGFnKCJsaXN0IinFEW9wIMQOKC4uLkNvbW1vblBhcmFtZXRlcnMpOiBzdHJpbmc7Cn0KCm1vZGVsINAkyGBxdWVyecULJHRha2U%2FOiBpbnQzMjvSHm9wyh19&e=%40typespec%2Fopenapi3&options=%7B%7D