Not a valid parameter definition - yaml

/cancel:
post:
description: ''
summary: Cancel
operationId: Cancel
produces:
- application/json
parameters:
- name: Body
in: body
required: true
description: ''
schema:
$ref: '#/definitions/CancelRequest'
- name: Authorization
in: header
required: true
description: ''
schema:
$ref: '#/definitions/Authorization'
- name: Content-Type
in: header
required: true
type: string
description: ''
Here's the snippet. It says that on the line with $ref: '#/definitions/CancelRequest' there is a wrong parameter definition. What might be the problem?

The error is probably misleading, the problem is with other parameters:
The Content-Type header should be defined using the consumes keyword rather than a parameter:
/cancel:
post:
consumes:
- application/json
- application/xml
Header parameters require a type (not a schema) and the type must be a simple type and cannot be a $ref. So it should be:
- name: Authorization
in: header
required: true
description: ''
type: string # <-------
However, in case of the Authorization header you should probably use a security definition instead. For example, if your API uses Basic authentication:
securityDefinitions:
BasicAuth:
type: basic
paths:
/cancel:
post:
security:
- BasicAuth: []

Related

how to convert yaml file data to a string in bash

How to convert YAML file data into string output, so that we can use it as a body parameter in the below curl request with the correct escape pattern.
curl request
curl -s -H "Accept: application/json" -H "Content-Type: application/json" --location --request POST "${HOST}/api/v1/projects" --header "Authorization: Bearer "$token"" -d '{"name":"'${PROJECT_NAME}'","openAPISpec":"none","isFileLoad": "true","openText": '${openText}',"source": "API"}'
---
swagger: '2.0'
info:
description: 'This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For
this sample, you can use the api key `special-key` to test the authorization filters.'
version: 1.0.6
title: Swagger Petstore
termsOfService: http://swagger.io/terms/
contact:
email: apiteam#swagger.io
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
host: petstore.swagger.io
basePath: "/v2"
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: http://swagger.io
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: http://swagger.io
schemes:
- https
- http
paths:
"/pet/{petId}/uploadImage":
post:
tags:
- pet
summary: uploads an image
description: ''
operationId: uploadFile
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
type: integer
format: int64
- name: additionalMetadata
in: formData
description: Additional data to pass to server
required: false
type: string
- name: file
in: formData
description: file to upload
required: false
type: file
responses:
'200':
description: successful operation
schema:
"$ref": "#/definitions/ApiResponse"
security:
- petstore_auth:
- write:pets
- read:pets
"/pet":
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
"$ref": "#/definitions/Pet"
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- write:pets
- read:pets
put:
tags:
- pet
summary: Update an existing pet
description: ''
operationId: updatePet
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
"$ref": "#/definitions/Pet"
responses:
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- write:pets
- read:pets
"/pet/findByStatus":
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
produces:
- application/json
- application/xml
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: true
type: array
items:
type: string
enum:
- available
- pending
- sold
default: available
collectionFormat: multi
responses:
'200':
description: successful operation
schema:
type: array
items:
"$ref": "#/definitions/Pet"
'400':
description: Invalid status value
security:
- petstore_auth:
- write:pets
- read:pets
"/pet/findByTags":
get:
tags:
- pet
summary: Finds Pets by tags
description: Multiple tags can be provided with comma separated strings. Use
tag1, tag2, tag3 for testing.
operationId: findPetsByTags
produces:
- application/json
- application/xml
parameters:
- name: tags
in: query
description: Tags to filter by
required: true
type: array
items:
type: string
collectionFormat: multi
responses:
'200':
description: successful operation
schema:
type: array
items:
"$ref": "#/definitions/Pet"
'400':
description: Invalid tag value
security:
- petstore_auth:
- write:pets
- read:pets
deprecated: true
"/pet/{petId}":
get:
tags:
- pet
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
produces:
- application/json
- application/xml
parameters:
- name: petId
in: path
description: ID of pet to return
required: true
type: integer
format: int64
responses:
'200':
description: successful operation
schema:
"$ref": "#/definitions/Pet"
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- api_key: []
post:
tags:
- pet
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
- application/xml
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
type: integer
format: int64
- name: name
in: formData
description: Updated name of the pet
required: false
type: string
- name: status
in: formData
description: Updated status of the pet
required: false
type: string
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- write:pets
- read:pets
delete:
tags:
- pet
summary: Deletes a pet
description: ''
operationId: deletePet
produces:
- application/json
- application/xml
parameters:
- name: api_key
in: header
required: false
type: string
- name: petId
in: path
description: Pet id to delete
required: true
type: integer
format: int64
responses:
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- petstore_auth:
- write:pets
- read:pets
"/store/order":
post:
tags:
- store
summary: Place an order for a pet
description: ''
operationId: placeOrder
consumes:
- application/json
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: order placed for purchasing the pet
required: true
schema:
"$ref": "#/definitions/Order"
responses:
'200':
description: successful operation
schema:
"$ref": "#/definitions/Order"
'400':
description: Invalid Order
"/store/order/{orderId}":
get:
tags:
- store
summary: Find purchase order by ID
description: For valid response try integer IDs with value >= 1 and <= 10. Other
values will generated exceptions
operationId: getOrderById
produces:
- application/json
- application/xml
parameters:
- name: orderId
in: path
description: ID of pet that needs to be fetched
required: true
type: integer
maximum: 10
minimum: 1
format: int64
responses:
'200':
description: successful operation
schema:
"$ref": "#/definitions/Order"
'400':
description: Invalid ID supplied
'404':
description: Order not found
delete:
tags:
- store
summary: Delete purchase order by ID
description: For valid response try integer IDs with positive integer value.
Negative or non-integer values will generate API errors
operationId: deleteOrder
produces:
- application/json
- application/xml
parameters:
- name: orderId
in: path
description: ID of the order that needs to be deleted
required: true
type: integer
minimum: 1
format: int64
responses:
'400':
description: Invalid ID supplied
'404':
description: Order not found
"/store/inventory":
get:
tags:
- store
summary: Returns pet inventories by status
description: Returns a map of status codes to quantities
operationId: getInventory
produces:
- application/json
parameters: []
responses:
'200':
description: successful operation
schema:
type: object
additionalProperties:
type: integer
format: int32
security:
- api_key: []
"/user/createWithArray":
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithArrayInput
consumes:
- application/json
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: List of user object
required: true
schema:
type: array
items:
"$ref": "#/definitions/User"
responses:
default:
description: successful operation
"/user/createWithList":
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithListInput
consumes:
- application/json
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: List of user object
required: true
schema:
type: array
items:
"$ref": "#/definitions/User"
responses:
default:
description: successful operation
"/user/{username}":
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
produces:
- application/json
- application/xml
parameters:
- name: username
in: path
description: 'The name that needs to be fetched. Use user1 for testing. '
required: true
type: string
responses:
'200':
description: successful operation
schema:
"$ref": "#/definitions/User"
'400':
description: Invalid username supplied
'404':
description: User not found
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUser
consumes:
- application/json
produces:
- application/json
- application/xml
parameters:
- name: username
in: path
description: name that need to be updated
required: true
type: string
- in: body
name: body
description: Updated user object
required: true
schema:
"$ref": "#/definitions/User"
responses:
'400':
description: Invalid user supplied
'404':
description: User not found
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
produces:
- application/json
- application/xml
parameters:
- name: username
in: path
description: The name that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
"/user/login":
get:
tags:
- user
summary: Logs user into the system
description: ''
operationId: loginUser
produces:
- application/json
- application/xml
parameters:
- name: username
in: query
description: The user name for login
required: true
type: string
- name: password
in: query
description: The password for login in clear text
required: true
type: string
responses:
'200':
description: successful operation
headers:
X-Expires-After:
type: string
format: date-time
description: date in UTC when token expires
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user
schema:
type: string
'400':
description: Invalid username/password supplied
"/user/logout":
get:
tags:
- user
summary: Logs out current logged in user session
description: ''
operationId: logoutUser
produces:
- application/json
- application/xml
parameters: []
responses:
default:
description: successful operation
"/user":
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
consumes:
- application/json
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: Created user object
required: true
schema:
"$ref": "#/definitions/User"
responses:
default:
description: successful operation
securityDefinitions:
api_key:
type: apiKey
name: api_key
in: header
petstore_auth:
type: oauth2
authorizationUrl: https://petstore.swagger.io/oauth/authorize
flow: implicit
scopes:
read:pets: read your pets
write:pets: modify pets in your account
definitions:
ApiResponse:
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string
Category:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Category
Pet:
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
"$ref": "#/definitions/Category"
name:
type: string
example: doggie
photoUrls:
type: array
xml:
wrapped: true
items:
type: string
xml:
name: photoUrl
tags:
type: array
xml:
wrapped: true
items:
xml:
name: tag
"$ref": "#/definitions/Tag"
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: Pet
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Tag
Order:
type: object
properties:
id:
type: integer
format: int64
petId:
type: integer
format: int64
quantity:
type: integer
format: int32
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
enum:
- placed
- approved
- delivered
complete:
type: boolean
xml:
name: Order
User:
type: object
properties:
id:
type: integer
format: int64
username:
type: string
firstName:
type: string
lastName:
type: string
email:
type: string
password:
type: string
phone:
type: string
userStatus:
type: integer
format: int32
description: User Status
xml:
name: User
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
Below is the successful string output I got from the request payload when I use 'Inspect' from the google browser.
So when we convert the YAML file data to string from the Linux bash and use it in the curl request mentioned above for '${openText}' field we are expected to have the string like the one below the string output.
I tried to yq tool but don't know to use it or whether it will give the exact result.
Expected/Close-To-Expected is string output.
"---\nswagger: '2.0'\ninfo:\n description: 'This is a sample server Petstore server. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For\n this sample, you can use the api key `special-key` to test the authorization filters.'\n version: 1.0.6\n title: Swagger Petstore\n termsOfService: http://swagger.io/terms/\n contact:\n email: apiteam#swagger.io\n license:\n name: Apache 2.0\n url: http://www.apache.org/licenses/LICENSE-2.0.html\nhost: petstore.swagger.io\nbasePath: \"/v2\"\ntags:\n- name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: http://swagger.io\n- name: store\n description: Access to Petstore orders\n- name: user\n description: Operations about user\n externalDocs:\n description: Find out more about our store\n url: http://swagger.io\nschemes:\n- https\n- http\npaths:\n \"/pet/{petId}/uploadImage\":\n post:\n tags:\n - pet\n summary: uploads an image\n description: ''\n operationId: uploadFile\n consumes:\n - multipart/form-data\n produces:\n - application/json\n parameters:\n - name: petId\n in: path\n description: ID of pet to update\n required: true\n type: integer\n format: int64\n - name: additionalMetadata\n in: formData\n description: Additional data to pass to server\n required: false\n type: string\n - name: file\n in: formData\n description: file to upload\n required: false\n type: file\n responses:\n '200':\n description: successful operation\n schema:\n \"$ref\": \"#/definitions/ApiResponse\"\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n \"/pet\":\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: ''\n operationId: addPet\n consumes:\n - application/json\n - application/xml\n produces:\n - application/json\n - application/xml\n parameters:\n - in: body\n name: body\n description: Pet object that needs to be added to the store\n required: true\n schema:\n \"$ref\": \"#/definitions/Pet\"\n responses:\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: ''\n operationId: updatePet\n consumes:\n - application/json\n - application/xml\n produces:\n - application/json\n - application/xml\n parameters:\n - in: body\n name: body\n description: Pet object that needs to be added to the store\n required: true\n schema:\n \"$ref\": \"#/definitions/Pet\"\n responses:\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n \"/pet/findByStatus\":\n get:\n tags:\n - pet\n summary: Finds Pets by status\n description: Multiple status values can be provided with comma separated strings\n operationId: findPetsByStatus\n produces:\n - application/json\n - application/xml\n parameters:\n - name: status\n in: query\n description: Status values that need to be considered for filter\n required: true\n type: array\n items:\n type: string\n enum:\n - available\n - pending\n - sold\n default: available\n collectionFormat: multi\n responses:\n '200':\n description: successful operation\n schema:\n type: array\n items:\n \"$ref\": \"#/definitions/Pet\"\n '400':\n description: Invalid status value\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n \"/pet/findByTags\":\n get:\n tags:\n - pet\n summary: Finds Pets by tags\n description: Multiple tags can be provided with comma separated strings. Use\n tag1, tag2, tag3 for testing.\n operationId: findPetsByTags\n produces:\n - application/json\n - application/xml\n parameters:\n - name: tags\n in: query\n description: Tags to filter by\n required: true\n type: array\n items:\n type: string\n collectionFormat: multi\n responses:\n '200':\n description: successful operation\n schema:\n type: array\n items:\n \"$ref\": \"#/definitions/Pet\"\n '400':\n description: Invalid tag value\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n deprecated: true\n \"/pet/{petId}\":\n get:\n tags:\n - pet\n summary: Find pet by ID\n description: Returns a single pet\n operationId: getPetById\n produces:\n - application/json\n - application/xml\n parameters:\n - name: petId\n in: path\n description: ID of pet to return\n required: true\n type: integer\n format: int64\n responses:\n '200':\n description: successful operation\n schema:\n \"$ref\": \"#/definitions/Pet\"\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n security:\n - api_key: []\n post:\n tags:\n - pet\n summary: Updates a pet in the store with form data\n description: ''\n operationId: updatePetWithForm\n consumes:\n - application/x-www-form-urlencoded\n produces:\n - application/json\n - application/xml\n parameters:\n - name: petId\n in: path\n description: ID of pet that needs to be updated\n required: true\n type: integer\n format: int64\n - name: name\n in: formData\n description: Updated name of the pet\n required: false\n type: string\n - name: status\n in: formData\n description: Updated status of the pet\n required: false\n type: string\n responses:\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n delete:\n tags:\n - pet\n summary: Deletes a pet\n description: ''\n operationId: deletePet\n produces:\n - application/json\n - application/xml\n parameters:\n - name: api_key\n in: header\n required: false\n type: string\n - name: petId\n in: path\n description: Pet id to delete\n required: true\n type: integer\n format: int64\n responses:\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n security:\n - petstore_auth:\n - write:pets\n - read:pets\n \"/store/order\":\n post:\n tags:\n - store\n summary: Place an order for a pet\n description: ''\n operationId: placeOrder\n consumes:\n - application/json\n produces:\n - application/json\n - application/xml\n parameters:\n - in: body\n name: body\n description: order placed for purchasing the pet\n required: true\n schema:\n \"$ref\": \"#/definitions/Order\"\n responses:\n '200':\n description: successful operation\n schema:\n \"$ref\": \"#/definitions/Order\"\n '400':\n description: Invalid Order\n \"/store/order/{orderId}\":\n get:\n tags:\n - store\n summary: Find purchase order by ID\n description: For valid response try integer IDs with value >= 1 and <= 10. Other\n values will generated exceptions\n operationId: getOrderById\n produces:\n - application/json\n - application/xml\n parameters:\n - name: orderId\n in: path\n description: ID of pet that needs to be fetched\n required: true\n type: integer\n maximum: 10\n minimum: 1\n format: int64\n responses:\n '200':\n description: successful operation\n schema:\n \"$ref\": \"#/definitions/Order\"\n '400':\n description: Invalid ID supplied\n '404':\n description: Order not found\n delete:\n tags:\n - store\n summary: Delete purchase order by ID\n description: For valid response try integer IDs with positive integer value.\n Negative or non-integer values will generate API errors\n operationId: deleteOrder\n produces:\n - application/json\n - application/xml\n parameters:\n - name: orderId\n in: path\n description: ID of the order that needs to be deleted\n required: true\n type: integer\n minimum: 1\n format: int64\n responses:\n '400':\n description: Invalid ID supplied\n '404':\n description: Order not found\n \"/store/inventory\":\n get:\n tags:\n - store\n summary: Returns pet inventories by status\n description: Returns a map of status codes to quantities\n operationId: getInventory\n produces:\n - application/json\n parameters: []\n responses:\n '200':\n description: successful operation\n schema:\n type: object\n additionalProperties:\n type: integer\n format: int32\n security:\n - api_key: []\n \"/user/createWithArray\":\n post:\n tags:\n - user\n summary: Creates list of users with given input array\n description: ''\n operationId: createUsersWithArrayInput\n consumes:\n - application/json\n produces:\n - application/json\n - application/xml\n parameters:\n - in: body\n found\n put:\n tags:\n - user\n summary: Updated user\n \n password:\n type: string\n phone:\n type: string\n userStatus:\n type: integer\n format: int32\n description: User Status\n xml:\n name: User\nexternalDocs:\n description: Find out more about Swagger\n url: http://swagger.io\n\n"
You are setting JSON as the curl input, but you have YAML. So:
yq -p yaml -o json file.yaml | # convert YAML to JSON
curl -s -H "Accept: application/json" \
-H "Content-Type: application/json" \
--location \
--request POST "${HOST}/api/v1/projects" \
--header "Authorization: Bearer $token" \
-d "#/dev/stdin" https://<URL>
If you need to modify the YAML file, you can process it before with the yq command
The curl request header specifies it accepts 'application/json' but you're not passing in JSON.
To convert a yaml to a JSON string, instead of using sed do:
openText=$(yq -oj petstore.yaml)
Disclaimer: I wrote yq
I tried the below code.
openText=$(sed -z 's/\n/\\n/g' petstore.yaml | tr -d ' ')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" --location --request POST "${HOST}/api/v1/projects" --header "Authorization: Bearer "$token"" -d '{"name":"'${PROJECT_NAME}'","openAPISpec":"none","isFileLoad": "true","openText": '${openText}',"source": "API"}'
String output seems to be ok with ( sed -z 's/\n/\n/g' petstore.yaml | tr -d ' ')
---\nswagger:'2.0'\ninfo:\ndescription:'ThisisasampleserverPetstoreserver.Youcanfindoutmoreabout\nSwaggerat[http://swagger.io](http://swagger.io)oron[irc.freenode.net,#swagger](http://swagger.io/irc/).For\nthissample,youcanusetheapikey`special-key`totesttheauthorizationfilters.'\nversion:1.0.6\ntitle:SwaggerPetstore\ntermsOfService:http://swagger.io/terms/\ncontact:\nemail:apiteam#swagger.io\nlicense:\nname:Apache2.0\nurl:http://www.apache.org/licenses/LICENSE-2.0.html\nhost:petstore.swagger.io\nbasePath:"/v2"\ntags:\n-name:pet\ndescription:EverythingaboutyourPets\nexternalDocs:\ndescription:Findoutmore\nurl:http://swagger.io\n-name:store\ndescription:AccesstoPetstoreorders\n-name:user\ndescription:Operationsaboutuser\nexternalDocs:\ndescription:Findoutmoreaboutourstore\nurl:http://swagger.io\nschemes:\n-https\n-http\npaths:\n"/pet/{petId}/uploadImage":\npost:\ntags:\n-pet\nsummary:uploadsanimage\ndescription:''\noperationId:uploadFile\nconsumes:\n-multipart/form-data\nproduces:\n-application/json\nparameters:\n-name:petId\nin:path\ndescription:IDofpettoupdate\nrequired:true\ntype:integer\nformat:int64\n-name:additionalMetadata\nin:formData\ndescription:Additionaldatatopasstoserver\nrequired:false\ntype:string\n-name:file\nin:formData\ndescription:filetoupload\nrequired:false\ntype:file\nresponses:\n'200':\ndescription:successfuloperation\nschema:\n"$ref":"#/definitions/ApiResponse"\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\n"/pet":\npost:\ntags:\n-pet\nsummary:Addanewpettothestore\ndescription:''\noperationId:addPet\nconsumes:\n-application/json\n-application/xml\nproduces:\n-application/json\n-application/xml\nparameters:\n-in:body\nname:body\ndescription:Petobjectthatneedstobeaddedtothestore\nrequired:true\nschema:\n"$ref":"#/definitions/Pet"\nresponses:\n'405':\ndescription:Invalidinput\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\nput:\ntags:\n-pet\nsummary:Updateanexistingpet\ndescription:''\noperationId:updatePet\nconsumes:\n-application/json\n-application/xml\nproduces:\n-application/json\n-application/xml\nparameters:\n-in:body\nname:body\ndescription:Petobjectthatneedstobeaddedtothestore\nrequired:true\nschema:\n"$ref":"#/definitions/Pet"\nresponses:\n'400':\ndescription:InvalidIDsupplied\n'404':\ndescription:Petnotfound\n'405':\ndescription:Validationexception\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\n"/pet/findByStatus":\nget:\ntags:\n-pet\nsummary:FindsPetsbystatus\ndescription:Multiplestatusvaluescanbeprovidedwithcommaseparatedstrings\noperationId:findPetsByStatus\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:status\nin:query\ndescription:Statusvaluesthatneedtobeconsideredforfilter\nrequired:true\ntype:array\nitems:\ntype:string\nenum:\n-available\n-pending\n-sold\ndefault:available\ncollectionFormat:multi\nresponses:\n'200':\ndescription:successfuloperation\nschema:\ntype:array\nitems:\n"$ref":"#/definitions/Pet"\n'400':\ndescription:Invalidstatusvalue\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\n"/pet/findByTags":\nget:\ntags:\n-pet\nsummary:FindsPetsbytags\ndescription:Multipletagscanbeprovidedwithcommaseparatedstrings.Use\ntag1,tag2,tag3fortesting.\noperationId:findPetsByTags\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:tags\nin:query\ndescription:Tagstofilterby\nrequired:true\ntype:array\nitems:\ntype:string\ncollectionFormat:multi\nresponses:\n'200':\ndescription:successfuloperation\nschema:\ntype:array\nitems:\n"$ref":"#/definitions/Pet"\n'400':\ndescription:Invalidtagvalue\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\ndeprecated:true\n"/pet/{petId}":\nget:\ntags:\n-pet\nsummary:FindpetbyID\ndescription:Returnsasinglepet\noperationId:getPetById\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:petId\nin:path\ndescription:IDofpettoreturn\nrequired:true\ntype:integer\nformat:int64\nresponses:\n'200':\ndescription:successfuloperation\nschema:\n"$ref":"#/definitions/Pet"\n'400':\ndescription:InvalidIDsupplied\n'404':\ndescription:Petnotfound\nsecurity:\n-api_key:[]\npost:\ntags:\n-pet\nsummary:Updatesapetinthestorewithformdata\ndescription:''\noperationId:updatePetWithForm\nconsumes:\n-application/x-www-form-urlencoded\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:petId\nin:path\ndescription:IDofpetthatneedstobeupdated\nrequired:true\ntype:integer\nformat:int64\n-name:name\nin:formData\ndescription:Updatednameofthepet\nrequired:false\ntype:string\n-name:status\nin:formData\ndescription:Updatedstatusofthepet\nrequired:false\ntype:string\nresponses:\n'405':\ndescription:Invalidinput\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\ndelete:\ntags:\n-pet\nsummary:Deletesapet\ndescription:''\noperationId:deletePet\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:api_key\nin:header\nrequired:false\ntype:string\n-name:petId\nin:path\ndescription:Petidtodelete\nrequired:true\ntype:integer\nformat:int64\nresponses:\n'400':\ndescription:InvalidIDsupplied\n'404':\ndescription:Petnotfound\nsecurity:\n-petstore_auth:\n-write:pets\n-read:pets\n"/store/order":\npost:\ntags:\n-store\nsummary:Placeanorderforapet\ndescription:''\noperationId:placeOrder\nconsumes:\n-application/json\nproduces:\n-application/json\n-application/xml\nparameters:\n-in:body\nname:body\ndescription:orderplacedforpurchasingthepet\nrequired:true\nschema:\n"$ref":"#/definitions/Order"\nresponses:\n'200':\ndescription:successfuloperation\nschema:\n"$ref":"#/definitions/Order"\n'400':\ndescription:InvalidOrder\n"/store/order/{orderId}":\nget:\ntags:\n-store\nsummary:FindpurchaseorderbyID\ndescription:ForvalidresponsetryintegerIDswithvalue>=1and<=10.Other\nvalueswillgeneratedexceptions\noperationId:getOrderById\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:orderId\nin:path\ndescription:IDofpetthatneedstobefetched\nrequired:true\ntype:integer\nmaximum:10\nminimum:1\nformat:int64\nresponses:\n'200':\ndescription:successfuloperation\nschema:\n"$ref":"#/definitions/Order"\n'400':\ndescription:InvalidIDsupplied\n'404':\ndescription:Ordernotfound\ndelete:\ntags:\n-store\nsummary:DeletepurchaseorderbyID\ndescription:ForvalidresponsetryintegerIDswithpositiveintegervalue.\nNegativeornon-integervalueswillgenerateAPIerrors\noperationId:deleteOrder\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:orderId\nin:path\ndescription:IDoftheorderthatneedstobedeleted\nrequired:true\ntype:integer\nminimum:1\nformat:int64\nresponses:\n'400':\ndescription:InvalidIDsupplied\n'404':\ndescription:Ordernotfound\n"/store/inventory":\nget:\ntags:\n-store\nsummary:Returnspetinventoriesbystatus\ndescription:Returnsamapofstatuscodestoquantities\noperationId:getInventory\nproduces:\n-application/json\nparameters:[]\nresponses:\n'200':\ndescription:successfuloperation\nschema:\ntype:object\nadditionalProperties:\ntype:integer\nformat:int32\nsecurity:\n-api_key:[]\n"/user/createWithArray":\npost:\ntags:\n-user\nsummary:Createslistofuserswithgiveninputarray\ndescription:''\noperationId:createUsersWithArrayInput\nconsumes:\n-application/json\nproduces:\n-application/json\n-application/xml\nparameters:\n-in:body\nname:body\ndescription:Listofuserobject\nrequired:true\nschema:\ntype:array\nitems:\n"$ref":"#/definitions/User"\nresponses:\ndefault:\ndescription:successfuloperation\n"/user/createWithList":\npost:\ntags:\n-user\nsummary:Createslistofuserswithgiveninputarray\ndescription:''\noperationId:createUsersWithListInput\nconsumes:\n-application/json\nproduces:\n-application/json\n-application/xml\nparameters:\n-in:body\nname:body\ndescription:Listofuserobject\nrequired:true\nschema:\ntype:array\nitems:\n"$ref":"#/definitions/User"\nresponses:\ndefault:\ndescription:successfuloperation\n"/user/{username}":\nget:\ntags:\n-user\nsummary:Getuserbyusername\ndescription:''\noperationId:getUserByName\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:username\nin:path\ndescription:'Thenamethatneedstobefetched.Useuser1fortesting.'\nrequired:true\ntype:string\nresponses:\n'200':\ndescription:successfuloperation\nschema:\n"$ref":"#/definitions/User"\n'400':\ndescription:Invalidusernamesupplied\n'404':\ndescription:Usernotfound\nput:\ntags:\n-user\nsummary:Updateduser\ndescription:Thiscanonlybedonebytheloggedinuser.\noperationId:updateUser\nconsumes:\n-application/json\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:username\nin:path\ndescription:namethatneedtobeupdated\nrequired:true\ntype:string\n-in:body\nname:body\ndescription:Updateduserobject\nrequired:true\nschema:\n"$ref":"#/definitions/User"\nresponses:\n'400':\ndescription:Invalidusersupplied\n'404':\ndescription:Usernotfound\ndelete:\ntags:\n-user\nsummary:Deleteuser\ndescription:Thiscanonlybedonebytheloggedinuser.\noperationId:deleteUser\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:username\nin:path\ndescription:Thenamethatneedstobedeleted\nrequired:true\ntype:string\nresponses:\n'400':\ndescription:Invalidusernamesupplied\n'404':\ndescription:Usernotfound\n"/user/login":\nget:\ntags:\n-user\nsummary:Logsuserintothesystem\ndescription:''\noperationId:loginUser\nproduces:\n-application/json\n-application/xml\nparameters:\n-name:username\nin:query\ndescription:Theusernameforlogin\nrequired:true\ntype:string\n-name:password\nin:query\ndescription:Thepasswordforloginincleartext\nrequired:true\ntype:string\nresponses:\n'200':\ndescription:successfuloperation\nheaders:\nX-Expires-After:\ntype:string\nformat:date-time\ndescription:dateinUTCwhentokenexpires\nX-Rate-Limit:\ntype:integer\nformat:int32\ndescription:callsperhourallowedbytheuser\nschema:\ntype:string\n'400':\ndescription:Invalidusername/passwordsupplied\n"/user/logout":\nget:\ntags:\n-user\nsummary:Logsoutcurrentloggedinusersession\ndescription:''\noperationId:logoutUser\nproduces:\n-application/json\n-application/xml\nparameters:[]\nresponses:\ndefault:\ndescription:successfuloperation\n"/user":\npost:\ntags:\n-user\nsummary:Createuser\ndescription:Thiscanonlybedonebytheloggedinuser.\noperationId:createUser\nconsumes:\n-application/json\nproduces:\n-application/json\n-application/xml\nparameters:\n-in:body\nname:body\ndescription:Createduserobject\nrequired:true\nschema:\n"$ref":"#/definitions/User"\nresponses:\ndefault:\ndescription:successfuloperation\nsecurityDefinitions:\napi_key:\ntype:apiKey\nname:api_key\nin:header\npetstore_auth:\ntype:oauth2\nauthorizationUrl:https://petstore.swagger.io/oauth/authorize\nflow:implicit\nscopes:\nread:pets:readyourpets\nwrite:pets:modifypetsinyouraccount\ndefinitions:\nApiResponse:\ntype:object\nproperties:\ncode:\ntype:integer\nformat:int32\ntype:\ntype:string\nmessage:\ntype:string\nCategory:\ntype:object\nproperties:\nid:\ntype:integer\nformat:int64\nname:\ntype:string\nxml:\nname:Category\nPet:\ntype:object\nrequired:\n-name\n-photoUrls\nproperties:\nid:\ntype:integer\nformat:int64\ncategory:\n"$ref":"#/definitions/Category"\nname:\ntype:string\nexample:doggie\nphotoUrls:\ntype:array\nxml:\nwrapped:true\nitems:\ntype:string\nxml:\nname:photoUrl\ntags:\ntype:array\nxml:\nwrapped:true\nitems:\nxml:\nname:tag\n"$ref":"#/definitions/Tag"\nstatus:\ntype:string\ndescription:petstatusinthestore\nenum:\n-available\n-pending\n-sold\nxml:\nname:Pet\nTag:\ntype:object\nproperties:\nid:\ntype:integer\nformat:int64\nname:\ntype:string\nxml:\nname:Tag\nOrder:\ntype:object\nproperties:\nid:\ntype:integer\nformat:int64\npetId:\ntype:integer\nformat:int64\nquantity:\ntype:integer\nformat:int32\nshipDate:\ntype:string\nformat:date-time\nstatus:\ntype:string\ndescription:OrderStatus\nenum:\n-placed\n-approved\n-delivered\ncomplete:\ntype:boolean\nxml:\nname:Order\nUser:\ntype:object\nproperties:\nid:\ntype:integer\nformat:int64\nusername:\ntype:string\nfirstName:\ntype:string\nlastName:\ntype:string\nemail:\ntype:string\npassword:\ntype:string\nphone:\ntype:string\nuserStatus:\ntype:integer\nformat:int32\ndescription:UserStatus\nxml:\nname:User\nexternalDocs:\ndescription:FindoutmoreaboutSwagger\nurl:http://swagger.io\n\n
But java app throws below error.
{"timestamp":"2022-12-08T20:47:59.420+0000","status":400,"error":"Bad Request","message":"JSON parse error: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value\n at [Source: (PushbackInputStream); line: 1, column: 111]","path":"/api/v1/projects"}
The conversion is working. But needs to be put it in the right format/structure to pass it through the java app.
Will work on it and post here upon success.

Accept only defined parameters for generated Spring-Server

First, I generated a spring-server using https://editor.swagger.io/.
The spring-server works quite well, but ignores these parameters that were not defined by me. So if I send a request to the server with the following JSON,
{
"art": "PK",
"termin": "2019-12-31",
"betrag": 120000,
"test": "test"
}
then I want to get an error, because the parameter "test" is not defined in my swagger.
My swagger code looks like this:
openapi: 3.0.1
info:
...
...
paths:
/vorgang:
post:
tags:
- vorgang
summary: Adds a vorgang
description: Adds a vorgang
operationId: addVorgang
requestBody:
description: procedure object
content:
application/json:
schema:
$ref: '#/components/schemas/Vorgang'
required: true
...
...
components:
schemas:
Vorgang:
type: object
properties:
art:
type: string
enum:
- PK
- FK
termin:
type: string
format: date
betrag:
type: number
format: double
required:
- art
- termin
- betrag

Schema error at paths should NOT have additional properties in SWAGGER

Please help me to solve this issue
paths: 'sepa/sct/{OriginatorAccount}':
post:
tags:
- SCT Initiation
summary: SCT Initiation
description: ''
operationId: doSEPASCTInit
parameters:
- name: OriginatorAccount
in: path
description: Originator Account
required: true
type: string
- in: body
description: Input Content
name: body
required: false
schema:
$ref: '#/definitions/MandateInfo'
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/MandateInfo'
'400':
description: Operation failed
default:
description: Alert details added successfully.
Error:
Schema error at paths should NOT have additional properties
additionalProperty: sepa/sct/{OriginatorAccount}
Endpoint paths must begin with a forward slash /:
/sepa/sct/{OriginatorAccount}

Gets duplicated mapping key error using openapi 3.0

I am trying to define my APIs using openapi version 3.0.0. I've generated following YAML file:
openapi: 3.0.0
info:
title: My YAML
description: My YAML
version: 1.0.0
servers:
- url: http://my.server.url
paths:
/v1/service/uri:
post:
summary: Getting some information.
parameters:
- name: Content-Type
in: header
description: Content type of request body.
required: true
style: simple
explode: false
schema:
type: string
- name: Host
in: header
description: Originate host which returns the response.
required: false
style: simple
explode: false
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyPostRequest'
example:
my_name: "zizi"
my_age: 29
required: true
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MyPostResponse'
components:
schemas:
MyPostRequest:
type: object
properties:
my_name:
type: string
my_age:
type: integer
format: int32
MyPostResponse:
type: object
properties:
status:
type: integer
format: int32
When I copy/paste these lines into Swagger Editor, it gives me duplicated mapping key error on line 19; it is for section description of parameter Content-Type.
I have studied openapi documentation, but I didn't see anything wrong with my YAML file.
I am not sure why you get that error, I tried to find out in which language Swagger is written, as there are several YAML parsers out there that are known to have problems, but couldn't easily determine that using google or wikipedia.
You don't have any duplicate keys in your file, but it is invalid (i.e. not valid YAML) because of the indentation of the key content (the second occurrence, the one under paths →
/v1/service/uri → post → responses → 200), that should be aligned with
description as that key cannot have a value node that is both a scalar (OK) as well as a mapping node content: ....

OpenAPI-Specification 2.0 a post with body AND header

I want to send a object in a post but with a api key.
How can I describe this in OpenAPI-Specification 2.0?
I tried this (a subset in yaml):
paths:
/eau:
post:
tags:
- Pets
summary: Send a pet
description: 'Send a pet'
operationId: sendapet
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: pet
description: Send a pet
required: true
schema:
$ref: '#/definitions/pet'
- in: header
name: api_key
But at
- in: header
name: api_key
I get the following error:
Schema error at paths['/pet'].post.parameters[1].in
should be equal to one of the allowed values
allowedValues: body
Jump to line 36
Schema error at paths['/pet'].post.parameters[1]
should match exactly one schema in oneOf
Jump to line 36
Schema error at paths['/pet'].post.parameters[1]
should NOT have additional properties
additionalProperty: in, name
Jump to line 36
The error occurs because the header parameter is missing type.
However, API keys are related to authentication/authorization, so they should be described using the securityDefinitions and security keywords instead of a header parameter:
securityDefinitions:
apiKey:
type: apiKey
in: header
name: api_key
security:
- apiKey: []
More info: API Keys

Resources