8000 Backticks appearing in tags are not properly handled · Issue #2423 · go-swagger/go-swagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Backticks appearing in tags are not properly handled #2423
Closed
@a2800276

Description

@a2800276

Problem statement

If schema data containing backticks end up in struct (etc.) tags of generated Go code, the tag generation is not handling quotation of tags properly. ( Outer quotes would need to be " instead of backtick with inner double quotes being escaped. One solution is to do this with all tags, but that would make the generated code ugly, and go fmt doesn't clean it up.)

Swagger specification

Backticks are legal, e.g. in XMLObject, the name parameter is a string with no further restrictions ...

Steps to reproduce

I've attached a minimal extract from a real-world public schema (https://api.mouser.com/api/docs/ui/index) which ends up generating broken code. Executed as (swagger generate client -f test.json.txt), here are the relevant bits:

// schema
"xml" : {
    "name" : "KeyValuePair`2",
    "wrapped" : true
}
// go IS
(...) `json:"ScheduledReleases" xml:"KeyValuePair`2"`

// go SHOULD
(...) "json:\"ScheduledReleases\" xml:\"KeyValuePair`2\""

test.json.txt

Unfortunately, you can't escape backticks within backticks, so Tags need to revert to double quotes containing escaped quotation marks ...

(Also, I'm well aware that this is terribly awfully unaesthetic style and it leaves me scratching my head asking myself what sort of a deranged monster would do such a thing, but as far as I can tell it's perfectly legal.)

Environment

swagger version: current (2020-11-13) master ( 8831a62 )
go version: go version go1.14.3 linux/amd64
OS:

$ lsb_release  -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal

Metadata

Metadata

Assignees

Labels

buggeneratormodelRelated to swagger generate model commandpending PRtagsRelated to model struct tags

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0