प्रोटोकॉल
वास्तविक प्रणालियाँ केवल REST तक सीमित नहीं हैं। Powerduck, x-protocol एक्सटेंशन से सामान्य OpenAPI पथ आइटम पर सात प्रोटोकॉल मॉडल करता है। स्ट्रीमिंग और RPC कार्रवाइयाँ HTTP के साथ एक ही विनिर्देश में रहती हैं; उन्हें अलग टूल में रखने या चुपचाप REST में बदलने की ज़रूरत नहीं होती।
हर गैर-HTTP कार्रवाई भी सामान्य पथ आइटम होती है, जिसमें HTTP विधि और responses."200".description होता है:
graphql,grpc,mcpऔरa2aमें post इस्तेमाल होता है;sseऔरwebsocketमें आम तौर पर get इस्तेमाल होता है;httpडिफ़ॉल्ट है और इसमेंx-protocolनहीं दिया जाता।
SSE
HTTP पर सर्वर से भेजे जाने वाले इवेंट के लिए x-protocol: "sse" इस्तेमाल होता है। स्ट्रीम का मीडिया प्रकार text/event-stream है और एक इवेंट का पेलोड schema के बजाय itemSchema से बताया जाता है:
paths:
/events:
get:
x-protocol: sse
responses:
"200":
description: Event stream
content:
text/event-stream:
itemSchema:
type: object
properties:
type:
type: string
data:
type: string
WebSocket
WebSocket में x-websocket ब्लॉक के साथ x-protocol: "websocket" इस्तेमाल होता है। URL की शुरुआत ws:// या wss:// से होनी चाहिए:
paths:
/ws:
get:
x-protocol: websocket
x-websocket:
url: wss://example.com/ws
subprotocols: []
headers: {}
responses:
"200":
description: Operation response
subprotocols और headers वैकल्पिक हैं।
GraphQL
GraphQL में /graphql/query/fieldName जैसे पथ पर post और x-graphql इस्तेमाल होते हैं। एंडपॉइंट पूरा HTTP(S) URL होना चाहिए और क्वेरी देना अनिवार्य है:
paths:
/graphql/query/product:
post:
x-protocol: graphql
x-graphql:
endpoint: https://example.com/graphql
query: query Product($id: ID!) { product(id: $id) { id name } }
operationName: Product
variablesSchema:
type: object
variables: {}
responses:
"200":
description: Operation response
operationName, variablesSchema और variables वैकल्पिक हैं।
gRPC
gRPC में /grpc/pkg.Service/Method जैसे पथ पर post और x-grpc इस्तेमाल होते हैं। सर्वर reflection का समर्थन करे तो reflection: true सेट करें; नहीं तो protoPaths और ज़रूरत होने पर includeDirs दें:
paths:
/grpc/products.ProductService/GetProduct:
post:
x-protocol: grpc
x-grpc:
address: host:port
service: products.ProductService
method: GetProduct
kind: unary
reflection: true
responses:
"200":
description: Operation response
kind का मान unary, server_streaming, client_streaming या bidi_streaming में से एक होता है।
MCP
MCP डिफ़ॉल्ट रूप से Streamable HTTP इस्तेमाल करता है, जिसमें /mcp/tools/tool-name जैसे पथ पर post और x-mcp ब्लॉक होता है:
paths:
/mcp/tools/create-product:
post:
x-protocol: mcp
x-mcp:
endpoint: http://127.0.0.1:3000/mcp
transport: streamable-http
method: tools/call
name: create-product
argumentsSchema:
type: object
arguments: {}
responses:
"200":
description: Operation response
method से MCP कार्रवाई चुनी जाती है: tools/call, tools/list, resources/read, resources/list, resources/templates/list, prompts/get या prompts/list। name, uri, argumentsSchema और arguments का उपयोग विधि की ज़रूरत के अनुसार होता है।
संरचना के नियम
- सहायक से बनवाए गए अनुबंधों में
requestBodyयाresponsesके मीडिया प्रकारों के लिएschemaया$refदें;text/event-streamमें हर इवेंट के लिए OAS 3.2 काitemSchemaइस्तेमाल होता है। यह Powerduck में लिखने की परंपरा है, हर OpenAPI दस्तावेज़ की सार्वभौमिक आवश्यकता नहीं। - हर पैरामीटर में
schemaयाcontentहोना चाहिए। - कार्रवाई संपादित करते समय चुना हुआ प्रोटोकॉल और उसकी कॉन्फ़िगरेशन सुरक्षित रखी जाती है। RPC और स्ट्रीमिंग कार्रवाइयाँ चुपचाप REST में नहीं बदली जातीं।
- ऊपर दिए एक्सटेंशन का सटीक ढाँचा इस्तेमाल करें;
externalUrlजैसी कुंजियाँ न गढ़ें और प्रोटोकॉल नाम के रूप मेंwsन दें।