Skip to content

Commit

Permalink
chore: update rmf-codegen + add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
timonrey committed Feb 20, 2023
1 parent 28f404f commit d9ee6bc
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api-specs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"generate-ramldoc:watch": "npx rmf-codegen generate ./api.raml -w -o ../../websites/api-docs-smoke-test/src/api-specs/api -t RAML_DOC"
},
"dependencies": {
"@commercetools-docs/rmf-codegen": "13.13.0"
"@commercetools-docs/rmf-codegen": "13.25.0"
}
}
83 changes: 83 additions & 0 deletions api-specs/test/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ uses:
soft-links: types/soft-links.raml
unions: types/unions.raml

traits:
right-header:
headers:
Accept:
displayName: Accept Header
type: string
description: Accept application/json Header
required: true
pattern: ^application/json$
default: application/json
frontastic-locale:
headers:
Frontastic-Locale:
displayName: Frontastic Locale
type: any
description: Locale
action-errorable:
responses:
400:
description: Action not registered.
body:
application/json:
type: any
example: !include ./examples/action-error.json

# Endpoints ("Resources" in RAML and HTTP terminology)
# Every CT API endpoint starts at this root
/{projectKey}:
Expand Down Expand Up @@ -475,6 +500,64 @@ uses:
type: object
example: !include examples/action-success.json

/namespace-action-with-headers:
uriParameters:
namespace:
displayName: Namespace
type: string
description: The namespace where the action to invoked is located. [Namespaces are used to categorize actions](/../frontend-development/developing-an-action-extension#1-implement-the-action).
action:
displayName: Action
type: string
description: The name of the action to invoked.
get:
is:
- action-errorable
- right-header
- frontastic-locale
description: Use the GET method to allow the frontend to fetch data from a backend system. For the response, we recommend to use standard HTTP codes and `application/json` encoded content. The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). The following response example contains information about a cart.
responses:
200:
description: The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). We recommend to use standard HTTP response codes and `application/json` encoded content. The following response example contains information about a cart.
body:
application/json:
type: object
example: !include examples/action-success.json
post:
is:
- action-errorable
- right-header
- frontastic-locale
description: Use the POST method to write data to a backend system. Any JSON serializable payload is accepted. The following request example adds a product to a cart. For the response, we recommend to use standard HTTP codes and `application/json` encoded content. The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). The following response example contains the updated cart information, which includes the added product.
body:
application/json:
type: any
example: !include examples/action-payload.json
responses:
200:
description: The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). We recommend to use standard HTTP response codes and `application/json` encoded content. The following response example contains information about a cart.
body:
application/json:
type: object
example: !include examples/action-success.json
put:
is:
- action-errorable
- right-header
- frontastic-locale
description: Use the PUT method to write data to a backend system. Any JSON serializable payload is accepted. The following request example adds a product to a cart. For the response, we recommend to use standard HTTP codes and `application/json` encoded content. The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). The following response example contains the updated cart information, which includes the added product.
body:
application/json:
type: any
example: !include examples/action-payload.json
responses:
200:
description: The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). We recommend to use standard HTTP response codes and `application/json` encoded content. The following response example contains information about a cart.
body:
application/json:
type: any
example: !include examples/action-success.json


# /resourceWithHeaders:
# description: Tests use of specific headers.
4 changes: 4 additions & 0 deletions api-specs/test/examples/action-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ok": false,
"message": "Action \"myAction\" in namespace \"myNamespace\" is not registered."
}
6 changes: 6 additions & 0 deletions api-specs/test/examples/action-payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"variant": {
"sku": "M0E200KJ1200DSDJ",
"count": 1
}
}
2 changes: 1 addition & 1 deletion api-specs/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"generate-ramldoc:watch": "npx rmf-codegen generate ./api.raml -w -o ../../websites/api-docs-smoke-test/src/api-specs/test -t RAML_DOC"
},
"dependencies": {
"@commercetools-docs/rmf-codegen": "13.13.0"
"@commercetools-docs/rmf-codegen": "13.25.0"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-theme-api-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"unist-util-visit": "2.0.3"
},
"devDependencies": {
"@commercetools-docs/rmf-codegen": "13.13.0",
"@commercetools-docs/rmf-codegen": "13.25.0",
"gatsby": "4.24.4",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion websites/api-docs-smoke-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@commercetools-docs/gatsby-theme-api-docs": "20.2.0",
"@commercetools-docs/gatsby-theme-docs": "20.2.0",
"@commercetools-docs/rmf-codegen": "13.13.0",
"@commercetools-docs/rmf-codegen": "13.25.0",
"gatsby": "4.24.4",
"gatsby-cli": "4.24.0",
"gatsby-source-filesystem": "4.24.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ import { ApiEndpointsForResource } from "/shortcodes"
# /\{projectKey}/resource/namespace-action-with-example

<ApiEndpointsForResource apiKey="test" resource="/{projectKey}/resource/namespace-action-with-example" />

# /\{projectKey}/resource/namespace-action-with-headers

<ApiEndpointsForResource apiKey="test" resource="/{projectKey}/resource/namespace-action-with-headers" />
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2083,15 +2083,15 @@ __metadata:
version: 0.0.0-use.local
resolution: "@commercetools-api-specs/api@workspace:api-specs/api"
dependencies:
"@commercetools-docs/rmf-codegen": 13.13.0
"@commercetools-docs/rmf-codegen": 13.25.0
languageName: unknown
linkType: soft

"@commercetools-api-specs/test@workspace:api-specs/test":
version: 0.0.0-use.local
resolution: "@commercetools-api-specs/test@workspace:api-specs/test"
dependencies:
"@commercetools-docs/rmf-codegen": 13.13.0
"@commercetools-docs/rmf-codegen": 13.25.0
languageName: unknown
linkType: soft

Expand All @@ -2100,7 +2100,7 @@ __metadata:
resolution: "@commercetools-docs/gatsby-theme-api-docs@workspace:packages/gatsby-theme-api-docs"
dependencies:
"@commercetools-docs/gatsby-transformer-raml": 13.3.0
"@commercetools-docs/rmf-codegen": 13.13.0
"@commercetools-docs/rmf-codegen": 13.25.0
"@commercetools-docs/ui-kit": 20.2.0
"@commercetools-uikit/design-system": 15.3.0
"@commercetools-uikit/spacings-inline": 15.3.0
Expand Down Expand Up @@ -2318,9 +2318,9 @@ __metadata:
languageName: unknown
linkType: soft

"@commercetools-docs/rmf-codegen@npm:13.13.0":
version: 13.13.0
resolution: "@commercetools-docs/rmf-codegen@npm:13.13.0"
"@commercetools-docs/rmf-codegen@npm:13.25.0":
version: 13.25.0
resolution: "@commercetools-docs/rmf-codegen@npm:13.25.0"
dependencies:
globby: ^13.1.1
js-yaml: ^4.0.0
Expand All @@ -2329,7 +2329,7 @@ __metadata:
bin:
raml-markdownlint: bin/raml-markdownlint.mjs
rmf-codegen: bin/rmf-codegen.js
checksum: 3776682cd6eb06e4709b2eafafc1582d03157e8c053f5de5e47bdc68104fefbaeeb3049d2af78a66be164a5eb89b0299a1c41572783bf1aab517f9482899f9cf
checksum: aca0a8ca82afd886ab9a976959768598151a43a9403bffb7600a7e7e0169aaf91de9bd166c4d9bfc4793718165a924c2f20f90492c5d4fec5a8488703476ab34
languageName: node
linkType: hard

Expand Down Expand Up @@ -2964,7 +2964,7 @@ __metadata:
dependencies:
"@commercetools-docs/gatsby-theme-api-docs": 20.2.0
"@commercetools-docs/gatsby-theme-docs": 20.2.0
"@commercetools-docs/rmf-codegen": 13.13.0
"@commercetools-docs/rmf-codegen": 13.25.0
gatsby: 4.24.4
gatsby-cli: 4.24.0
gatsby-source-filesystem: 4.24.0
Expand Down

0 comments on commit d9ee6bc

Please sign in to comment.