-1

I am trying to develop a server on Node.js. There is a POST request where I need to send a value for grade, this value can be an integer or null. I tried any type of ways, but no success.

Here is my API definition:

swagger: "2.0"
paths:
  /credits/operations:
    post:
      operationId: "creditsOperationsPOST"
      parameters:
        - in: "body"
          name: "credito"
          required: false
          schema:
            $ref: "#/definitions/credito"
      responses:
        200:
          description: "Created"
      x-swagger-router-controller: "Credits"

definitions:
  credito:
    type: "object"
    properties:
      sgecode:
        type: "string"
      grade:
        type: "integer"
        x-nullable: true

Can someone help me please?

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Can you clarify what you mean by "no success" - do you get an error? If so, what kind of error - a YAML syntax error reported by the editor, or an error response received from your server after making a request, or something else? Also please post your YAML file. – Helen Dec 05 '18 at 19:55
  • Hi @Helen, this is the yaml file. Thanks for your help. swagger: "2.0" paths: /credits/operations: post: operationId: "creditsOperationsPOST" parameters: - in: "body" name: "credito" required: false schema: $ref: "#/definitions/credito" responses: 200: description: "Created" x-swagger-router-controller: "Credits" definitions: credito: type: "object" properties: sgecode: type: "string" grade: type: "integer" x-nullable: true – Lucas Calado Cerbelo Dec 06 '18 at 10:44
  • Possible duplicate of [nullable fields in swagger on node.js](https://stackoverflow.com/q/38139657/113116), [Additional properties not allowed: nullable swagger](https://stackoverflow.com/questions/48504816/additional-properties-not-allowed-nullable-swagger), [How to define a property that can be string or null in OpenAPI (Swagger)?](https://stackoverflow.com/q/48111459/113116) – Helen Dec 08 '18 at 18:39

1 Answers1

-1

I found a way to use null and integer. On the YAML file, I added this

grade:
    type: ["integer","null"]

and works well for me.

  • While this _might_ work in some tools, this is [not valid OpenAPI syntax](https://stackoverflow.com/a/48114322/113116) and won't work in OpenAPI-compliant tools. – Helen Dec 08 '18 at 18:32