Yaml - Swagger, Duplicate mapping key - yaml

I've created a simple API, however I am having problems documenting it with Swagger as I get error: Duplicate mapping key on line 200. It is the line which says: "INVALID TOKEN" on route to update a switch: api/switches/update/{id}
I've tried creating also definition specific for update, but it was the same as Create so I think its okay to use Create definition for update as well. Not sure, if this could be a part of the problem.
swagger: "2.0"
info:
version: "1.0.0"
title: Mechanical Switches API
host: localhost:4000
basePath: /
schemes:
- http
- https
consumes:
- application/json
produces:
- application/json
- application/xml
- text/xml
- text/html
paths:
/api/welcome:
get:
description: Sharing the love with welcome message
summary: Welcome message
operationId: getWelcomeMessage
tags:
- user
responses:
'200':
description: "OK"
/api/user/register:
post:
description: Register a new user
summary: Create new user
operationId: postNewUser
tags:
- user
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
parameters:
- in: body
name: User registration
description: The user to create
schema:
$ref: "#/definitions/userCreate"
/api/user/login:
post:
description: Login as user
summary: Login user
operationId: loginExistingUser
tags:
- user
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
parameters:
- in: body
name: User login
description: The user to login
schema:
$ref: "#/definitions/userLogin"
/api/switches/create:
post:
description: Create a new switch
summary: New Switch
operationId: postNewSwitch
tags:
- switches
responses:
'200':
description: "OK"
'400':
description: "ACCESS DENIED"
'401':
description: "INVALID TOKEN"
parameters:
- in: body
name: Create switch
description: Create a new switch
schema:
$ref: "#/definitions/switchCreate"
/api/switches:
get:
description: Get all the switches
summary: All Switches
operationId: getAllSwitches
tags:
- switches
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/{id}:
get:
parameters:
- name: id
in: path
required: true
type: integer
format: int64
description: Get a specific switch
summary: Specific switch
operationId: getSingleSwitch
tags:
- switches
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/type/linear:
get:
description: Get all linear switches
summary: Linear switches
operationId: getLinearSwitches
tags:
- switches
- type linear
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/type/tactile:
get:
description: Get all tactile switches
summary: Tactile switches
operationId: getTactileSwitches
tags:
- switches
- type tactile
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/type/clicky:
get:
description: Get all clicky switches
summary: Clicky switches
operationId: getClickySwitches
tags:
- switches
- type clicky
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/mount/5pin:
get:
description: Get all switches with 5-pin mount
summary: All 5-pin
operationId: getAll5pin
tags:
- switches
- 5pin
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/mount/3pin:
get:
description: Get all switches with 3-pin mount
summary: All 3-pin
operationId: getAll3pin
tags:
- switches
- 3pin
responses:
'200':
description: "OK"
'400':
description: "NOT OK"
/api/switches/update/{id}:
put:
parameters:
- name: id
in: path
required: true
type: integer
format: int64
description: Update a specific switch
summary: Update switch
operationId: updateSwitch
tags:
- switches
- update
responses:
'200':
description: "OK"
'400':
description: "ACCESS DENIED"
'401':
description: "INVALID TOKEN"
parameters:
- in: body
name: Update existing switch
description: Update a switch
schema:
$ref: "#/definitions/switchCreate"
/api/switches/delete/{id}:
delete:
parameters:
- name: id
in: path
required: true
type: integer
format: int64
description: Delete a specific switch
summary: Delete switch
operationId: deleteSwitch
tags:
- switches
- delete
responses:
'200':
description: "OK"
'400':
description: "ACCESS DENIED"
'401':
description: "INVALID TOKEN"
definitions:
userCreate:
properties:
userName:
type: string
email:
type: string
password:
type: string
required:
- userName
- email
- password
userLogin:
properties:
email:
type: string
password:
type: string
required:
- email
- password
switchCreate:
properties:
model:
type: string
brand:
type: string
switchCollection:
type: string
switchType:
type: string
actuationForce:
type: string
preTravel:
type: string
totalTravel:
type: string
stemStructure:
type: string
mount:
type: string
lifespan:
type: string
colors:
type: string
manufacturer:
type: string
required:
- model
- brand
- switchCollection
- switchType
- actuationForce
- preTravel
- totalTravel
- stemStructure
- mount
- lifespan
- colors
- manufacturer

The "duplicate mapping key" error occurs because the /api/switches/update/{id} definition contains two parameters sections:
/api/switches/update/{id}:
put:
parameters: # <------
- name: id
in: path
required: true
type: integer
format: int64
description: Update a specific switch
...
responses:
...
parameters: # <------
- in: body
name: Update existing switch
description: Update a switch
schema:
$ref: "#/definitions/switchCreate"
You need to merge the parameters into a single list:
/api/switches/update/{id}:
put:
parameters:
- name: id
in: path
required: true
type: integer
format: int64
- in: body
name: Update existing switch
description: Update a switch
schema:
$ref: "#/definitions/switchCreate"

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.

Configuring Spring Boot REST API project with yaml file

It is my first time working with Spring Boot REST API. I would like to build a Spring Boot Project with 2 microservices: UserManagement and Messaging.
I have the following yaml file for my UserManagement API endpoint:
swagger: '2.0'
info:
description: UMS Service
version: 1.0.0
title: UMS API
host: ums
basePath: /api/v1
tags:
- name: role
description: Operations about roles
- name: user
description: Operations about users
- name: login/logout
description: Operations about sessions
schemes:
- https
- http
paths:
/role:
post:
tags:
- role
summary: Create role
description: This can only be done by the logged in user.
operationId: createRole
produces:
- application/json
parameters:
- in: body
name: body
description: Created role object
required: true
schema:
$ref: '#/definitions/Role'
responses:
default:
description: successful operation
get:
tags:
- role
summary: Get role by name
description: ''
operationId: getRoleByName
produces:
- application/json
parameters:
- name: rolename
in: query
description: The name that needs to be fetched.
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Role'
'400':
description: Invalid rolename supplied
'401':
description: Not authenticated
'404':
description: Role not found
put:
tags:
- role
summary: Updated role name
operationId: updateRole
produces:
- application/json
parameters:
- name: rolename
in: query
description: name that need to be updated
required: true
type: string
- in: body
name: body
description: Updated role object
required: true
schema:
$ref: '#/definitions/Role'
responses:
'400':
description: Invalid role supplied
'401':
description: Not authenticated
'404':
description: Role not found
delete:
tags:
- role
summary: Delete role
description: This can only be done by the logged in user.
operationId: deleteRole
produces:
- application/json
parameters:
- name: rolename
in: query
description: The role that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid role supplied
'401':
description: Not authenticated
'404':
description: Role not found
/user:
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
produces:
- application/json
parameters:
- in: body
name: body
description: Created user object
required: true
schema:
$ref: '#/definitions/User'
responses:
default:
description: successful operation
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
produces:
- application/json
parameters:
- name: username
in: query
description: The name that needs to be fetched
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/User'
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUser
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Updated user object
required: true
schema:
$ref: '#/definitions/User'
responses:
'400':
description: Invalid user supplied
'401':
description: Not authenticated
'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
parameters:
- name: username
in: query
description: The name that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
/user/role:
post:
tags:
- user
summary: Assign role to user
description: This can only be done by the logged in user.
operationId: createUserRole
produces:
- application/json
parameters:
- in: body
name: body
description: Created user object
required: true
schema:
$ref: '#/definitions/UserRole'
responses:
default:
description: successful operation
get:
tags:
- user
summary: Get role by user name
description: ''
operationId: getRoleByUserName
produces:
- application/json
parameters:
- name: username
in: query
description: The name that needs to be fetched
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/UserRole'
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
put:
tags:
- user
summary: Updated user's role
description: This can only be done by the logged in user.
operationId: updateUserRole
produces:
- application/json
parameters:
- in: body
name: body
description: Updated user object with new role
required: true
schema:
$ref: '#/definitions/UserRole'
responses:
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
/session/login:
get:
tags:
- login/logout
summary: Get last login for user
description: This can only be done by the logged in user.
operationId: getLastSessionStart
produces:
- application/json
parameters:
- name: username
in: query
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Session'
'401':
description: Not authenticated
/session/logout:
get:
tags:
- login/logout
summary: Get last logout for user
description: This can only be done by the logged in user.
operationId: getLastSessionEnd
produces:
- application/json
parameters:
- name: username
in: query
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Session'
'401':
description: Not authenticated
post:
tags:
- login/logout
summary: Set logout for user
description: This can only be done by the logged in user.
operationId: setLastSessionEnd
produces:
- application/json
parameters:
- in: body
name: body
description: Set Log out data for user
required: true
schema:
$ref: '#/definitions/Session'
responses:
default:
description: successful operation
securityDefinitions:
ums_auth:
type: oauth2
authorizationUrl: 'http://ums/oauth/user'
flow: implicit
scopes:
'write:users': modify users in your account
'read:users': read user data
api_key:
type: apiKey
name: api_key
in: header
definitions:
UserRole:
type: object
properties:
username:
type: string
rolename:
type: string
Role:
type: object
properties:
rolename:
type: string
User:
type: object
properties:
username:
type: string
email:
type: string
password:
type: string
role:
type: string
Session:
type: object
properties:
username:
type: string
login:
type: number
logout:
type: number
My question is: how do I configure my UserManagement Service to communicate with this yaml file and generate its contents in a web browser? I am using Eclipse with STS3 plugin.
Thank you for any suggestions. Also, I'd be grateful to sample links to Spring Boot REST API projects with application.yml files which could help me build a simple Spring Boot REST API with 2 services.
You may need a openapi-generator-maven-plugin to read your YML file and generate an OAS (Open API specification) out of it.
Not completely tried from scratch, but check if below helps
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/oas/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<modelPackage>com.xyz....</modelPackage>
<apiPackage>com.xyz...</apiPackage>
<output>./../api</output>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</plugin>
You may reach out to the one who asked a similar question on this article, he might have tried from scratch Openapi operationid is repeated

Failing to add examples to YAML file

Purpose: Add examples to yaml file so it will be exposed in Postman collection.
I'm trying to add 2 simple example but keep getting errors. The current error is : missed comma between flow collection entries.
Can you please assist?
swagger: "2.0"
info:
description: "Test"
version: "1.4.4"
title: "my-test"
host: "somehost"
basePath: "/somepath"
schemes:
- "https"
tags:
- name: Recommend
description: helloWorld
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
produces:
"application/json"
parameters:
name: "myRequest"
in: "body"
description: "bla"
required: true
schema:
$ref: "#/definitions/myRequest"
examples: {ex1: $ref: "#/components/examples/test1" , ex2: $ref: "#/components/examples/test2" }
responses:
"204":
description: "All good"
definitions:
myRequest:
type: object
required:
- name
- lastname
properties:
name:
type: string
lastname:
type: string
components:
examples:
test1:
value:
name: test1
lastname: test1
test2:
value:
name: test2
lastname: test2
You are mixing up OpenAPI 2.0 and 3.0 syntax.
Multiple examples are supported in OpenAPI 3.0 only. The correct syntax is:
openapi: 3.0.0
...
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
requestBody: # <------
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/myRequest"
examples: # <------
ex1:
$ref: "#/components/examples/test1"
ex2:
$ref: "#/components/examples/test2"
responses:
"204":
description: "All good"
components:
schemas:
myRequest:
...
examples:
test1:
value:
name: test1
lastname: test1
test2:
value:
name: test2
lastname: test2
If you use OpenAPI 2.0 (swagger: '2.0), you can only define a single example, and this example must be specified inline, it cannot be $referenced.
swagger: "2.0"
...
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
produces:
- "application/json" # <---- Note the leading dash here
parameters:
- name: "myRequest" # <---- Note the leading dash here
in: "body"
description: "bla"
required: true
schema:
$ref: "#/definitions/myRequest"
responses:
"204":
description: "All good"
definitions:
myRequest:
type: object
required:
- name
- lastname
properties:
name:
type: string
lastname:
type: string
example: # <---- Example value for a schema
name: test1
lastname: test1

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}

Swagger Editor 3.0 How to code component schemas for java maps

I have an response schema that contains java URI, Set and Map.
I can't find any example how to code this yaml part for swagger.
How to write the URI, Set and Map part in yaml components: schemas: see below.
My response java code looks like below.
public class ShowStaticInfo {
private String Id;
private long time;
private URI poster;
private Set<Tag> tags;
private HashMap<String,Tag> objectCreated;
And the written yaml code like this.
As stated above this yaml needs to be changed.
openapi: "3.0.1"
info:
title: Mobile backend
version: 1.0.0
license:
name: Apache 2.0
servers:
- url: https://development.cybercom.com/services/6
description: Development server
- url: https://staging.cybercom.com/services
description: Staging server
- url: https://production.cybercom.com/services
description: Production server
paths:
/buildinfo:
get:
description: Returns the build information (Version and Time stamp).
operationId: getBuildInfo
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/BuildInfo'
parameters:
- in: header
name: LBPATH
schema:
type: string
/countries/{countryId}/cities/{cityId}/showinfo/static:
get:
description: Returns a list of static show information for a city.
operationId: getShowStaticInfo
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ShowStaticInfo'
parameters:
- in: path
name: countryId
required: true
schema:
type: string
- in: path
name: cityId
required: true
schema:
type: string
- in: header
name: Accept-Language
schema:
type: string
- in: header
name: LBPATH
schema:
type: string
components:
schemas:
BuildInfo:
properties:
version:
type: string
timestamp:
type: string
status:
type: string
ShowStaticInfo:
properties:
poster:
$ref: '#/components/schemas/URI'
time:
type: integer
format: int64
showId:
type: string
tags:
$ref: '#/components/schemas/Set'
showObjectCreated:
$ref: '#/components/schemas/HashMap'

Resources