Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Swagger shows 'string' instead of body example

I am trying to set a default json body for the following endpoint:

const loginJsonSchema = {
    'type': 'object',
    'properties': {
        'username': {
            'type': 'string',
            'example': 'my_user' // this property is ignored
        },
        'password': {
            'type': 'string',
            'example': 'my_password' // this property is ignored
        },
    },
    'required': ['username', 'password'],
}


const paths = {
    "/auth/login": {
        "post": {
            "tags": [
                "auth"
            ],
            "summary": "Login",
            "description": "",
            "operationId": "auth-login",
            "consumes": [
                "application/json"
            ],
            "parameters": [
                {
                    "name": "Credentials",
                    "in": "body",
                    "description": "Your credentials",
                    "required": true,
                    "schema": {
                        loginJsonSchema
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "successful operation",
                    "schema": loginSuccessResponseSchema,
                },
            },
        }
    },

Instead of the example values, I get the default body as 'string':

enter image description here

I expected the following default body:

{
  "username": "my_user",
  "password": "my_password"
}

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You need to remove the extra { } from schema like this:

const paths = {
"/auth/login": {
    "post": {
        "tags": [
            "auth"
        ],
        "summary": "Login",
        "description": "",
        "operationId": "auth-login",
        "consumes": [
            "application/json"
        ],
        "parameters": [
            {
                "name": "Credentials",
                "in": "body",
                "description": "Your credentials",
                "required": true,
                "schema": loginJsonSchema
            }
        ],
        "responses": {
            "200": {
                "description": "successful operation",
                "schema": loginSuccessResponseSchema,
            },
        },
    }
},

See here: https://jsfiddle.net/5gfpy1qr/

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!