googleapis / googleapis/api-linter

why not design unmarshal for lint.Response

Open
#1,038 2 comments 0 reactions 0 assignees View on GitHub
priority: p3 type: feature request
Dominant language
Go
Stars
765
Forks
181
Avg merge
2d 12h
Merged PRs (30d)
3

Description

Sometimes, we need parse the output of api-linter in our CI pipelines, however, lint.Response don't support unmarshal, we suggest to add unmarshal in lint.Response, the code is as following,

package main

import (
"encoding/json"
"fmt"
)

// position describes a one-based position in a source code file.
// They are one-indexed, as a human counts lines or columns.
type Position struct {
Line int `json:"line_number" yaml:"line_number"`
Column int `json:"column_number" yaml:"column_number"`
}

// fileLocation describes a location in a source code file.
//
// Note: Positions are one-indexed, as a human counts lines or columns
// in a file.
type FileLocation struct {
Start Position `json:"start_position" yaml:"start_position"`
End Position `json:"end_position" yaml:"end_position"`
}

type Problem struct {
Message string `json:"message" yaml:"message"`
Suggestion string `json:"suggestion,omitempty" yaml:"suggestion,omitempty"`
Location FileLocation `json:"location" yaml:"location"`
RuleID string `json:"rule_id" yaml:"rule_id"`
RuleDocURI string `json:"rule_doc_uri" yaml:"rule_doc_uri"`
Category string `json:"category,omitempty" yaml:"category,omitempty"`
}

type Response struct {
FilePath string `json:"file_path" yaml:"file_path"`
Problems []Problem `json:"problems" yaml:"problems"`
}

func main() {
var res []Response
by := []byte(`[{
"file_path": "proto/commitmeta.proto",
"problems": [
{
"message": "Proto files should set option java_outer_classname = \"CommitmetaProto\".",
"location": {
"start_position": {
"line_number": 63,
"column_number": 1
},
"end_position": {
"line_number": 63,
"column_number": 38
}
},
"rule_id": "core::0191::java-outer-classname",
"rule_doc_uri": "https://linter.aip.dev/191/java-outer-classname"
}
]
}]`)
err := json.Unmarshal(by, &res)
if err == nil {
fmt.Printf("unmarshal: %v", res)
}
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.