From c4e3eb5eb5d824f6bf27b75b302a3713900ee496 Mon Sep 17 00:00:00 2001 From: hamzawaleed01 Date: Sun, 10 Dec 2023 15:42:01 +0500 Subject: [PATCH 1/4] feat: add api-compact.yml --- api-compact.yaml | 126 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 api-compact.yaml diff --git a/api-compact.yaml b/api-compact.yaml new file mode 100644 index 00000000..b67e73ee --- /dev/null +++ b/api-compact.yaml @@ -0,0 +1,126 @@ +--- +apigateway_responses: + "200": + statusCode: "200" + "401": + statusCode: "401" + "403": + statusCode: "403" + "404": + statusCode: "404" + "429": + statusCode: "429" + "500": + statusCode: "500" + default: + statusCode: "400" +responses: + "200": + description: OK + "400": + description: Bad Request + "401": + description: Unauthorized + "403": + description: Forbidden + "404": + description: Not Found + "429": + description: Too Many Requests + "500": + description: Internal Server Error +subscription_plan_uuid: + name: subscription_plan_uuid + in: path + required: true + type: string +auth_header: + name: Authorization + in: header + required: true + type: string +endpoints: + v1: + assignLicenses: + post: + description: Assigns a license to given user emails and sends an activation email. + operationId: assign_licenses + consumes: + - application/json + produces: + - application/json + parameters: + - name: Authorization + in: header + required: true + type: string + - name: subscription_plan_uuid + in: path + required: true + type: string + - name: body + in: body + description: List of emails to assign licenses. + required: true + schema: + type: array + items: + type: object + properties: + user_emails: + description: List of emails to assign licenses. + type: array + required: true + user_sfids: + description: List of salesforce user ids to assign licenses. + type: array + required: true + greeting: + description: Email template closing e.g Hello. + type: string + required: true + closing: + description: Email template closing e.g Goodbye. + type: string + required: true + notify_users: + description: Send license assignment email or not. + type: boolean + required: true + responses: + "200": + description: OK + "400": + description: Bad Request + "401": + description: Unauthorized + "403": + description: Forbidden + "404": + description: Not Found + "429": + description: Too Many Requests + "500": + description: Internal Server Error + x-amazon-apigateway-integration: + responses: + "200": + statusCode: "200" + "401": + statusCode: "401" + "403": + statusCode: "403" + "404": + statusCode: "404" + "429": + statusCode: "429" + "500": + statusCode: "500" + default: + statusCode: "400" + httpMethod: POST + type: http + requestParameters: + integration.request.header.Authorization: method.request.header.Authorization + integration.request.path.subscription_plan_uuid: method.request.path.subscription_plan_uuid + uri: https://${stageVariables.license_manager_host}/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/ From ecd79e7704cc652141055207379686ca9faa50b0 Mon Sep 17 00:00:00 2001 From: hamzawaleed01 Date: Tue, 12 Dec 2023 10:28:28 +0500 Subject: [PATCH 2/4] feat: add api.yaml and fix api-compact.yaml --- api-compact.yaml | 212 ++++++++++++++++++++++------------------------- api.yaml | 126 ++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+), 115 deletions(-) create mode 100644 api.yaml diff --git a/api-compact.yaml b/api-compact.yaml index b67e73ee..92432c34 100644 --- a/api-compact.yaml +++ b/api-compact.yaml @@ -1,126 +1,108 @@ ---- -apigateway_responses: - "200": +# License Manager IDA: upstream API definitions, including vendor extensions. +# Note, while this document is not strictly to Swagger spec, each HTTP method's +# definition _must_ be to spec or the downstream ref will fail. +# +# Clients must include an Authorization header with OAuth2 access token in order to communicate: +# Authorization: JWT {access_token} +# +# +# Available service endpoints -- note that alternate endpoints may be presented at the API Gateway tier +# POST /api/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/ + +apigateway_responses: &apigateway_responses + default: + statusCode: "400" + 200: statusCode: "200" - "401": + 401: statusCode: "401" - "403": + 403: statusCode: "403" - "404": + 404: statusCode: "404" - "429": + 429: statusCode: "429" - "500": + 500: statusCode: "500" - default: - statusCode: "400" -responses: - "200": - description: OK - "400": - description: Bad Request - "401": - description: Unauthorized - "403": - description: Forbidden - "404": - description: Not Found - "429": - description: Too Many Requests - "500": - description: Internal Server Error -subscription_plan_uuid: - name: subscription_plan_uuid - in: path + +responses: &responses + 200: + description: "OK" + 400: + description: "Bad Request" + 401: + description: "Unauthorized" + 403: + description: "Forbidden" + 404: + description: "Not Found" + 429: + description: "Too Many Requests" + 500: + description: "Internal Server Error" + +subscription_plan_uuid: &subscription_plan_uuid + name: "subscription_plan_uuid" + in: "path" required: true - type: string -auth_header: - name: Authorization - in: header + type: "string" + +auth_header: &auth_header + name: "Authorization" + in: "header" required: true - type: string + type: "string" + endpoints: v1: + + # /v1/subscriptions/{subscription_plan_uuid}/licenses/assign/ assignLicenses: - post: - description: Assigns a license to given user emails and sends an activation email. - operationId: assign_licenses - consumes: - - application/json - produces: - - application/json - parameters: - - name: Authorization - in: header - required: true - type: string - - name: subscription_plan_uuid - in: path - required: true - type: string - - name: body - in: body - description: List of emails to assign licenses. - required: true - schema: - type: array - items: - type: object - properties: - user_emails: - description: List of emails to assign licenses. - type: array - required: true - user_sfids: - description: List of salesforce user ids to assign licenses. - type: array - required: true - greeting: - description: Email template closing e.g Hello. - type: string - required: true - closing: - description: Email template closing e.g Goodbye. - type: string - required: true - notify_users: - description: Send license assignment email or not. - type: boolean - required: true - responses: - "200": - description: OK - "400": - description: Bad Request - "401": - description: Unauthorized - "403": - description: Forbidden - "404": - description: Not Found - "429": - description: Too Many Requests - "500": - description: Internal Server Error - x-amazon-apigateway-integration: - responses: - "200": - statusCode: "200" - "401": - statusCode: "401" - "403": - statusCode: "403" - "404": - statusCode: "404" - "429": - statusCode: "429" - "500": - statusCode: "500" - default: - statusCode: "400" - httpMethod: POST - type: http - requestParameters: - integration.request.header.Authorization: method.request.header.Authorization - integration.request.path.subscription_plan_uuid: method.request.path.subscription_plan_uuid - uri: https://${stageVariables.license_manager_host}/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/ + post: + description: "Assigns a license to given user emails and sends an activation email." + operationId: "assign_licenses" + consumes: + - "application/json" + produces: + - "application/json" + parameters: + - *auth_header + - *subscription_plan_uuid + - name: "body" + in: "body" + description: "List of emails to assign licenses." + required: true + schema: + type: "array" + items: + type: "object" + properties: + user_emails: + description: "List of emails to assign licenses." + type: "array" + required: true + user_sfids: + description: "List of salesforce user ids to assign licenses." + type: "array" + required: true + greeting: + description: "Email template closing e.g Hello." + type: "string" + required: true + closing: + description: "Email template closing e.g Goodbye." + type: "string" + required: true + notify_users: + description: "Send license assignment email or not." + type: "boolean" + required: true + responses: *responses + x-amazon-apigateway-integration: + responses: *apigateway_responses + httpMethod: "POST" + type: "http" + requestParameters: + integration.request.header.Authorization: "method.request.header.Authorization" + integration.request.path.subscription_plan_uuid: "method.request.path.subscription_plan_uuid" + uri: "https://${stageVariables.license_manager_host}/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/" diff --git a/api.yaml b/api.yaml new file mode 100644 index 00000000..b67e73ee --- /dev/null +++ b/api.yaml @@ -0,0 +1,126 @@ +--- +apigateway_responses: + "200": + statusCode: "200" + "401": + statusCode: "401" + "403": + statusCode: "403" + "404": + statusCode: "404" + "429": + statusCode: "429" + "500": + statusCode: "500" + default: + statusCode: "400" +responses: + "200": + description: OK + "400": + description: Bad Request + "401": + description: Unauthorized + "403": + description: Forbidden + "404": + description: Not Found + "429": + description: Too Many Requests + "500": + description: Internal Server Error +subscription_plan_uuid: + name: subscription_plan_uuid + in: path + required: true + type: string +auth_header: + name: Authorization + in: header + required: true + type: string +endpoints: + v1: + assignLicenses: + post: + description: Assigns a license to given user emails and sends an activation email. + operationId: assign_licenses + consumes: + - application/json + produces: + - application/json + parameters: + - name: Authorization + in: header + required: true + type: string + - name: subscription_plan_uuid + in: path + required: true + type: string + - name: body + in: body + description: List of emails to assign licenses. + required: true + schema: + type: array + items: + type: object + properties: + user_emails: + description: List of emails to assign licenses. + type: array + required: true + user_sfids: + description: List of salesforce user ids to assign licenses. + type: array + required: true + greeting: + description: Email template closing e.g Hello. + type: string + required: true + closing: + description: Email template closing e.g Goodbye. + type: string + required: true + notify_users: + description: Send license assignment email or not. + type: boolean + required: true + responses: + "200": + description: OK + "400": + description: Bad Request + "401": + description: Unauthorized + "403": + description: Forbidden + "404": + description: Not Found + "429": + description: Too Many Requests + "500": + description: Internal Server Error + x-amazon-apigateway-integration: + responses: + "200": + statusCode: "200" + "401": + statusCode: "401" + "403": + statusCode: "403" + "404": + statusCode: "404" + "429": + statusCode: "429" + "500": + statusCode: "500" + default: + statusCode: "400" + httpMethod: POST + type: http + requestParameters: + integration.request.header.Authorization: method.request.header.Authorization + integration.request.path.subscription_plan_uuid: method.request.path.subscription_plan_uuid + uri: https://${stageVariables.license_manager_host}/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/ From 820c740ddd4f1c442649a1def397c2aa593db7d3 Mon Sep 17 00:00:00 2001 From: hamzawaleed01 Date: Wed, 13 Dec 2023 18:17:17 +0500 Subject: [PATCH 3/4] feat: update yaml files --- api-compact.yaml | 114 ++++++++++++++++++++++++++++++++--------------- api.yaml | 80 +++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 36 deletions(-) diff --git a/api-compact.yaml b/api-compact.yaml index 92432c34..ac87bab8 100644 --- a/api-compact.yaml +++ b/api-compact.yaml @@ -25,6 +25,41 @@ apigateway_responses: &apigateway_responses 500: statusCode: "500" +apigateway_responses_with_mapping_template_for_uuid: &apigateway_responses_with_mapping_template_for_uuid + default: + statusCode: "400" + 200: + statusCode: "200" + responseTemplates: + # Response body mapping template, this template is used for updating + # "next" and "previous" urls (both host and url path) while preserving + # the protocol (http | https) and querystring parameters. + application/json: > + #set($inputRoot = $input.path('$')) + #set($host = $stageVariables.gateway_host) + #set($uuid = $input.params('uuid')) + + #set($URLMatchRegex = "(^https?://)[^/]*[^?]*(.*$)") + #set($updatedURL = "$1$host$context.resourcePath$2") + #set($resourceUuidMatch = "{uuid}") + + { + "count": $inputRoot.count, + "next": "$inputRoot.next.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "previous": "$inputRoot.previous.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "results": $inputRoot.results + } + 401: + statusCode: "401" + 403: + statusCode: "403" + 404: + statusCode: "404" + 429: + statusCode: "429" + 500: + statusCode: "500" + responses: &responses 200: description: "OK" @@ -41,6 +76,10 @@ responses: &responses 500: description: "Internal Server Error" +produces: &produces + - "application/json" + - "application/csv" + subscription_plan_uuid: &subscription_plan_uuid name: "subscription_plan_uuid" in: "path" @@ -53,6 +92,15 @@ auth_header: &auth_header required: true type: "string" +x-amazon-apigateway-integration-assign-licenses: &apigateway_integration_assign_licenses + responses: *apigateway_responses_with_mapping_template_for_uuid + httpMethod: "POST" + type: "http" + requestParameters: + integration.request.header.Authorization: "method.request.header.Authorization" + integration.request.path.subscription_plan_uuid: "method.request.path.subscription_plan_uuid" + + endpoints: v1: @@ -63,46 +111,40 @@ endpoints: operationId: "assign_licenses" consumes: - "application/json" - produces: - - "application/json" + produces: *produces parameters: - *auth_header - *subscription_plan_uuid - name: "body" - in: "body" - description: "List of emails to assign licenses." - required: true - schema: - type: "array" - items: - type: "object" - properties: - user_emails: - description: "List of emails to assign licenses." - type: "array" - required: true - user_sfids: - description: "List of salesforce user ids to assign licenses." - type: "array" - required: true - greeting: - description: "Email template closing e.g Hello." - type: "string" - required: true - closing: - description: "Email template closing e.g Goodbye." - type: "string" - required: true - notify_users: - description: "Send license assignment email or not." - type: "boolean" - required: true + in: "body" + description: "List of emails to assign licenses." + required: true + schema: + type: "array" + items: + type: "object" + properties: + user_emails: + description: "List of emails to assign licenses." + type: "array" + required: true + user_sfids: + description: "List of salesforce user ids to assign licenses." + type: "array" + required: true + greeting: + description: "Email template closing e.g Hello." + type: "string" + required: true + closing: + description: "Email template closing e.g Goodbye." + type: "string" + required: true + notify_users: + description: "Send license assignment email or not." + type: "boolean" + required: true responses: *responses x-amazon-apigateway-integration: - responses: *apigateway_responses - httpMethod: "POST" - type: "http" - requestParameters: - integration.request.header.Authorization: "method.request.header.Authorization" - integration.request.path.subscription_plan_uuid: "method.request.path.subscription_plan_uuid" + <<: *apigateway_integration_assign_licenses uri: "https://${stageVariables.license_manager_host}/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/" diff --git a/api.yaml b/api.yaml index b67e73ee..cbf75bf8 100644 --- a/api.yaml +++ b/api.yaml @@ -14,6 +14,34 @@ apigateway_responses: statusCode: "500" default: statusCode: "400" +apigateway_responses_with_mapping_template_for_uuid: + "200": + statusCode: "200" + responseTemplates: + application/json: > + #set($inputRoot = $input.path('$')) #set($host = + $stageVariables.gateway_host) #set($uuid = $input.params('uuid')) + + #set($URLMatchRegex = "(^https?://)[^/]*[^?]*(.*$)") #set($updatedURL = "$1$host$context.resourcePath$2") #set($resourceUuidMatch = "{uuid}") + + { + "count": $inputRoot.count, + "next": "$inputRoot.next.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "previous": "$inputRoot.previous.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "results": $inputRoot.results + } + "401": + statusCode: "401" + "403": + statusCode: "403" + "404": + statusCode: "404" + "429": + statusCode: "429" + "500": + statusCode: "500" + default: + statusCode: "400" responses: "200": description: OK @@ -29,6 +57,9 @@ responses: description: Too Many Requests "500": description: Internal Server Error +produces: + - application/json + - application/csv subscription_plan_uuid: name: subscription_plan_uuid in: path @@ -39,6 +70,40 @@ auth_header: in: header required: true type: string +x-amazon-apigateway-integration-assign-licenses: + responses: + "200": + statusCode: "200" + responseTemplates: + application/json: > + #set($inputRoot = $input.path('$')) #set($host = + $stageVariables.gateway_host) #set($uuid = $input.params('uuid')) + + #set($URLMatchRegex = "(^https?://)[^/]*[^?]*(.*$)") #set($updatedURL = "$1$host$context.resourcePath$2") #set($resourceUuidMatch = "{uuid}") + + { + "count": $inputRoot.count, + "next": "$inputRoot.next.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "previous": "$inputRoot.previous.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "results": $inputRoot.results + } + "401": + statusCode: "401" + "403": + statusCode: "403" + "404": + statusCode: "404" + "429": + statusCode: "429" + "500": + statusCode: "500" + default: + statusCode: "400" + httpMethod: POST + type: http + requestParameters: + integration.request.header.Authorization: method.request.header.Authorization + integration.request.path.subscription_plan_uuid: method.request.path.subscription_plan_uuid endpoints: v1: assignLicenses: @@ -49,6 +114,7 @@ endpoints: - application/json produces: - application/json + - application/csv parameters: - name: Authorization in: header @@ -106,6 +172,20 @@ endpoints: responses: "200": statusCode: "200" + responseTemplates: + application/json: > + #set($inputRoot = $input.path('$')) #set($host = + $stageVariables.gateway_host) #set($uuid = + $input.params('uuid')) + + #set($URLMatchRegex = "(^https?://)[^/]*[^?]*(.*$)") #set($updatedURL = "$1$host$context.resourcePath$2") #set($resourceUuidMatch = "{uuid}") + + { + "count": $inputRoot.count, + "next": "$inputRoot.next.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "previous": "$inputRoot.previous.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", + "results": $inputRoot.results + } "401": statusCode: "401" "403": From 8ca198ba6314cf77bd5b610540bfb11946109a2f Mon Sep 17 00:00:00 2001 From: hamzawaleed01 Date: Wed, 13 Dec 2023 19:44:32 +0500 Subject: [PATCH 4/4] feat: update yaml files --- api-compact.yaml | 16 ++++++--------- api.yaml | 51 +++--------------------------------------------- 2 files changed, 9 insertions(+), 58 deletions(-) diff --git a/api-compact.yaml b/api-compact.yaml index ac87bab8..753f883c 100644 --- a/api-compact.yaml +++ b/api-compact.yaml @@ -92,15 +92,6 @@ auth_header: &auth_header required: true type: "string" -x-amazon-apigateway-integration-assign-licenses: &apigateway_integration_assign_licenses - responses: *apigateway_responses_with_mapping_template_for_uuid - httpMethod: "POST" - type: "http" - requestParameters: - integration.request.header.Authorization: "method.request.header.Authorization" - integration.request.path.subscription_plan_uuid: "method.request.path.subscription_plan_uuid" - - endpoints: v1: @@ -146,5 +137,10 @@ endpoints: required: true responses: *responses x-amazon-apigateway-integration: - <<: *apigateway_integration_assign_licenses + responses: *apigateway_responses + httpMethod: "POST" + type: "http" + requestParameters: + integration.request.header.Authorization: "method.request.header.Authorization" + integration.request.path.subscription_plan_uuid: "method.request.path.subscription_plan_uuid" uri: "https://${stageVariables.license_manager_host}/v1/subscriptions/{subscription_plan_uuid}/licenses/assign/" diff --git a/api.yaml b/api.yaml index cbf75bf8..c891d205 100644 --- a/api.yaml +++ b/api.yaml @@ -1,3 +1,6 @@ +# This file is a "de-compacted" version of api-compact.yaml. The consuming tools are unable to process YAML anchors. +# This file was generated using http://www.yamllint.com/. + --- apigateway_responses: "200": @@ -70,40 +73,6 @@ auth_header: in: header required: true type: string -x-amazon-apigateway-integration-assign-licenses: - responses: - "200": - statusCode: "200" - responseTemplates: - application/json: > - #set($inputRoot = $input.path('$')) #set($host = - $stageVariables.gateway_host) #set($uuid = $input.params('uuid')) - - #set($URLMatchRegex = "(^https?://)[^/]*[^?]*(.*$)") #set($updatedURL = "$1$host$context.resourcePath$2") #set($resourceUuidMatch = "{uuid}") - - { - "count": $inputRoot.count, - "next": "$inputRoot.next.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", - "previous": "$inputRoot.previous.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", - "results": $inputRoot.results - } - "401": - statusCode: "401" - "403": - statusCode: "403" - "404": - statusCode: "404" - "429": - statusCode: "429" - "500": - statusCode: "500" - default: - statusCode: "400" - httpMethod: POST - type: http - requestParameters: - integration.request.header.Authorization: method.request.header.Authorization - integration.request.path.subscription_plan_uuid: method.request.path.subscription_plan_uuid endpoints: v1: assignLicenses: @@ -172,20 +141,6 @@ endpoints: responses: "200": statusCode: "200" - responseTemplates: - application/json: > - #set($inputRoot = $input.path('$')) #set($host = - $stageVariables.gateway_host) #set($uuid = - $input.params('uuid')) - - #set($URLMatchRegex = "(^https?://)[^/]*[^?]*(.*$)") #set($updatedURL = "$1$host$context.resourcePath$2") #set($resourceUuidMatch = "{uuid}") - - { - "count": $inputRoot.count, - "next": "$inputRoot.next.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", - "previous": "$inputRoot.previous.replaceAll($URLMatchRegex, $updatedURL).replace($resourceUuidMatch, $uuid)", - "results": $inputRoot.results - } "401": statusCode: "401" "403":