// Copyright 2020-2026 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package buf.alpha.registry.v1alpha1;

// JSONSchemaService serves JSONSchemas describing protobuf types in buf
// modules.
service JSONSchemaService {
  // GetJSONSchema allows users to get an (approximate) json schema for a
  // protobuf type.
  rpc GetJSONSchema(GetJSONSchemaRequest) returns (GetJSONSchemaResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
}

message GetJSONSchemaRequest {
  string owner = 1;
  string repository = 2;
  // Optional reference (if unspecified, will use the repository's default_branch).
  string reference = 3;

  // A fully qualified name of the type to generate a JSONSchema for, e.g.
  // "pkg.foo.Bar". The type needs to resolve in the referenced module or any of
  // its dependencies. Currently only messages types are supported.
  string type_name = 4;
}

message GetJSONSchemaResponse {
  // A json schema representing what the json encoded payload for type_name
  // should conform to. This schema is an approximation to be used by editors
  // for validation and autocompletion, not a lossless representation of the
  // type's descriptor.
  bytes json_schema = 1;
}
