Loading
Extension de Salesforce avec des clics, sans code
Définition d'un jeu de caractères dans le schéma

Définition d'un jeu de caractères dans le schéma

Pour spécifier un charset pour les appels externes, remplissez l'en-tête de Content-Type. Un charset peut être configuré s'il est spécifiquement défini dans le schéma.

Éditions requises

Disponible avec : Lightning Experience
Disponible avec : Enterprise Edition, Performance Edition, Unlimited Edition et Developer Edition

Lors d'un appel externe, l'en-tête Content-Type est utilisé pour décrire le type de média (par exemple, application/json, text/plain, etc.) d'une ressource qui peut être consommée par l'opération.

charset est un paramètre facultatif de Content-Type qui spécifie le codage de caractères du type de média.

Remarque
Remarque Avec la version Spring '23, charset dans l'en-tête Content-Type n'est plus rempli par défaut en passant des appels externes. Auparavant, Content-Type incluait le paramètre charset=UTF-8 par défaut.

Par exemple, nous allons modifier le schéma BankService pour définir charset sur UTF-8. Les versions des schémas OpenAPI 2.0 et Open API 3.0 sont implémentées différemment. Par conséquent, nous utilisons les deux versions.

Exemple
Exemple Définition de charset dans un schéma OpenAPI 2.0
{
    "swagger":"2.0",
    "basePath":"/",
    "info":{
        "version":"1.0",
        "title":"External Service for demo bank",
        "description":"### External Service for demo bank",
        "x-vcap-service-name":"DemoBankRestServices"
    },
    "securityDefinitions":{
        "basicAuth":{
            "type":"basic"
        }
    },
    "security":[
        {
            "basicAuth":[
                
            ]
        }
    ],
    "tags":[
        {
            "name":"DemoBankRestServices"
        }
    ],
    "paths":{
        "/accounts/{accountName}":{
            "get":{
                "operationId":"getAccount",
                "summary":"Retrieves an account",
                "description":"Retrieves the account with specific name",
                "consumes":[
                    "text/plain; charset=UTF-8"
                ],
                "produces":[
                    "application/json"
                ],
                "parameters":[
                    {
                        "name":"accountName",
                        "in":"path",
                        "required":true,
                        "type":"string",
                        "description":"Name of the account"
                    }
                ],
                "responses":{
                    "200":{
                        "description":"The response when system finds an account with given name",
                        "schema":{
                            "$ref":"#/definitions/accountDetails"
                        }
                    },
                    "400":{
                        "description":"Error response if the account name parameter is less than minimum characters",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    },
                    "404":{
                        "description":"Error response if the account is not supported by service or account is not found",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    }
                }
            },
            "delete":{
                "operationId":"DeleteAccount",
                "summary":"Deletes an account",
                "description":"Deletes the account with specific name",
                "consumes":[
                    "text/plain; charset=UTF-8"
                ],
                "produces":[
                    "application/json"
                ],
                "parameters":[
                    {
                        "name":"accountName",
                        "in":"path",
                        "required":true,
                        "type":"string",
                        "description":"Name of the account"
                    }
                ],
                "responses":{
                    "204":{
                        "description":"The response when system finds an account with given name",
                        "schema":{
                            "type":"string"
                        }
                    },
                    "400":{
                        "description":"Error response if the account name parameter is less than minimum characters",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    },
                    "404":{
                        "description":"Error response if the account is not supported by service or account is not found",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    }
                }
            },
            "post":{
                "operationId":"addAccount",
                "summary":"Add an account",
                "description":"Add an account to the database",
                "consumes":[
                    "text/plain; charset=UTF-8"
                ],
                "produces":[
                    "application/json"
                ],
                "parameters":[
                    {
                        "name":"accountName",
                        "in":"path",
                        "required":true,
                        "type":"string",
                        "description":"Name of the account"
                    },
                    {
                        "name":"accountType",
                        "in":"query",
                        "required":true,
                        "type":"string",
                        "description":"The type of account"
                    }
                ],
                "responses":{
                    "201":{
                        "description":"The response when the account does not already exist and we can create one",
                        "schema":{
                            "$ref":"#/definitions/accountDetails"
                        }
                    },
                    "409":{
                        "description":"The response when the account already exists and we cannot create one",
                        "schema":{
                            "$ref":"#/definitions/accountDetails"
                        }
                    },
                    "400":{
                        "description":"Error response if the account name parameter is less than minimum characters",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    },
                    "404":{
                        "description":"Error response if the account is not supported by service or account is not found",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    }
                }
            },
            "put":{
                "operationId":"updateAccount",
                "summary":"Updates an account",
                "description":"Updates the account with specified name",
                "consumes":[
                    "text/plain; charset=UTF-8"
                ],
                "produces":[
                    "application/json"
                ],
                "parameters":[
                    {
                        "name":"accountName",
                        "in":"path",
                        "required":true,
                        "type":"string",
                        "description":"Name of the account"
                    },
                    {
                        "name":"accountType",
                        "in":"query",
                        "required":true,
                        "type":"string",
                        "description":"The type of account"
                    }
                ],
                "responses":{
                    "200":{
                        "description":"The response when system finds an account with given name",
                        "schema":{
                            "$ref":"#/definitions/accountDetails"
                        }
                    },
                    "400":{
                        "description":"Error response if the account name parameter is less than minimum characters",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    },
                    "404":{
                        "description":"Error response if the account is not supported by service or account is not found",
                        "schema":{
                            "$ref":"#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions":{
        "accountDetails":{
            "required":[
                "id",
                "name",
                "type",
                "availableBal"
            ],
            "properties":{
                "id":{
                    "type":"string",
                    "description":"id"
                },
                "name":{
                    "type":"string",
                    "description":"name"
                },
                "type":{
                    "type":"string",
                    "description":"type"
                },
                "availableBal":{
                    "type":"string",
                    "description":"availableBal"
                }
            }
        },
        "errorModel":{
            "required":[
                "errorCode",
                "errorMessage"
            ],
            "properties":{
                "errorCode":{
                    "type":"string",
                    "description":"A service-specific error code."
                },
                "errorMessage":{
                    "type":"string",
                    "description":"A service-specific error code."
                }
            }
        }
    }
}
Exemple
Exemple Définition de charset dans un schéma OpenAPI 3.0
{
  "openapi": "3.0.1",
  "info": {
    "title": "External Service for demo bank",
    "description": "### External Service for demo bank",
    "version": "1.0",
    "x-vcap-service-name": "DemoBankRestServices"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "security": [
    {
      "basicAuth": []
    }
  ],
  "tags": [
    {
      "name": "DemoBankRestServices"
    }
  ],
  "paths": {
    "/accounts/{accountName}": {
      "get": {
        "summary": "Retrieves an account",
        "description": "Retrieves the account with specific name",
        "operationId": "getAccount",
        "parameters": [
          {
            "name": "accountName",
            "in": "path",
            "description": "Name of the account",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The response when system finds an account with given name",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/accountDetails"
                }
              }
            }
          },
          "400": {
            "description": "Error response if the account name parameter is less than minimum characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          },
          "404": {
            "description": "Error response if the account is not supported by service or account is not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Updates an account",
        "description": "Updates the account with specified name",
        "operationId": "updateAccount",
        "parameters": [
          {
            "name": "accountName",
            "in": "path",
            "description": "Name of the account",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountType",
            "in": "query",
            "description": "The type of account",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded; charset=UTF-8": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The response when system finds an account with given name",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/accountDetails"
                }
              }
            }
          },
          "400": {
            "description": "Error response if the account name parameter is less than minimum characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          },
          "404": {
            "description": "Error response if the account is not supported by service or account is not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Add an account",
        "description": "Add an account to the database",
        "operationId": "addAccount",
        "parameters": [
          {
            "name": "accountName",
            "in": "path",
            "description": "Name of the account",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountType",
            "in": "query",
            "description": "The type of account",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded; charset=UTF-8": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The response when the account does not already exist and we can create one",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/accountDetails"
                }
              }
            }
          },
          "400": {
            "description": "Error response if the account name parameter is less than minimum characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          },
          "404": {
            "description": "Error response if the account is not supported by service or account is not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          },
          "409": {
            "description": "The response when the account already exists and we cannot create one",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/accountDetails"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Deletes an account",
        "description": "Deletes the account with specific name",
        "operationId": "DeleteAccount",
        "parameters": [
          {
            "name": "accountName",
            "in": "path",
            "description": "Name of the account",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "The response when system finds an account with given name",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Error response if the account name parameter is less than minimum characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          },
          "404": {
            "description": "Error response if the account is not supported by service or account is not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/errorModel"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "accountDetails": {
        "required": [
          "availableBal",
          "id",
          "name",
          "type"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "id"
          },
          "name": {
            "type": "string",
            "description": "name"
          },
          "type": {
            "type": "string",
            "description": "type"
          },
          "availableBal": {
            "type": "string",
            "description": "availableBal"
          }
        }
      },
      "errorModel": {
        "required": [
          "errorCode",
          "errorMessage"
        ],
        "type": "object",
        "properties": {
          "errorCode": {
            "type": "string",
            "description": "A service-specific error code."
          },
          "errorMessage": {
            "type": "string",
            "description": "A service-specific error code."
          }
        }
      }
    },
    "securitySchemes": {
      "basicAuth": {
        "type": "http",
        "scheme": "basic"
      }
    }
  }
}
 
Chargement
Salesforce Help | Article