gnostic
gnostic copied to clipboard
protoc-gen-openapi: http pattern key mismatch
I was try following https://google.aip.dev/133 guidance
// Copyright 2019 Google LLC.
//
// 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 google.example.library.v1;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
option go_package = "google.golang.org/genproto/googleapis/example/library/v1;library";
service LibraryService {
option (google.api.default_host) = "library-example.googleapis.com";
// Creates a book, and returns the new Book.
rpc CreateBook(CreateBookRequest) returns (Book) {
option (google.api.http) = {
post: "/v1/{parent=shelves/*}/books"
body: "book"
};
option (google.api.method_signature) = "parent,book";
}
}
// Request message for LibraryService.CreateBook.
message CreateBookRequest {
// The name of the shelf in which the book is created.
string parent = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).child_type = "Book"
];
// The book to create.
Book book = 2 [(google.api.field_behavior) = REQUIRED];
}
// A single book in the library.
message Book {
option (google.api.resource) = {
type: "library-example.googleapis.com/Book",
pattern: "shelves/{shelf_id}/books/{book_id}"
};
// The resource name of the book.
// Book names have the form `shelves/{shelf_id}/books/{book_id}`.
// The name is ignored when creating a book.
string name = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "library-example.googleapis.com/Book"
];
// The name of the book author.
string author = 2;
// The title of the book.
string title = 3;
}
after generate
paths:
/v1/shelves/{shelf}/books:
post:
tags:
- LibraryService
description: Creates a book, and returns the new Book.
operationId: LibraryService_CreateBook
parameters:
- name: shelf
in: path
description: The shelf id.
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Book'
required: true
expected
description: Creates a book, and returns the new Book.
operationId: LibraryService_CreateBook
parameters:
- - name: shelf
+ - name: parent
in: path
- description: The shelf id.
+ description: The name of the shelf in which the book is created.
required: true
schema:
type: string