Skip to content

Incorrect parsing of sample string slices containing commas #899

@shouhei

Description

@shouhei

Describe the bug
Incorrect parsing of sample string slices containing commas.

To Reproduce

When I defined the following structure and generate swagger using swag init.

type Example struct {
    Messages []string `json:"Messages" example:"\"a,b,c\",\"a,b,c\""`
}

Outputted like this.

definitions:
  main.Example:
    properties:
      Messages:
        example:
        - '"a'
        - b
        - c"
        - '"a'
        - b
        - c"
        items:
          type: string
        type: array
    type: object

Expected behavior

I expect to output like

definitions:
  main.Example:
    properties:
      Messages:
        example:
        - "a,b,c"
        - "a,b,c"
        items:
          type: string
        type: array
    type: object

Your swag version
v1.6.9


I think, It will be able to fix by modify the code to use csv reader alternative to use strings.Split.

https://github.com/swaggo/swag/blob/master/parser.go#L1278

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions