i'm trying to generate swagger JSON files using https://github.com/pseudomuto/protoc-gen-doc, I can't find a way to exclude some of the APIs of the grpc service/fields inside the messages.
found the relevant styling in swagger, but can't seem to find a way to add it in the protobuf file http://watson-developer-cloud.github.io/api-guidelines/swagger-coding-style.html#excluding-operations-from-the-sdks
service MyService {
rpc ExternalApi (ExternalApiRequest) returns (ExternalApiResponse) {
option (google.api.http) = {
post: "/my/externalApi"
};
}
rpc InternalApi (InternalApiRequest) returns (InternalApiResponse) {
option (google.api.http) = {
post: "/my/internalApi"
};
}
message ExternalApiResponse {
string prefix = 1;
string id = 2; // field to exclude
}
// message to exclude
message Header { }
is there a way to exclude actions / fields from the protocol buffer files?
You can add
string id = 2 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field).read_only = true];
Related
What is the right syntax to define swagger response schema, in a .proto file?
I've tried the stuff below, but my compilation fails, complaining about :
Error while parsing option value for "openapiv2_operation": Message type "grpc.gateway.protoc_gen_swagger.options.JSONSchema" has no field named "item".
I've also tried "items" but without luck.
For some reasons, I am not finding a proper documentation on how to define this in a proto file.
I've managed to find a bunch of example though, but none actually covers this scenario.
....
rpc ListOrganizations (ListOrganizationsRequest) returns (ListOrganizationsResponse) {
option (google.api.http) = {
get : "/v4/organizations"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
description: "Get organizations list";
summary: "Fetch the user organizations list";
tags: "Organizations";
responses: {
key: "200"
value: {
description: "On successful response";
schema: {
json_schema: {
type: ARRAY;
item:{
"test": STRING
}
}
}
}
}
......
The response structure will have to eventually match this message:
message Organization {
string id = 1; // e.g. '/organizations/117'
string displayName = 2;
OrganizationType type = 3; // Type of organization
repeated OrganizationMember members = 4;
google.protobuf.Timestamp create_time = 5; // The time and date at with the Organization was createdVy
google.protobuf.Timestamp update_time = 6;
}
message ListOrganizationsRequest {
OrganizationType type = 1;
OrganizationView view = 2;
}
message ListOrganizationsResponse {
repeated Organization organizations = 1;
int32 totalSize = 2; // total count of organizations that match request.
}
OK I managed to find a solution by digging into openapiv2.proto
Still, it will be nice to have somewhere on the public domain, some proper docs on this.
For whoever is interested, the schema definition should look something like this:
schema: {
json_schema: {
type: ARRAY;
ref: '#/definitions/mix.api.ListOrganizationsResponse'
}
}
I have a script groovy, this script for live fetching of docker image,
I want to add the authentication function with the private repository, but I am not familiar with groovy, who can help me, thanks
import groovy.json.JsonSlurper
// Set the URL we want to read from, it is MySQL from official Library for this example, limited to 20 results only.
docker_image_tags_url = "https://registry.adx.abc/v2/mysql/tags/list"
try {
// Set requirements for the HTTP GET request, you can add Content-Type headers and so on...
def http_client = new URL(docker_image_tags_url).openConnection() as HttpURLConnection
http_client.setRequestMethod('GET')
// Run the HTTP request
http_client.connect()
// Prepare a variable where we save parsed JSON as a HashMap, it's good for our use case, as we just need the 'name' of each tag.
def dockerhub_response = [:]
// Check if we got HTTP 200, otherwise exit
if (http_client.responseCode == 200) {
dockerhub_response = new JsonSlurper().parseText(http_client.inputStream.getText('UTF-8'))
} else {
println("HTTP response error")
System.exit(0)
}
// Prepare a List to collect the tag names into
def image_tag_list = []
// Iterate the HashMap of all Tags and grab only their "names" into our List
dockerhub_response.results.each { tag_metadata ->
image_tag_list.add(tag_metadata.name)
}
// The returned value MUST be a Groovy type of List or a related type (inherited from List)
// It is necessary for the Active Choice plugin to display results in a combo-box
return image_tag_list.sort()
} catch (Exception e) {
// handle exceptions like timeout, connection errors, etc.
println(e)
}
The problem has been resolved, thank you everyone for your help
// Import the JsonSlurper class to parse Dockerhub API response
import groovy.json.JsonSlurper
// Set the URL we want to read from, it is MySQL from official Library for this example, limited to 20 results only.
docker_image_tags_url = "https://registry.adx.vn/v2/form-be/tags/list"
try {
// Set requirements for the HTTP GET request, you can add Content-Type headers and so on...
def http_client = new URL(docker_image_tags_url).openConnection() as HttpURLConnection
http_client.setRequestMethod('GET')
String userCredentials = "your_user:your_passwd";
String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userCredentials.getBytes()));
http_client.setRequestProperty ("Authorization", basicAuth);
// Run the HTTP request
http_client.connect()
// Prepare a variable where we save parsed JSON as a HashMap, it's good for our use case, as we just need the 'name' of each tag.
def dockerhub_response = [:]
// Check if we got HTTP 200, otherwise exit
if (http_client.responseCode == 200) {
dockerhub_response = new JsonSlurper().parseText(http_client.inputStream.getText('UTF-8'))
} else {
println("HTTP response error")
System.exit(0)
}
// Prepare a List to collect the tag names into
def image_tag_list = []
// Iterate the HashMap of all Tags and grab only their "names" into our List
dockerhub_response.tags.each { tag_metadata ->
image_tag_list.add(tag_metadata)
}
// The returned value MUST be a Groovy type of List or a related type (inherited from List)
// It is necessary for the Active Choice plugin to display results in a combo-box
return image_tag_list.sort()
} catch (Exception e) {
// handle exceptions like timeout, connection errors, etc.
println(e)
}
here is the result
I have an issue to run this service in my client
but when I console.log before the request it was fine
here is the code :
import 'package:grpc/grpc.dart';
import 'package:rpc/src/generated/blog.pb.dart';
import 'package:rpc/src/generated/blog.pbgrpc.dart';
Future<void> main() async {
final channel = ClientChannel(
'localhost',
port: 50051,
options: const ChannelOptions(credentials: ChannelCredentials.insecure()),
);
var stub = BlogServiceClient(channel);
// final name = args.isNotEmpty ? args[0] : 'world';
try {
var bg = Blog();
bg.authorId = "name";
bg.title = "LOL";
bg.content = "Content here";
var data = CreateBlogRequest();
data.blog = bg;
print(data);
await stub.createBlog(data);
// print(gotIt.);
} catch (er) {
print('something error yeahh ===> $er');
}
await channel.shutdown();
}
blog.proto ::
syntax = "proto3";
package blog;
//option go_package="blogpb";
message Blog {
string id = 1;
string author_id = 2;
string title = 3;
string content = 4;
}
message CreateBlogRequest {
Blog blog = 1;
}
message CreateBlogResponse {
Blog blog = 1;
}
message ReadBlogRequest {
string blog_id = 1;
}
message ReadBlogResponse {
Blog blog = 1;
}
message UpdateBlogRequest {
Blog blog = 1;
}
message UpdateBlogResponse {
Blog blog = 1;
}
service BlogService {
rpc CreateBlog (CreateBlogRequest) returns (CreateBlogResponse);
rpc ReadBlog (ReadBlogRequest) returns (ReadBlogResponse);
rpc UpdateBlog (UpdateBlogRequest) returns (UpdateBlogResponse);
}
what I got is gRPC Error (12, unknown service blog.BlogService)
I think I already change port and command options also, but still doesn't work
and the same result
what I expect it I create the blog with that service createBlog
i run the server on Go
I really need to know this badly what's wrong,
I think dart developer not too many because it hards for me to find info about this out on the internet there,
so I came here to ask, and hope grpc Dart team will help some developers about some issues, I have seen on the GitHub issue on grpc-dart, not many the team answer some issues on grpc-dart
i gave wrong package name on .proto file
it was not same like service BlogService {}
my package name was named package something , after i changed tp package blog
it was work well
I'm trying to develop a Mule application with inbound IMAP connector. It works fine when the incoming mail is plain text but when it's HTML or Rich Text there's no text in the payload. How to make the application independent of the incoming mail type?
HTML or Rich Text are most probably MIME multipart emails. In that case, Mule tries to extract the text has payload only if the multipart email contains a first part that is has a content type starting with text/ (like text/plain). I reckon that in your case, the multipart email doesn't match this rule, thus Mule doesn't know what to do with it.
I suggest you use a choice router to deal with the case when there's no text in the payload after the email has been received. In that case, use whatever logic that is relevant to you to extract the content from one of the inbound attachments into which the different parts have been transferred.
I've been able to write some Java-code that bring out the text-part of a multipart message but I can't find a way to get this working with Mule. MUle wants to load the class with a String even though it's a multi part message.
The code I've written is below:
import javax.activation.DataHandler;
import javax.mail.*;
public class ReadMultipartMail3 {
public String stringback(Part payload) throws Exception {
String answer ="";
if(payload.isMimeType("text/plain") || payload.isMimeType("text/html"))
{
answer=(payload.getContent().toString());
}
else{
Multipart multipart = (Multipart) payload.getContent();
for (int x = 0; x < multipart.getCount(); x++) {
Part p = multipart.getBodyPart(x);
System.out.println("Content Type: "+p.getContentType());
BodyPart bodyPart = multipart.getBodyPart(x);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT))) {
System.out.println("Mail have some attachment : ");
DataHandler handler = bodyPart.getDataHandler();
System.out.println("file name : " + handler.getName());
} else {
if(p.isMimeType("text/plain") || p.isMimeType("text/html"))
{
answer = (p.getContent().toString());
}
else if (p.isMimeType("multipart/alternative"))
{
Multipart mp = (Multipart)p.getContent();
int partsCount = mp.getCount();
for (int z = 0; z < partsCount; z++) {
System.out.println("Content Type: "+z+" "+mp.getBodyPart(z).getContentType());
if(mp.getBodyPart(z).getContentType().contains("text/plain"))
{answer = (String) mp.getBodyPart(z).getContent();}
}
}
}
}
}
return answer;}}
I would like to parse a file within an MWE2 workflow, e.g. by giving the org.eclipse.emf.mwe.utils.Reader component a file written in my DSL rather than the XMI representation of it.
Alternatively have a look at org.eclipse.xtext.mwe.UriBasedReader
I have found the solution at http://www.eclipse.org/forums/index.php/m/831365/
Workflow {
component = org.eclipse.xtext.mwe.Reader {
register = org.xtext.example.mydsl.MyDslStandaloneSetup {}
path = "modeldir"
loadResource = {
slot = "models"
}
}
}
Adjusted to the answer of Christian when using a single file it can be written
Workflow {
component = org.eclipse.xtext.mwe.UriBasedReader {
register = org.xtext.example.mydsl.MyDslStandaloneSetup {}
uri = "model.file"
loadResource = {
slot = "model"
}
}
}