Hi friends, I have an error during yaml API testing in Swagger editor
I have duplicate mapping key error in line no 98
I try to force execute the testing I have :
Failed to fetch.
Possible Reasons:
CORS
Network Failure
URL scheme must be "http" or "https" for CORS request. ----- this error please help me!!..
openapi: 3.0.0
info:
title: 06-jobs-api
contact: {}
version: '1.0'
servers:
- url: https://new-jobs-api.herokuapp.com/api/v1
variables: {}
paths:
/auth/register:
post:
tags:
- Auth
summary: register
operationId: register
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/registerrequest'
example:
name: josh
email: josh#gmail.com
password: joshgmail.com
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
/auth/login:
post:
tags:
- Auth
summary: login
operationId: login
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/loginrequest'
example:
email: john#gmail.com
password: john#gmail.com
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
/jobs:
post:
tags:
- Jobs
summary: create job
operationId: createjob
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/createjobrequest'
example:
company: mongodb
position: back-end developer
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
get:
tags:
- Jobs
summary: get all jobs
operationId: getalljobs
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
/jobs/{id}:
parameters:
- in: path
name: id
schema:
type: string
required: true
description: The user ID
get: ----- here I have an error line no 98
tags:
- Jobs
summary: get single job
operationId: getsinglejob
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
patch:
tags:
- Jobs
summary: update job
operationId: updatejob
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/updatejobrequest'
example:
company: prime
position: front-end developer
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
delete:
tags:
- Jobs
summary: delete job
operationId: deletejob
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
components:
schemas:
registerrequest:
title: registerrequest
required:
- name
- email
- password
type: object
properties:
name:
type: string
email:
type: string
password:
type: string
example:
name: josh
email: josh#gmail.com
password: joshgmail.com
createjobrequest:
title: createjobrequest
required:
- company
- position
type: object
properties:
company:
type: string
position:
type: string
example:
company: mongodb
position: back-end developer
updatejobrequest:
title: updatejobrequest
required:
- company
- position
type: object
properties:
company:
type: string
position:
type: string
example:
company: prime
position: front-end developer
loginrequest:
title: loginrequest
required:
- email
- password
type: object
properties:
email:
type: string
password:
type: string
example:
email: john#gmail.com
password: john#gmail.com
securitySchemes:
httpBearer:
type: http
scheme: bearer
security:
- httpBearer: []
tags:
- name: Misc
description: ''
- name: Auth
description: ''
- name: Jobs
description: ''
You need to unindent /jobs/{id} in line 90 by two spaces.
Related
Is possible to match each element of a nested array response (using contains) using just one schema?
I have a set of yml files with request params and response schemas, like this one:
response:
appId: '#string'
attributes: '#array'
login: '#string'
permissions: '#array'
metadata:
roles: '##array'
userData:
description: '#string'
employeeId: '#string'
employeeNumber: '##string'
id: '#string'
login: '#string'
mail: '#string'
name: '#string'
and then, in a reusable feature:
* def req = read(<testDataFile>)
* match response contains req.response
I can match nested objects with just one schema but I'm not sure if it's possible use the schema to match nested arrays
maybe like:
response:
appId: '##string'
attributes: '##array'
attributes[*]:
key: '#string'
or any other expression
Thanks a lot
You can't do this with a single "schema" and you have to declare the repeating element separately, as a Karate variable: https://github.com/intuit/karate#schema-validation
* def foo = { a: '#number' }
* def bar = { baz: [{ a: 1 }, { a: 2 }, { a: 3 }] }
* match each bar.baz == foo
* match bar == { baz: '#[] foo' }
Is possible to match each element of a nested array response (using contains) using just one schema?
I have a set of yml files with request params and response schemas, like this one:
response:
appId: '#string'
attributes: '#array'
login: '#string'
permissions: '#array'
metadata:
roles: '##array'
userData:
description: '#string'
employeeId: '#string'
employeeNumber: '##string'
id: '#string'
login: '#string'
mail: '#string'
name: '#string'
and then, in a reusable feature:
* def req = read(<testDataFile>)
* match response contains req.response
I can match nested objects with just one schema but I'm not sure if it's possible use the schema to match nested arrays
maybe like:
response:
appId: '##string'
attributes: '##array'
attributes[*]:
key: '#string'
or any other expression
Thanks a lot
You can't do this with a single "schema" and you have to declare the repeating element separately, as a Karate variable: https://github.com/intuit/karate#schema-validation
* def foo = { a: '#number' }
* def bar = { baz: [{ a: 1 }, { a: 2 }, { a: 3 }] }
* match each bar.baz == foo
* match bar == { baz: '#[] foo' }
I need to define a response header parameter that would be common for all the 2xx response codes in the RAML API.
I only found a way to define the parameter per each HTTP code like this:
responses:
200:
headers:
X-Transaction-Id:
type: string
But I need to do something like this:
responses:
[200-300):
headers:
X-Transaction-Id:
type: string
Any help pls?
Cannot do that. You need to declare each status code separately.
Why don't you try implementing it as a resource type in a library.
#%RAML 1.0 Library
usage: |
All common response types...
types:
common-response:
type: object
properties:
key1: string
key2: string
resourceTypes:
common_response_types:
description: Common response types for API
get?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
post?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
patch?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
delete?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
The you can call it using this.
uses:
common_responses: libraries/common-responses.raml
/getuser:
type: common_responses.common_response_types
I am creating API by Swagger 2.0. Everything is good on Swagger 2.0, but, when build it to Slate, all the example value is not shown, just show the data type.
Ex. In swagger, what I want is:
{
"cd": 0,
"data": {
"Num1": "113.90083333",
"Num2": "113.5991"
}
}
But in Slate interface after being built,
{
"cd": "string",
"data": {
"Num1": "number",
"Num2": "number"
}
}
YAML code:
/mar:
get:
tags:
- MP
operationId: "MP1"
produces:
- application/json
responses:
200:
description: "WELL"
schema:
type: object
properties:
cd:
type: string
example: 0
data:
type: object
properties:
Num1:
type: number
example: "113.90083333"
Num2:
type: number
example: "113.5991"
I have created a raml in anypoint platform below is my RAML file
#%RAML 0.8
title: es-be-crm-dev
version: 001-dev
#baseUri: http://localhost:8081/api
baseUri: https://mocksvc.mulesoft.com/mocks/44267573-73b2-4369-8e2d- 3a6abbf20e34/api
traits:
- rate-limited:
queryParameters:
client_id:
type: string
client_secret:
type: string
schemas:
- api-request-schema: !include schemas/api-request-schema.json
/teams/{teamId}/teamMembers:
post:
description: Delete Team Member(s) from specified Team
headers:
Accept:
displayName: Accepted response format
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
Content-Type:
displayName: body Mime Type
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
body:
application/json:
schema: api-request-schema
example: !include examples/api-request-example.json
responses:
201:
description: Returned when the entity has been successfully created
headers:
ETag:
displayName: Entity Tag
description: Hash of the previously requested resource
type: string
example: asd8asd98hlk209u098asdfmoiun4023
required: false
401:
description: Returned when the user is not authorized to add a member
delete:
description: Adds Team Member(s) in specified Team
headers:
Accept:
displayName: Accepted response format
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
Content-Type:
displayName: body Mime Type
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
body:
application/json:
schema: api-request-schema
example: !include examples/api-request-example.json
responses:
201:
description: Returned when the entity has been successfully created
headers:
ETag:
displayName: Entity Tag
description: Hash of the previously requested resource
type: string
example: asd8asd98hlk209u098asdfmoiun4023
required: false
401:
description: Returned when the user is not authorized to delete a member
below is api-request-example.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"teamMembers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"teamMember": {
"type": "object",
"properties": {
"empID": {
"type": "string"
},
"sourceSystemId": {
"type": "string"
},
"sourceSystemObjectId": {
"type": "string"
}
},
"required": [
"empID",
"sourceSystemId",
"sourceSystemObjectId"
]
}
},
"required": [
"teamMember"
]
}
}
},
"required": [
"teamMembers"
]
}
below is Example file
{
"teamMembers": [{
"teamMember": {
"empID": "d3193f53-5f07-e611-80e3-a45d36fc4f90",
"sourceSystemId": "abc",
"sourceSystemObjectId": "abc"
}
}]
}
whenever i try to mock my api in it throws an error with status code 400
{
"error": "schema did not parse: Unexpected token a"
}
is there anything that i am missing here ???
Has the error message says mule is not able to parse your schema and this is probably because the ApiKit version you are using does not support aliases.
That's way he says can't parse a.
Change it with a direct include
schema: !include api-request-schema.json
I know is not ideal but is just a little more to write.