Skip to content

Commit

Permalink
fix: properly describe request bodies and add response descriptions (t…
Browse files Browse the repository at this point in the history
  • Loading branch information
childish-sambino committed Apr 21, 2020
1 parent 80c8a80 commit 8821832
Show file tree
Hide file tree
Showing 30 changed files with 18,397 additions and 22,318 deletions.
34 changes: 33 additions & 1 deletion src/services/twilio-api/api-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ class TwilioApiBrowser {
// Move the operations into an operations object.
OPERATIONS.forEach(operationName => {
if (operationName in path) {
path.operations[operationName] = path[operationName];
const operation = path[operationName];
path.operations[operationName] = operation;
delete path[operationName];

// Convert all the request body properties to query parameters for
// simpler parsing downstream.
const parameters = this.requestPropertiesToParameters(operation.requestBody);

if (parameters.length > 0) {
operation.parameters = operation.parameters ? operation.parameters.concat(parameters) : parameters;
}
}
});

Expand All @@ -65,6 +74,29 @@ class TwilioApiBrowser {

return domains;
}

requestPropertiesToParameters(requestBody) {
const parameters = [];
const content = (requestBody || {}).content || {};

Object.values(content).forEach(type => {
const typeSchema = type.schema || {};
const properties = typeSchema.properties || {};
const required = typeSchema.required || [];

Object.entries(properties).forEach(([name, schema]) => {
parameters.push({
name,
schema,
in: 'query',
required: required.includes(name),
description: schema.description
});
});
});

return parameters;
}
}

module.exports = TwilioApiBrowser;
186 changes: 100 additions & 86 deletions src/services/twilio-api/twilio_accounts.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"type": "object"
}
}
}
},
"description": "OK"
}
},
"security": [
Expand All @@ -170,38 +171,35 @@
},
"post": {
"description": "Create a new AWS Credential",
"parameters": [
{
"description": "A string that contains the AWS access credentials in the format `<AWS_ACCESS_KEY_ID>:<AWS_SECRET_ACCESS_KEY>`. For example, `AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY`",
"in": "query",
"name": "Credentials",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"in": "query",
"name": "FriendlyName",
"required": false,
"schema": {
"type": "string"
}
},
{
"description": "The SID of the Subaccount that this Credential should be associated with. Must be a valid Subaccount of the account issuing the request.",
"in": "query",
"name": "AccountSid",
"required": false,
"schema": {
"maxLength": 34,
"minLength": 34,
"pattern": "^AC[0-9a-fA-F]{32}$",
"type": "string"
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"properties": {
"AccountSid": {
"description": "The SID of the Subaccount that this Credential should be associated with. Must be a valid Subaccount of the account issuing the request.",
"maxLength": 34,
"minLength": 34,
"pattern": "^AC[0-9a-fA-F]{32}$",
"type": "string"
},
"Credentials": {
"description": "A string that contains the AWS access credentials in the format `<AWS_ACCESS_KEY_ID>:<AWS_SECRET_ACCESS_KEY>`. For example, `AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY`",
"type": "string"
},
"FriendlyName": {
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"type": "string"
}
},
"required": [
"Credentials"
],
"type": "object"
}
}
}
],
},
"responses": {
"201": {
"content": {
Expand All @@ -210,7 +208,8 @@
"$ref": "#/components/schemas/accounts.v1.credential.credential_aws"
}
}
}
},
"description": "Created"
}
},
"security": [
Expand Down Expand Up @@ -290,7 +289,8 @@
"$ref": "#/components/schemas/accounts.v1.credential.credential_aws"
}
}
}
},
"description": "OK"
}
},
"security": [
Expand All @@ -316,17 +316,23 @@
"pattern": "^CR[0-9a-fA-F]{32}$",
"type": "string"
}
},
{
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"in": "query",
"name": "FriendlyName",
"required": false,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"properties": {
"FriendlyName": {
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"type": "string"
}
},
"type": "object"
}
}
}
},
"responses": {
"200": {
"content": {
Expand All @@ -335,7 +341,8 @@
"$ref": "#/components/schemas/accounts.v1.credential.credential_aws"
}
}
}
},
"description": "OK"
}
},
"security": [
Expand Down Expand Up @@ -421,7 +428,8 @@
"type": "object"
}
}
}
},
"description": "OK"
}
},
"security": [
Expand All @@ -435,38 +443,35 @@
},
"post": {
"description": "Create a new Public Key Credential",
"parameters": [
{
"description": "A URL encoded representation of the public key. For example, `-----BEGIN PUBLIC KEY-----MIIBIjANB.pa9xQIDAQAB-----END PUBLIC KEY-----`",
"in": "query",
"name": "PublicKey",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"in": "query",
"name": "FriendlyName",
"required": false,
"schema": {
"type": "string"
}
},
{
"description": "The SID of the Subaccount that this Credential should be associated with. Must be a valid Subaccount of the account issuing the request",
"in": "query",
"name": "AccountSid",
"required": false,
"schema": {
"maxLength": 34,
"minLength": 34,
"pattern": "^AC[0-9a-fA-F]{32}$",
"type": "string"
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"properties": {
"AccountSid": {
"description": "The SID of the Subaccount that this Credential should be associated with. Must be a valid Subaccount of the account issuing the request",
"maxLength": 34,
"minLength": 34,
"pattern": "^AC[0-9a-fA-F]{32}$",
"type": "string"
},
"FriendlyName": {
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"type": "string"
},
"PublicKey": {
"description": "A URL encoded representation of the public key. For example, `-----BEGIN PUBLIC KEY-----MIIBIjANB.pa9xQIDAQAB-----END PUBLIC KEY-----`",
"type": "string"
}
},
"required": [
"PublicKey"
],
"type": "object"
}
}
}
],
},
"responses": {
"201": {
"content": {
Expand All @@ -475,7 +480,8 @@
"$ref": "#/components/schemas/accounts.v1.credential.credential_public_key"
}
}
}
},
"description": "Created"
}
},
"security": [
Expand Down Expand Up @@ -555,7 +561,8 @@
"$ref": "#/components/schemas/accounts.v1.credential.credential_public_key"
}
}
}
},
"description": "OK"
}
},
"security": [
Expand All @@ -581,17 +588,23 @@
"pattern": "^CR[0-9a-fA-F]{32}$",
"type": "string"
}
},
{
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"in": "query",
"name": "FriendlyName",
"required": false,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"properties": {
"FriendlyName": {
"description": "A descriptive string that you create to describe the resource. It can be up to 64 characters long.",
"type": "string"
}
},
"type": "object"
}
}
}
},
"responses": {
"200": {
"content": {
Expand All @@ -600,7 +613,8 @@
"$ref": "#/components/schemas/accounts.v1.credential.credential_public_key"
}
}
}
},
"description": "OK"
}
},
"security": [
Expand Down
Loading

0 comments on commit 8821832

Please sign in to comment.