swagger-api / swagger-api/swagger-codegen
[Bug][TypeScript]: single quote in enums not escaped
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When defining a model property as an enum, single quotes are not escaped.
Example input:
definitions:
Order:
title: Pet Order
description: An order for a pets from the pet store
type: object
properties:
status:
type: string
description: Order Status
enum:
- pla'ced
- approved
- delivered
Example output:
export interface Order {
status?: Order.StatusEnum;
}
export namespace Order {
export type StatusEnum = 'pla'ced' | 'approved' | 'delivered';
export const StatusEnum = {
Placed: 'pla'ced' as StatusEnum,
Approved: 'approved' as StatusEnum,
Delivered: 'delivered' as StatusEnum
}
}
Swagger-codegen version
2.3.0
Suggest a fix/enhancement
Fixing the escaping in https://github.com/swagger-api/swagger-codegen/blob/v2.3.0/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java#L342
should solve the issue.
The escapeText() method in
https://github.com/swagger-api/swagger-codegen/blob/v2.3.0/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L376
does not escape single quotes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java around the referenced escaping logic, then inspect escapeText() in modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java. Verify generated TypeScript enum unions and constants escape single quotes correctly for values such as pla'ced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100