Forum Discussion

standreu's avatar
standreu
Visitor
5 months ago

Issue when send an array of json in a multipart/form-data

Hello, 

I am receiving an issue when I try to send an array of json inside a multipart/form-data with

openapi 3.0.3.

By the moment I only send an item json:

{
  "componentName": "string",
  "images": [
    "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  ],
  "numOfInstances": 0,
  "restartPolicy": "RESTART_POLICY_ALWAYS",
  "commandLineParams": {
    "command": [
      "string"
    ],
    "commandArgs": [
      "string"
    ]
  },
  "exposedInterfaces": [
    {
      "interfaceId": "string",
      "commProtocol": "TCP",
      "commPort": 0,
      "visibilityType": "VISIBILITY_EXTERNAL",
      "network": "string",
      "InterfaceName": "string"
    }
  ],
  "computeResourceProfile": {
    "cpuArchType": "ISA_X86_64",
    "numCPU": {
      "whole": {
        "value": 2
      },
      "decimal": {
        "value": 0.5
      },
      "millivcpu": {
        "value": "500m"
      }
    },
    "memory": 0,
    "diskStorage": 0,
    "gpu": [
      {
        "gpuVendorType": "Nvidia",
        "gpuModeName": "string",
        "gpuMemory": 0,
        "numGPU": 0
      }
    ],
    "vpu": 0,
    "fpga": 0,
    "hugepages": [
      {
        "pageSize": "2MB",
        "number": 0
      }
    ],
    "cpuExclusivity": true
  },
  "compEnvParams": [
    {
      "envVarName": "string",
      "envValueType": "USER_DEFINED",
      "envVarValue": "string",
      "envVarSrc": "string"
    }
  ],
  "deploymentConfig": {
    "configType": "DOCKER_COMPOSE",
    "contents": "string"
  },
  "persistentVolumes": [
    {
      "volumeSize": "10Gi",
      "volumeMountPath": "string",
      "volumeName": "string",
      "ephemeralType": false,
      "accessMode": "RW",
      "sharingPolicy": "EXCLUSIVE"
    }
  ]
}

Swagger aspect:

But I am receiving  the next error:

The definition in swagger yaml is:

      requestBody:
        description: An application can consist of multiple components. App providers are allowed to define separate artefacts for each component or they could define a consolidated artefact at application level.
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - artefactId
                - appProviderId
                - artefactName
                - artefactVersionInfo
                - artefactVirtType
                - artefactDescriptorType
                - componentSpec
              properties:
                artefactId:
                  $ref: '#/components/schemas/ArtefactId'
                
                ... Other properties hidden. Comment added for this chat 
                
                componentSpec:
                  description: Details about compute, networking and storage requirements for each component of the application. App provider should define all information needed to instantiate the component. If artefact is being defined at component level this section should have information just about the component. In case the artefact is being defined at application level the section should provide details about all the components.
                  type: array
                  items:
                    $ref: '#/components/schemas/ComponentSpec'
                  minItems: 1
            encoding:
              componentSpec:
                contentType: application/json
        required: true

I have added encoding at the same level than schema.

The definition of componentSpec is:

ComponentSpec:
  type: object
  required:
    - componentName
    - images
    - numOfInstances
    - restartPolicy
    - computeResourceProfile
  properties:
    componentName:
      type: string
      pattern: ^[A-Za-z0-9][A-Za-z0-9_]{6,62}[A-Za-z0-9]$
      description: Must be a valid RFC 1035 label name. Component name must be unique with an          application
    images:
      description: List of all images associated with the component. Images are specified using the file  identifiers. Partner OP provides these images using file upload api.
      type: array
      items:
        $ref: '#/components/schemas/FileId'
      minItems: 1
   numOfInstances:
     type: integer
     format: int32
     description: Number of component instances to be launched.
   restartPolicy:
     type: string
    enum:
      - RESTART_POLICY_ALWAYS
     - RESTART_POLICY_NEVER
     description: How the platform shall handle component failure
   commandLineParams:
     $ref: '#/components/schemas/CommandLineParams'
   exposedInterfaces:
     description: Each application component exposes some ports either for external users or for inter component communication. Application provider is required to specify which ports are to be exposed and the type of traffic that will flow through these ports.
     type: array
     items:
       $ref: '#/components/schemas/InterfaceDetails'
     minItems: 1
  computeResourceProfile:
    $ref: '#/components/schemas/ComputeResourceInfo'
  compEnvParams:
    type: array
   items:
     $ref: '#/components/schemas/CompEnvParams'
 deploymentConfig:
   $ref: '#/components/schemas/DeploymentConfig'
 persistentVolumes:
  description: The ephemeral volume a container process may need to temporary store internal data
  type: array
  items:
    $ref: '#/components/schemas/PersistentVolumeDetails'
  minItems: 1

Finally, the curl command formed in swagger is:

curl -X POST "http://127.0.0.1:8989/operatorplatform/federation/v1/fdfdfdfdfdf/artefact" -H "accept: */*" -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJXVWVkU0Y1dVZjU0pKVVVpZnphNGFNdnRCOHdhV0lJWUZQRTJVRE9WTERZIn0.eyJleHAiOjE3MDQzNjI2MDMsImlhdCI6MTcwNDM2MjMwMywianRpIjoiYWNiM2NkMTAtODk3OS00ZDQxLWI5ZDgtM2ExZjkzMTQ3NmY0IiwiaXNzIjoiaHR0cDovLzEyNy4wLjAuMTo5MDkwL2F1dGgvcmVhbG1zL21lYy1mZWRlcmF0aW9uIiwic3ViIjoiNGMyYmNmZmQtYmQ1MC00YjI0LWI0NzYtNDliYjcxNDdkMmU4IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoib3JpZ2luYXRpbmctb3AtMSIsImFjciI6IjEiLCJzY29wZSI6IiIsImNsaWVudElkIjoib3JpZ2luYXRpbmctb3AtMSIsImNsaWVudEhvc3QiOiIxNzIuMjQuMC4xIiwiY2xpZW50QWRkcmVzcyI6IjE3Mi4yNC4wLjEifQ.0oyp4A0g-lIbwKqc7rewCidjL84j7vIy01WS_7qL_oyuJvQ7zMV4bUYPote-iVqFZfG73-nldqMBPkAzFK_GPiheaN5nQRK8XChDRTadrKSzUNT4VlRjHOGUWLeflB1zF8I7U6HmWa8BDCUZxT633RZr7mJaSIyW1CIR8YZmpbmXxLIXTDK7Ws9lKLo_zpMEYGeY2lOpLwniPu7t7bJtCMDcRqn6kiytWnwwVOJPbWJtcq9rq63yLpW8zxnV55dvwGTQsbcFS2iT2Y6FWf_-PGp28ulGAyQ1UXV_kN2fbhjJ0bJRiYqLC7fAqOxXnymF3256u1Gfw6hWClhZvPkugQ" -H "Content-Type: multipart/form-data" -F "artefactId=dfdfdfdfdfdf" -F "appProviderId=dfddfdfdfdfdfff" -F "artefactDescriptorType=COMPONENTSPEC" -F "artefactVersionInfo=fddfdfdfdfdfddfdf" -F "componentSpec=["{\n \"componentName\": \"string\",\n \"images\": [\n \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"\n ],\n \"numOfInstances\": 0,\n \"restartPolicy\": \"RESTART_POLICY_ALWAYS\",\n \"commandLineParams\": {\n \"command\": [\n \"string\"\n ],\n \"commandArgs\": [\n \"string\"\n ]\n },\n \"exposedInterfaces\": [\n {\n \"interfaceId\": \"string\",\n \"commProtocol\": \"TCP\",\n \"commPort\": 0,\n \"visibilityType\": \"VISIBILITY_EXTERNAL\",\n \"network\": \"string\",\n \"InterfaceName\": \"string\"\n }\n ],\n \"computeResourceProfile\": {\n \"cpuArchType\": \"ISA_X86_64\",\n \"numCPU\": {\n \"whole\": {\n \"value\": 2\n },\n \"decimal\": {\n \"value\": 0.5\n },\n \"millivcpu\": {\n \"value\": \"500m\"\n }\n },\n \"memory\": 0,\n \"diskStorage\": 0,\n \"gpu\": [\n {\n \"gpuVendorType\": \"Nvidia\",\n \"gpuModeName\": \"string\",\n \"gpuMemory\": 0,\n \"numGPU\": 0\n }\n ],\n \"vpu\": 0,\n \"fpga\": 0,\n \"hugepages\": [\n {\n \"pageSize\": \"2MB\",\n \"number\": 0\n }\n ],\n \"cpuExclusivity\": true\n },\n \"compEnvParams\": [\n {\n \"envVarName\": \"string\",\n \"envValueType\": \"USER_DEFINED\",\n \"envVarValue\": \"string\",\n \"envVarSrc\": \"string\"\n }\n ],\n \"deploymentConfig\": {\n \"configType\": \"DOCKER_COMPOSE\",\n \"contents\": \"string\"\n },\n \"persistentVolumes\": [\n {\n \"volumeSize\": \"10Gi\",\n \"volumeMountPath\": \"string\",\n \"volumeName\": \"string\",\n \"ephemeralType\": false,\n \"accessMode\": \"RW\",\n \"sharingPolicy\": \"EXCLUSIVE\"\n }\n ]\n}"]" -F "artefactName=fddfdfdfddfdfdfd" -F "artefactVirtType=CONTAINER_TYPE"

 

No RepliesBe the first to reply