this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

encoding/jsonschema: respect Config.PkgName

This restores the `Config.PkgName` functionality broken by previous
updates.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I135df49c58f7ac88cdcf47563bbd31c8e20c7ab2
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205904
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+10 -12
+8 -12
encoding/jsonschema/decode.go
··· 119 119 } 120 120 121 121 func (d *decoder) decode(v cue.Value) *ast.File { 122 - f := &ast.File{} 123 - 124 - if pkgName := d.cfg.PkgName; pkgName != "" { 125 - pkg := &ast.Package{Name: ast.NewIdent(pkgName)} 126 - f.Decls = append(f.Decls, pkg) 127 - } 128 - 129 122 var defsRoot cue.Value 130 123 if d.cfg.Root != "" { 131 124 defsPath, err := parseRootRef(d.cfg.Root) ··· 230 223 d.errf(v, "cannot build final syntax: %v", err) 231 224 return nil 232 225 } 233 - var attrs []ast.Decl 226 + var preamble []ast.Decl 227 + if d.cfg.PkgName != "" { 228 + preamble = append(preamble, &ast.Package{Name: ast.NewIdent(d.cfg.PkgName)}) 229 + } 234 230 if rootInfo.schemaVersionPresent { 235 231 // TODO use cue/literal.String 236 232 // TODO is this actually useful information: why is knowing the schema 237 233 // version of the input useful? 238 - attrs = append(attrs, &ast.Attribute{ 234 + preamble = append(preamble, &ast.Attribute{ 239 235 Text: fmt.Sprintf("@jsonschema(schema=%q)", rootInfo.schemaVersion), 240 236 }) 241 237 } 242 238 if rootInfo.deprecated { 243 - attrs = append(attrs, &ast.Attribute{Text: "@deprecated()"}) 239 + preamble = append(preamble, &ast.Attribute{Text: "@deprecated()"}) 244 240 } 245 - if len(attrs) > 0 { 246 - f.Decls = append(attrs, f.Decls...) 241 + if len(preamble) > 0 { 242 + f.Decls = append(preamble, f.Decls...) 247 243 } 248 244 return f 249 245 }
+2
encoding/jsonschema/testdata/txtar/pkgname.txtar
··· 22 22 // Main schema 23 23 // 24 24 // Specify who you are and all. 25 + package somepkg 26 + 25 27 @jsonschema(schema="https://json-schema.org/draft/2019-09/schema") 26 28 27 29 // A person is a human being.