question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example fields being used as default values

See original GitHub issue

When using a json based swagger document, example values are being used a default values when default is not defined. The expectation is that example values would be ignored.

For example:

"paths": {
  "/companies": {
      "post": {
        "description": "Create a Company",
        "parameters": [
          {
            "name": "company",
            "in": "body",
            "description": "A Company",
            "required": true,
            "schema": {
              "$ref": "#/definitions/company"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Created",
            "schema": {
              "$ref": "#/definitions/company"
            }
          },
          "406": {
            "description": "Not Acceptable"
          }
        }
      }
    }
},
"definitions": {
    "company": {
      "type": "object",
      "properties": {
        "id": {
          "description": "unique identifier of a company",
          "example": "01234567-89ab-cdef-0123-456789abcdef",
          "format": "uuid",
          "maxLength": 37,
          "readOnly": true,
          "type": "string"
        },
        "name": {
          "description": "name of company",
          "example": "acme",
          "maxLength": 255,
          "readOnly": false,
          "type": "string"
        },
        "code": {
          "description": "unique code of company",
          "maxLength": 255,
          "type": "string"
        },
        "created_at": {
          "description": "when company was created",
          "example": "2001-01-01T12:00:00Z",
          "format": "date-time",
          "readOnly": true,
          "type": "string"
        },
        "updated_at": {
          "description": "when company was updated",
          "example": "2001-01-01T12:00:00Z",
          "format": "date-time",
          "readOnly": true,
          "type": "string"
        }
      },
      "required": [
        "name",
        "code"
      ]
    }
}

When sending a POST request to the /companies endpoint where the code value is defined, but the name field is empty. The result is the value acme being used as if it were a default value.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
joetennantcommented, May 23, 2017

😃

Thanks

1reaction
jamesacrescommented, May 17, 2019

This is still an issue, and a very bad bug?

https://github.com/APIDevTools/swagger-express-middleware/pull/99

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set default values for fields or controls - Microsoft Support
This article explains how to set a default value for a table field or for a control on a form in an Access...
Read more >
Use a function to provide default field values | Sicse
A default value can be set for fields that are attached to a content type (i.e., any field-able entity). The entered value is...
Read more >
Default Values and Placeholders - Formidable Forms
Default values will be used when a new entry is created or when a field is conditionally shown. Default values will not replace...
Read more >
Default Field Values - Salesforce Help
Default field values automatically insert the value of a custom field when a new record is created. You can use a default value...
Read more >
How to Add Default Values for Form Fields - WPForms
You can add a default value by typing text directly into the Default Value field. For our example, we'll add “General Inquiry” as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found