chrusty / protoc-gen-jsonschema

Protobuf to JSON-Schema compiler
Apache License 2.0
496 stars 101 forks source link

Handle google.protobuf.Struct #89

Closed grant closed 3 years ago

grant commented 3 years ago

Currently the generator doesn't handle the special type google.protobuf.Struct that well:

ACTUAL

message AuditLog {
  // Deprecated: Use `metadata` field instead.
  // Other service-specific data about the request, response, and other
  // activities.
  // When the JSON object represented here has a proto equivalent, the proto
  // name will be indicated in the `@type` property.
  google.protobuf.Struct service_data = 15;
}
...
"serviceData": {
  "properties": {
    "fields": {
      "additionalProperties": {
        "oneOf": [
          {
            "type": "array"
          },
          {
            "type": "boolean"
          },
          {
            "type": "number"
          },
          {
            "type": "object"
          },
          {
            "type": "string"
          }
        ],
        "description": "`Value` represents a dynamically typed value which can be either\n null, a number, a string, a boolean, a recursive struct value, or a\n list of values. A producer of value is expected to set one of that\n variants, absence of any variant indicates an error.\n\n The JSON representation for `Value` is JSON value."
      },
      "type": "object",
      "description": "Unordered map of dynamically typed values."
    }
  },
  "additionalProperties": true,
  "type": "object",
  "description": "Deprecated: Use `metadata` field instead.\n Other service-specific data about the request, response, and other\n activities.\n When the JSON object represented here has a proto equivalent, the proto\n name will be indicated in the `@type` property."
}
...

EXPECTED

...
"serviceData": {
  "type": "object",
  "description": "Deprecated: Use `metadata` field instead.\n Other service-specific data about the request, response, and other\n activities.\n When the JSON object represented here has a proto equivalent, the proto\n name will be indicated in the `@type` property."
}
...

I think we clean this up in postgen, but we should try to clean up the schema upstream.


https://github.com/chrusty/protoc-gen-jsonschema/blob/3469322725c0968fb49b3552ff59ead8bb9d735a/internal/converter/types.go#L184

chrusty commented 3 years ago

See the new release for this feature