Hello I'm pretty new to swagger and for the life of me I cannot find out how to fix the code for this error. I keep getting I'm having a duplicated mapping key and its at the bottom of the code linked below.
/channels/{country_code}/{category_slug}:
get:
tags:
- "Channels"
summary: Get a list of all channels that a company has added to spotlight for a given category
description: "This GET will return a list of all channels which are aviable to your API key and Category"
operationID: "channels_slug_GET"
parameters:
- name: "country_code"
in: "path"
description: "The country the user is located in (retrievable via Geolocation service call)"
required: true
type: "string"
- name: "category_slug"
in: "path"
description: "the category the channel(s) belong to"
required: true
type: "string"
- name: "detail"
in: "query"
description: "As channel objects are fairly large, an optional parameter detail is introduced to most Spotlight API calls. It has two possible values - lean and partial.\n lean - specifying lean will return just the _id,title,slug, description, company, company_logo,poster, spotlight_poster,videos_thumb properties for a channel.\npartial - specifying partial will return the lean data for the channel plus limited data for the channel's video, playlist, and child channels"
required: false
type: "string"
- name: "token"
in: "query"
description: "Your API access token (see /token route)"
required: true
type: "string"
responses:
200:
description: "List of all available channels"
schema:
type: "array"
items:
$ref: "#/definitions/Channel"
default:
description: "Unexpected error"
schema:
$ref: "#/definitions/Error"
you might have declared following url multiple times in the YAML.
"/channels/{country_code}/{category_slug}:"
Related
This question already has answers here:
Swagger API which is having query string
(3 answers)
Closed 2 years ago.
Can someone explain me why I have an error
Query string in path are not allowed
I use OpenApi 3.0.1 and I follow this documentation where this part of code is described. So this errors should not appear but it is, why?
/posts/{postid}?offset=0&limit=5:
get:
tags:
- posts
summary: example
description: 'example text'
operationId: getComments
parameters:
- name: postId
in: path
description: Post id
required: true
schema:
type: string
- name: offset
in: query
schema:
type: integer
description: The number of items to skip before starting to collect the result set
required: false
- in: query
name: limit
schema:
type: integer
description: The numbers of items to return
required: false
responses:
200:
description: example desc
content:
application/json:
schema:
items:
$ref: '#/components/schemas/ResponseData'
422:
description: Unprocessable entity
content: {}
Thank you.
You should write:
/posts/{postid}
instead of
/posts/{postid}?offset=0&limit=5:
The definitions of offset and limit in parameters section are enough to know these are query parameters since they already contain property in: query.
If you look at https://swagger.io/docs/specification/describing-parameters/, it is not said you should add the query string as is in the paths section of the swagger specification. (What may be confusing is that some GET requests containing a query string are shown, which may confuse you in believing you should write the query string as is in swagger specification.)
I'm getting the "bad indentation of mapping entry" error in the Swagger Editor for the OpenAPI definition below. Can anyone tell what's wrong with the code below?
responses:
'200':
description: List all applicable errors for API
headers:
x-request-received-at:
type: string
description: A datetime stamp of when the request was received
x-response-sent-at:
type: string
description: A datetime stamp of when the response was sent
schema:
$ref: '#/definitions/ErrorResponse'
default:
description: An unexpected error occurred
schema:
$ref: '#/definitions/Error'
'/funeral/{contractReference}/agreement':
get:
summary: Get the funeral policy and debit order mandate agreement for the client to sign
operationId:
- get801FuneralCoverPlanAgreementHtml
- getAUTHORITYANDMANDATEFORPAYMENTINSTRUCTIONSHTML
tags:
- "FuneralCoverService"
- "InternalAPI"
parameters:
- name: contractReference
in: "path"
required: true
type: string
description: "Unique contract reference linked to the quote and estimate prepared for the client which should be used as input to the agreements."
maxLength: 80
Parameter attributes are misaligned. All attributes must have the same indentation level.
Wrong:
parameters:
- name: contractReference
in: "path"
required: true
type: string
description: "Unique contract reference linked to the quote and estimate prepared for the client which should be used as input to the agreements."
maxLength: 80
Correct:
parameters:
- name: contractReference
in: "path"
required: true
type: string
description: "Unique contract reference linked to the quote and estimate prepared for the client which should be used as input to the agreements."
maxLength: 80
My Goal:
I am working on a set of endpoints in an application and I have a swagger 2.0 file with all of the endpoints. They are working on our test environment, but we will not yet make them available in prod.
My question is:
If I upgrade to OpenApi 3, is it possible to hide the paths I don't want to be visible in prod via the servers object?
I didn't think it was from reading the docs, but I would love to be wrong there because I'd prefer to have just one api.yml instead of one for each environment.
Thank you!
I did some testing and the answer is no.
You CAN chose which servers users can run a "try it out" test. Which is a great feature
But, you can NOT hide an endpoint based on which server is chosen from the dropdown at the top of the page. Which was the original goal
Below is the OpenAPI yaml I used in an online editor to verify. I used the online editor here: Swagger Editor and used the petstore.yaml example provided at the OpenAPI-Specification github repo as a starting point. I removed all but one endpoint to shorten things. If you are starting an open api document I would recommend visiting OpenAPI or Swagger to find documentation and a full example.
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: Try to not show get when prod server is chosen
license:
name: MIT
servers:
- url: http://prod
- url: http://test
- url: http://dev
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
servers:
- url: http://test
- url: http://dev
responses:
200:
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
I'm trying to run the following code:
/v1/test/{id}:
x-swagger-router-controller: Security
get:
operationId: test
description: "Test jwt middleware and multiple paths"
security:
- JWT: []
parameters:
- name: "id"
in: "path"
description: "ID of user"
required: true
type: "integer"
responses:
"200":
description: "Success"
schema:
$ref: "#/definitions/LoginSuccess"
"403":
description: "Access Denied"
schema:
$ref: "#/definitions/Error"
/v2/test/{id}:
$ref: "#/paths/~1v1~1test~1{id}"
But i'm receiving the following error:
API Errors:
#/paths/~1v2~1test~1{id}/$ref: Path could not be resolved:
/paths/~1v1~1test~1{id}
How can i fix this?
In this particular case what I really needed to achieve was to be able to version my API especially where not all methods had a newer version yet ie where for example /api/v1/method and /api/v2/method were still destined for the same function.
I thus solved it as follows
parameters:
- name: version
in: path
description: Version number of API
required: true
type: string
enum: &APIVERSION
- v1
- v2
In this way both v1 and v2 went to the same place. I can also add v3 etc to the enum which is reusable by different paths as enum: *APIVERSION
I'm new to Swagger. I've written the following code using Swagger Editor, but I'm getting multiple errors. I've already looked at documentation and other examples, but I'm not able to clarify the problem.
swagger: '2.0'
info:
version: "1"
title: 'Grocery Shop'
description: 'This contains the url to access all the Grocery food related information. You can also add, update or delete any food item as well based on their respective id.'
contact:
email: you#your-company.com
tags:
- name: FoodItem
description: Specifically for Food item
- name: Category
description: Specifically for the category purpose
schemes:
- https
paths:
'/findfood/{foodItemId}':
get:
tags:
- FoodItem
summary: "Find the required food"
description: "Find the food with passed food id as an argument. Make sure that passed id exist otherwise it will return an error"
operationId: findFoodWithId
produces:
- "application/json"
parameters:
- in: path
name: foodItemId
required: true
type: integer
miniumum: 1
description: The id associated with the food in the grocery shop
responses:
200:
description: "successful operation"
schema:
$ref: '#definitions/Food'
404:
description: "Food is not found
definitions:
Food:
type: "object"
properties:
foodItemId:
type: integer
format: int32
required:
- foodItemId
xml:
name: "User"
# Added by API Auto Mocking Plugin
host: "localhost:8080"
basePath: "/grocery"
The errors which I'm getting are:
Semantic error at paths./findfood/{foodItemId} Declared path parameter
"foodItemId" needs to be defined as a path parameter at either the
path or operation level Jump to line 18
Schema error at paths./findfood/{foodItemId}.get.parameters[0] is not
exactly one from
<#/definitions/parameter>,<#/definitions/jsonReference> Jump to line
28
Parser error can not read a block mapping entry; a multiline key may
not be an implicit key Jump to line 48
These errors are misleading. The actual errors are:
miniumum: 1 contains a typo - miniumum
$ref: '#definitions/Food' needs a / between # and definitions: '#/definitions/Food'
description: "Food is not found needs the ending quotation mark.