SwaggerUI/YAML - Parser error bad indentation of a mapping entry - swagger

Screenshot of Swagger Editor & code
Hi, I am new to API testing and Swagger and am getting this parser error message in the Swagger Editor and I am having problems locating the problem.
Bellow is a copy paste of the code.
The error message is "bad indentation of a mapping entry" and is displayed where --> in: "path".
I followed this YouTube Tutorial --> https://www.youtube.com/watch?v=CoUl9_NWdqQ
swagger: '2.0'
info:
version: 'v1.0'
title: 'Random'
# Added by API Auto Mocking Plugin
host: virtserver.swaggerhub.com
basePath: /GroovySalmon/DOITNOW/v1.0
schemes:
- https
paths:
/vehicles/{id}/data_request/drive_state:
get:
operationId: "drive_state"
description: "Returns the driving and position state of the vehicle"
parameters:
**-name: "id"**
in: "path"
description: "The ID number of the car"
required: true
type: "String"
responses:
200:
description: "Success"
schema:
properties:
shift_state:
type: "String"
example: "sport"
speed:
type: "number"
format: "double"
example: 94.5
latitude:
description: "degrees north of the equator"
type: "number"
format: "double"
example: 37.345
longitude:
description: "degrees west of the prime meridian"
type: "number"
format: "double"
example: 122.1243
heading:
description: "integer compass heading"
type: "integer"
format: "int32"
minimum: 0
maximum: 359
example: 4
gps_as_of:
description: "unix timestamp of gps fix"
example: "1234934991232"

Change
type: "String"
to
type: "string"
Note the lowercase "s" in "string".
All OpenAPI type values are lowercase and case-sensitive.
Also, make sure there are spaces after - in parameter definitions (and in YAML lists in general), and that the indentation is correct:
- name: "id"
in: "path"
...

Related

On Swagger, which is a correct way to write yaml file? [duplicate]

This question already has answers here:
Post a json body with swagger
(1 answer)
How to describe this POST JSON request body in OpenAPI (Swagger)?
(3 answers)
Closed 2 years ago.
swagger: "2.0"
info:
version: "1.0.0"
title: "CCA API"
host: localhost:1337
basePath: /v1
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/user/login:
post:
description: Access a user account
summary: User Account Access
operationId: loginAccount
parameters:
- name: email
dataType: string
in: body
required: true
description: Your email
- name: password
dataType: string
in: body
required: true
description: Your password
responses:
"200":
description: Successfully signed in
schema:
type: object
properties:
email:
type: string
firstName:
type: string
lastName:
type: string
token:
type: string
userType:
type: string
401:
description: Invalid email or password.
Which is a correct way to write yaml file?
I have this error: "Not a valid parameter definition"
in each declaration of the parameters...
I would also like to know the correct way to integrate Sails JS with Swagger?
As Vantroys said dataType is not the correct key. It's type.
But in this case you try to define an post method and need to define some type of input data, like in the example below.
Have look at the pet store example from swagger itself:
https://editor.swagger.io/
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
Concerning your parameters : I think you have to use "type", and not "dataType" :
parameters:
- name: email
type: string
in: body
required: true
description: Your email
- name: password
type: string
in: body
required: true
description: Your password

Swagger editor is throwing error while specifying the response "Not a valid response definition"

I am trying to generate the API documentation using swagger editor. I specified my API specification as follow
paths:
/opendata/v1/{index}:
get:
tags: [verification]
description: Verify the person information
parameters:
- name: index
in: path
description: specific data index
required: true
type: string
- name: name
in: query
description: name of a person
required: false
type: string
- name: company name
in: query
description: name of a company
required: false
type: string
responses:
'200':
description: Success
content:
application/json:
schemas:
$ref: '#/responses/200'
responses:
'200':
description: Success
schema:
type: object
properties:
verification:
type: string
But its always showing error in the editor that "Not a valid response definition". I checked the specification for response from here. What changes I should do so that error will not come.
Note: I want the response in the json form like below:
{
verification:string
}
You are mixing OpenAPI/Swagger 2.0 and OpenAPI 3.0 syntax. Your spec seems to be swagger: '2.0', so you should use:
paths:
/opendata/v1/{index}:
get:
...
produces:
- application/json
responses:
200:
$ref: '#/responses/200'
Here's a related OpenAPI/Swagger 2.0 guide: Describing Responses

Swagger-codegen generated code having issues Routing requests with parameters in path

I created my api definition using swagger and have generated the server code using Swagger-tools in NodeJs. The SwaggerRouter handles all routes properly excepts the routes with ID.
For example , routes like
/v1/factoris/self
/v1/factoris/create
are directed to the right controller
but calls with IDs
/v1/factoris/{factoris_id}
are returned as invalid routes.
Any idea what I might be missing ?
Here is a sample of the swagger specs
/factoris/create:
post:
tags:
- "Factoris"
summary: "Create New Factori"
description: ""
operationId: "factorisCreatePOST"
parameters:
- in: "body"
name: "FactoriCreate"
description: "Create a new factory"
required: true
schema:
$ref: "#/definitions/FactoriCreate"
responses:
201:
description: "A single factori object"
schema:
$ref: "#/definitions/inline_response_201"
405:
description: "Method not allowed"
schema:
$ref: "#/definitions/inline_response_405"
security:
- oauth2:
- "admin"
x-swagger-router-controller: "Factoris"
/factoris/{factori-id}:
get:
tags:
- "Factoris"
summary: "Factori Information"
description: ""
operationId: "factorisFactori_idGET"
parameters:
- name: "factori-id"
in: "path"
description: "The factori identifier string"
required: true
type: "string"
- name: "expand"
in: "query"
description: "Provide expanded information on Assemblies or Products or Users"
required: true
type: "string"
responses:
200:
description: "A single factori object"
schema:
$ref: "#/definitions/inline_response_201"
404:
description: "Factori not found"
schema:
$ref: "#/definitions/inline_response_404"
security:
- oauth2:
- "codeadmin"
x-swagger-router-controller: "Factoris"
After some trial and error, I figured out that path parameter does not work if its has a "-" (factori-id)
so changing factori-id to factori_id fixed it. But its still a bug since the path parameter cannot handle "-"
here is the open issue created in Swagger-codegen
https://github.com/swagger-api/swagger-codegen/issues/5763

Swagger Editor Parameter Errors

I'm trying to draft up an API in Swagger for easy viewing through SwaggerUI, but I'm encountering errors I don't quite understand. As far as I can tell, I'm adhering to the specification.
/history/tags/{tag_id}:
get:
summary: "Gets the history of this tag."
description: "Warning: not using both the start and end date fields may result in excessively long responses."
operationId: "get_tag_history"
produces:
- "application/json"
parameters:
- name: "tag_id"
in: "path"
description: "UUID for this tag."
type: "string"
required: true
- name: "start_date"
in: "query"
description: "Start date for history"
type: "String"
foramt: "date"
required: false
- name: "end_date"
in: "query"
description: "End date for history"
type: "String"
foramt: "date"
required: false
responses:
200:
description: "Operation success"
schema:
$ref: "#/definitions/Tag_history"
400:
description: "Invalid request"
The second and third parameters are throwing Schema error at paths./history/tags/{tag_id}.get.parameters[1]
is not exactly one from <#/definitions/parameter>,<#/definitions/jsonReference> (or parameters[2], depending on which parameter).
Most other problems I've seen are simply people forgetting to use schema:, but that isn't how query parameters are structured. Any ideas?
Change
type: "String"
foramt: "date"
to
type: "string"
format: "date"
type is case-sensitive, and format was misspelled.

Data does not match any schemas from 'oneOf' - Error

Am hitting the following error with swagger online editor
Data does not match any schemas from 'oneOf'
'/tenants/tenant_id/groups/group_id':
get:
description: 'Returns the group with specific id ( id, name, description, tenant_id... ) along with end point pools ( id, name, description, source, tenant_id... ) associated with this particular groups'
operationId: getGroupWithKey
consumes:
- application/json
- text/plain, */*
produces:
- text/xml
parameters:
- in: header
name: 'X-AuthToken'
description: authentication token obtained during login
required: true
schema:
$ref: '#/definitions/token_string'
responses:
'200':
description: OK (group with provided id received)
schema:
$ref: '#/definitions/getGroupWithKey'
default:
description: error
schema:
$ref: '#/definitions/errorModel'
definitions:
### Login Definitions ###
token_string:
type: object
required:
- 'X-AuthToken'
properties:
X-AuthToken:
type: string
Error is as bellow points to line 206 which is line starting with "parameters"
✖ Swagger Error
Data does not match any schemas from 'oneOf'
Jump to line 206
Details
Object
code: "ONE_OF_MISSING"
message: "Data does not match any schemas from 'oneOf'"
path: Array [5]
0: "paths"
1: "/tenants/tenant_id/groups/group_id"
2: "get"
3: "parameters"
4: "0"
inner: Array [2]
0: Object
code: "ONE_OF_MISSING"
message: "Data does not match any schemas from 'oneOf'"
path: Array [5]
inner: Array [2]
1: Object
code: "OBJECT_MISSING_REQUIRED_PROPERTY"
message: "Missing required property: $ref"
path: Array [5]
level: 900
type: "Swagger Error"
description: "Data does not match any schemas from 'oneOf'"
lineNumber: 206
I tried changing the type: string under definition, still no luck.
Am pretty sure I am missing proper type value here, appreciate any help
Thanks you
When defining a header parameter you cannot use schema, it's allowed only when in: bodyis used.
Therefore a header parameter can only be an atomic property (string, number, ...).
It seems that you want to define a reusable header parameter, you do that this way:
Define token_string in parameters section
Then use it with a $refin operation's parameters
(I also add dummy getGroupWithKey and errorModel to make the definition valid):
swagger: '2.0'
info:
version: 1.0.0
title: Header API
description: A simple API to learn how you can define headers
paths:
'/tenants/tenant_id/groups/group_id':
get:
description: 'Returns the group with specific id ( id, name, description, tenant_id... ) along with end point pools ( id, name, description, source, tenant_id... ) associated with this particular groups'
operationId: getGroupWithKey
consumes:
- application/json
- text/plain, */*
produces:
- text/xml
parameters:
- $ref: '#/parameters/token_string'
responses:
'200':
description: OK (group with provided id received)
schema:
$ref: '#/definitions/getGroupWithKey'
default:
description: error
schema:
$ref: '#/definitions/errorModel'
parameters:
token_string:
in: header
name: X-AuthToken
type: string
description: authentication token obtained during login
required: true
definitions:
### Login Definitions ###
errorModel:
type: string
getGroupWithKey:
type: string
You can of course define you parameter inline if you want.
I suggest you to take a look at another question on the same topic Define global parameters

Resources