Serverless-aws-documentation swagger parameters - serverless

When I use serverless openapi generate the resulting openapi.yaml contains no parameters
I have tried parameters instead queryParams as well as pathParams
functions:
get:
handler: retransmit/get.get
events:
- http:
path: retransmit/{game_id}/{camera_id}
method: get
cors: true
documentation:
summary: "Fetch frame_id"
description: "Fetch frame_id ranges for given grab_id and camera_id"
queryParams:
- name: "game_id"
description: "app id"
required: true
- name: "camera_id"
description: "user id or 'my'"
required: true
error:
Semantic error at paths./retransmit/{game_id}/{camera_id}
Declared path parameter "game_id" needs to be defined as a path parameter at either the path or operation level
Jump to line 27
Semantic error at paths./retransmit/{game_id}/{camera_id}
Declared path parameter "camera_id" needs to be defined as a path parameter at either the path or operation level
Jump to line 27

Change queryParams to pathParams
functions:
get:
handler: retransmit/get.get
events:
- http:
path: retransmit/{game_id}/{camera_id}
method: get
cors: true
documentation:
summary: "Fetch frame_id"
description: "Fetch frame_id ranges for given grab_id and camera_id"
pathParams:
- name: "game_id"
description: "app id"
required: true
- name: "camera_id"
description: "user id or 'my'"
required: true

Related

How to define an URL ending with an integer?

The OpenAPI definition below will generate the URL as http://localhost:9200/GetCourse?id=1. How to change the definition to generate the URL as http://localhost:9200/GetCourse/1?
/GetCourse:
get:
summary: Get Courses
description: >
The GetCourse details.
tags:
- Content information
parameters:
- name: id
in: query
description: The ID of the HEI being queried
required: true
type: integer
responses:
'200':
description: An array of courses
schema:
$ref: '#/definitions/Courses'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
Change the parameter location (in) from query to path.
Add /{id} at the end of the path name.
paths:
/GetCourse/{id}: # <----
get:
...
parameters:
- name: id
in: path # <----
description: The ID of the HEI being queried
required: true
type: integer

Required property per path and method

Consider the following sample specification:
swagger: '2.0'
info:
title: stackoverflow question
version: '1.0'
paths:
/websites:
post:
parameters:
- in: body
name: website
required: true
schema:
$ref: '#/definitions/website'
responses:
201:
description: Website created
/websites/{id}:
patch:
parameters:
- name: 'id'
in: 'path'
type: 'integer'
required: true
- in: body
name: fields
required: true
schema:
$ref: '#/definitions/website'
responses:
200:
description: Website updated
definitions:
website:
type: object
required:
- fieldB
properties:
fieldA:
type: string
readOnly: true
fieldB:
type: string
format: date-time
fieldC:
type: string
format: date-time
The fieldB property is required for both POST and PATCH methods. Is it possible to make it required only for a single path and method without having to specify two different model definitions?
If not, what would be a good solution to achieve this?

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

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

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

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

Create my own type in Swagger

I Have this YAML code of swagger and I need to create my own type (named MyOwnType).
If I use "MyOwnType" a compilation error occurs.
paths:
/in/total:
get:
summary: My summary.
description: My description.
parameters:
- name: total
in: query
description: Total.
required: true
type: MyOwnType # -- THIS LINE OCCURS ERROR --
format: MyOwnType
responses:
201:
description: Respose
schema:
$ref: '#/definitions/MyOwnType'
definitions:
MyOwnType:
properties:
var:
type: string
description: data.
I created a definition "MyOwnType" and I can use like that: "$ref: '#/definitions/MyOwnType'" in schema.
But how can I use the "MyOwnType" definition on a parameter type?
A query parameter can not have a JSON Schema. If you want to have schema for your parameter you should change in of your parameter to body or formData and use schema key:
swagger: '2.0'
info:
version: 0.0.0
title: '<enter your title>'
paths:
/in/total:
get:
summary: My summary.
description: My description.
parameters:
- name: total
in: body
description: Total.
required: true
schema:
$ref: '#/definitions/MyOwnType'
responses:
201:
description: Respose
schema:
$ref: '#/definitions/MyOwnType'
definitions:
MyOwnType:
properties:
var:
type: string
description: data.

Resources