I have pretty common case where GET Endpoint should accept pagination and sorting parameters. REST Contract is writing with OpenAPI. And the aim is to be able to receive something like such an object:
components:
schemas:
Paging:
type: object
properties:
page:
type: integer
limit:
type: integer
sorting:
$ref: '#/components/schemas/Sorting'
Sorting:
type: object
properties:
attr:
type: array
items:
$ref: '#/comonents/schemas/SortingAttr'
SortingAttr:
type: object
properties:
sortyBy:
$ref: '#/components/schemas/SortyByEnum'
direction:
$ref: '#/components/schemas/SortDirectionEnum'
SortByEnum:
type: string
enum: [ PROP1, PROP2 ]
SortDirectionEnum:
type: string
enum: [ ASC, DESC ]
As a workaround I use POST Request and provide object 'Paging' as a body and thus get this nested object in controller. However, this does not work as query parameter for GET request.
Is there another way to get following query params?
page
limit
array of sorting params: [{sortParam, sortDirection}]
Related
I need an example for an email with some complext content(json format) and multiple array attachment. The attachments should be able to be of any format. so far I have searched everywhere and I am starting to think it may not be possible. what I would like is something like below:
/somepath:
put:
summary: sends an email
description: Send an email
operationId: send-mail
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/data.SomeData'
type: object
properties:
format: binary
attachment:
content:
multipart/form-data:
schema:
properties:
my-attachment:
type: array
items:
type: string
format: binary
This is what I have tried to do in swagger 2.0, which looks more realistic and swagger 2.0 does not accept:
/somePath:
put:
consumes:
- multipart/form-data
description: Send an email
operationId: send-mail
parameters:
- description: The Data model
in: body
name: someData
required: true
schema:
$ref: '#/definitions/data.someData'
type: object
- description: Base 64 upload attachment
in: formData
name: file
type: array
items:
type: string
format: binary
Found the Answer for Openapi 3.0 :
multipart/form-data:
schema:
type: object
properties:
body:
$ref: '#/components/schemas/data.SomeData'
file:
type: array
description: Base 64 upload attachment
items:
type: string
format: binary
required:
- body
schema ID is really bothering me.
The logic I want is:
Open a modal popup window in grid A, and add the selected data (select row) in the modal popup as a new row in grid A.
Finally, we confirm this via the saveChanges () event.
This behavior works very nicely, but there are some things I don't understand.
schema: {
data : 'list' ,
model: {
id: 'prodNo',
fields: {
orderDSeq: { editable: false },
orderNo: { editable: false },
prodNo: {type: 'string'},
mtrlQt: {type: 'string'},
prodSize: {type: 'string'},
prodUnit: {type: 'string'},
orderQnt: {type: 'string'},
presentStkQnt: {type: 'string'},
prodPrice: {type: 'string'},
totalPrice: {type: 'string'},
spplLimitDt: {type: 'string'},
reMark: {type: 'string'}
Above is the schema of A grid, And
schema: {
data: 'list',
model: {
id: 'key',
fields: {
prodNm: {type: 'string'},
orderNo: {type : 'string'},
prodNo: { type: 'string' },
mtrlQt: { type: 'string' },
prodSize: { type: 'string' },
sStk: { type: 'string' },
prodPrice: { type: 'string' }
Above is the modal popup schema.
It's a bit small, but it has a very similar structure.
The key question here.
This is not about A Grid, but about the schema ID of the modal popup.
Any changes made to Grid A did not affect this operation.
As far as I know, "Key(ID)" in the schema model should be one of the values of the actual fields.
However, if you set this to one of the actual fields, the saveChanges () event will not detect grid changes. (ex, id:prodNm, id:prodNo... I did it because some of the information told me to exclude the Key data from the field, but the results were the same.)
However, if I specify the ID value as an arbitrary random character, this works very nicely.
Any word like "id:key, id:sound, id:stick .." This logic is performed for any characters that do not exist in the field.
Please make me understand this behavior.
How does model ID affect this logic?
ID is an important key for detecting changes, but I can't understand this groundless behavior.
I'd like to import an open-api 3.0 yaml file into postman, v. 7.1.1.
I am generating OpenApi 3.0 docs in Laravel using darkaonline/l5-swagger. The generated open-api 3.0 yaml file produces an error-free output when pasted into editor.swagger.io. The api is being written in accordance with json:api spec (or is intended to be).
When the file is imported to postman (v 7.1.1) this error is generated : "Error while importing Open API 3.0: Could not import" All the documentation I've read says that postman now supports open api 3.0. I tried loading OpenApi 3.0 yaml examples from Zircote's github, and they imported just fine. They are much less complex than our docs, though.
Code excerpt: Warning this is a lot, but I feel like I needed to give enough context(It's actually a small chunk of the full doc--the file is 2000 lines long):
info:
title: 'NAME OF MY API'
version: 1.0.0
servers:
-
url: 'https://api.API.com/v1'
paths:
/accounts:
get:
tags:
- accounts
summary: 'list accounts'
operationId: 'App\Http\Controllers\v1\AccountsController::index'
responses:
200:
description: 'A list of accounts'
content:
application/vnd.api+json:
schema:
required:
- data
properties:
data:
description: 'Show all accounts for this request.'
type: array
items:
properties:
type:
type: string
id:
type: string
attributes:
$ref: '#/components/schemas/account'
relationships:
properties:
persons:
type: array
items:
$ref: '#/components/schemas/relationship'
type: object
links:
$ref: '#/components/schemas/relationship/properties/links'
type: object
meta:
$ref: '#/components/schemas/meta'
links:
$ref: '#/components/schemas/links'
type: object
401:
description: 'Unauthorized access'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
404:
description: 'No records found'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
servers:
-
url: 'https://api.API.com/v1'
post:
tags:
- accounts
summary: 'new account'
operationId: 'App\Http\Controllers\v1\AccountsController::store'
responses:
201:
description: 'Successful save'
401:
description: 'Unauthorized access'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
400:
description: 'Bad request, save failed'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
servers:
-
url: 'https://api.API.com/v1'
'/accounts/{id}':
get:
tags:
- accounts
summary: 'get one account'
operationId: 'App\Http\Controllers\v1\AccountsController::show'
parameters:
-
name: id
in: path
required: true
schema:
type: string
responses:
200:
description: 'An account object'
content:
application/vnd.api+json:
schema:
properties:
type:
description: 'Display the specified resource.'
type: string
id:
description: 'Display the specified resource.'
type: string
attributes:
$ref: '#/components/schemas/account'
relationships:
description: 'Display the specified resource.'
properties:
persons:
description: 'Display the specified resource.'
type: array
items:
$ref: '#/components/schemas/relationship'
type: object
links:
$ref: '#/components/schemas/relationship/properties/links'
type: object
401:
description: 'Unauthorized access'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
404:
description: 'Record not found'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
servers:
-
url: 'https://api.API.com/v1'
delete:
tags:
- accounts
summary: 'remove account'
operationId: 'App\Http\Controllers\v1\AccountsController::destroy'
parameters:
-
name: id
in: path
required: true
schema:
type: string
responses:
200:
description: 'An account object'
401:
description: 'Unauthorized access'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
405:
description: 'Method not allowed'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
400:
description: 'Bad request, save failed'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
servers:
-
url: 'https://api.API.com/v1'
patch:
tags:
- accounts
summary: 'update account'
operationId: 'App\Http\Controllers\v1\AccountsController::update'
parameters:
-
name: id
in: path
required: true
schema:
type: string
responses:
200:
description: 'An account object'
401:
description: 'Unauthorized access'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
400:
description: 'Bad request, save failed'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/error-response'
servers:
-
url: 'https://api.API.com/v1'
components:
schemas:
account:
title: 'account object'
description: 'A single account object.'
required:
- ur_account_id
- name
- address1
- city
- state
- zip
- country_code
- phone
- email
properties:
_id:
description: 'Unique identifier to include in path to get a single record.'
type: string
ur_account_id:
description: 'The unique account ID.'
type: string
name:
description: 'The name associated with the account'
type: string
address_1:
description: 'The street address for the account.'
type: string
address_2:
description: 'The Suite number, PO Box Number, Floor Number, etc, for the account.'
type: string
city:
description: 'The city the account is resides in.'
type: string
state:
description: 'The two letter abbreviation of the state the account resides in'
type: string
zip:
description: 'The Postal Code the account resides in.'
type: string
country_code:
description: 'Country code associated with the account.'
type: string
phone:
description: 'The phone number associated with the account.'
type: string
phone_alpha:
description: 'The phone number associated with the account.'
type: string
email:
description: 'Email associated with the account'
type: string
require_po:
description: 'Whether the account requires a PO.'
type: string
status:
description: 'Status of current account'
type: boolean
tags:
-
name: accounts
description: 'Everything about accounts'
externalDocs:
description: 'Find out more'
url: 'http://admin.API.com/documents' ```
The problem is that within each path object’s servers object, I defined only the base URL, assuming for some reason that the base URL would be concatenated with the path. If you define a server object within the path object, you have to use the FULL URL for the endpoint. It was giving me errors specifically with /{id} endpoints because I defined a path variable that not present in the servers object
What does this error below mean? (Running in Swagger Editor)
Schema error should NOT have additional properties additionalProperty:
/buildinfo, /clearcache,
/countries/{countryId}/cinemas/{theatreid}/screens/{screenid}/layout,
/countries/{countryId}/cinemas/{theatreid}/screens Jump to line 0
Below is my yaml file.
openapi: "3.0.1"
info:
title: Mobile backend
version: 1.0.0
license:
name: Apache 2.0
paths:
/buildinfo:
get:
description: Returns the build information (Version and Time stamp).
operationId: getBuildInfo
parameters:
- name: LBPATH
in: header
/clearcache:
get:
description: Clears the mobile backends cache (You need to be Admin to do this call)
operationId: clearCache
parameters:
- name: LBPATH
in: header
/countries/{countryId}/cinemas/{theatreid}/screens/{screenid}/layout:
get:
description: Returns a list of Auditoriums that is currently running in a specific city. Ordered by movie name in ascending order.
operationId: getScreenLayout
parameters:
- name: theatreid
in: path
- name: screenid
in: path
- name: seatwidth
in: query
- name: seatheight
in: query
- name: Accept-Language
in: header
- name: LBPATH
in: header
/countries/{countryId}/cinemas/{theatreid}/screens:
get:
description: Returns a list of Auditoriums that is currently running in a specific city. Ordered by movie name in ascending order.
operationId: getAuditoriumsInTheatre
parameters:
- name: theatreid
in: path
- name: Accept-Language
in: header
- name: LBPATH
in: header
components:
schemas:
ProfileNotifications:
properties:
iWantEmails:
type: boolean
iWantSMS:
type: boolean
iWantPushNotifications:
type: boolean
OfferActivateRequest:
properties:
offerId:
type: int64
osType:
$ref: '#/components/schemas/OSType'
mobileId:
type: string
activationDate:
type: date
Customer:
properties:
type:
$ref: '#/components/schemas/TicketType'
count:
type: int32
Profile$ProfileStatus:
properties:
Booking:
properties:
profileId:
type: string
remoteEntityIds:
type: array
items:
string
customers:
type: array
items:
$ref: '#/components/schemas/Customer'
showId:
type: string
seatsUnnumberedCount:
type: int32
ProfileFriend:
properties:
name:
type: string
profileReferenceCode:
type: string
OfferConsumeRequest:
properties:
offerId:
type: int64
osType:
$ref: '#/components/schemas/OSType'
mobileId:
type: string
Profile:
properties:
language:
type: string
children:
type: array
items:
int32
city:
type: string
memberSince:
type: date
status:
$ref: '#/components/schemas/Profile$ProfileStatus'
firstName:
type: string
lastName:
type: string
phonenumber:
type: string
socialSecurityNumber:
type: string
acceptedTermsAndConditionsOn:
type: date
acceptedGeneralDataProtectionRegulationOn:
type: date
profileId:
type: string
currentLevelId:
type: string
aztecCode:
type: string
allowSfBioToSendNewsletters:
type: boolean
favoriteMovies:
type: array
items:
string
spendingPointsWillExpire:
type: array
items:
$ref: '#/components/schemas/SpendingPoint'
friends:
type: array
items:
$ref: '#/components/schemas/ProfileFriend'
userEmail:
type: string
providerId:
type: int32
providerToken:
type: string
memberNumber:
type: string
userHasVerifiedThisAccount:
type: boolean
loyaltyLevelId:
type: string
loyaltyLevelName:
type: string
loyaltyLevelSince:
type: date
loyaltyLevelExpiration:
type: date
loyaltyPointsAvailableForSpending:
type: int32
loyaltyMoviesLeftToTheNextLevel:
type: int32
loyaltyPointsLeftToTheNextLevel:
type: int32
loyaltyPointsLevelToGetGoldMember:
type: int32
loyaltyMovieLevelToGetGoldMember:
type: int32
loyaltySpendingPointsExpireDate:
type: date
loyaltySpendingPointsExpireAmount:
type: int32
oldClubCardNumber:
type: string
loyaltyEndDate:
type: date
CardType$Type:
properties:
purchaseCard:
type: boolean
Card:
properties:
type:
$ref: '#/components/schemas/CardType$Type'
number:
type: string
requestedAmount:
type: int32
deductedAmount:
type: int32
isUsed:
type: boolean
balance:
type: int32
errorCode:
type: int32
LockSeats:
properties:
seatKeys:
type: array
items:
$ref: '#/components/schemas/SeatKey'
auditoriumSys99Code:
type: string
dateTime:
type: int64
SeatKey:
properties:
seatRow:
type: int32
seatSection:
type: string
seatId:
type: int32
ShowKey:
properties:
Payment:
properties:
email:
type: string
profileId:
type: string
serialVersionUID:
type: int64
ticketTypes:
type: array
items:
$ref: '#/components/schemas/TicketType'
easyPayment:
$ref: '#/components/schemas/EasyPayment'
reservationPayment:
type: boolean
reservationNumber:
type: string
cards:
type: array
items:
$ref: '#/components/schemas/Card'
showKey:
$ref: '#/components/schemas/ShowKey'
bookingId:
type: int32
redirectUrl:
type: string
transactionId:
type: string
customers:
type: array
items:
$ref: '#/components/schemas/Customer'
goggleCount:
type: int32
paymentResponseCode:
type: string
Reservation:
properties:
email:
type: string
profileId:
type: string
cards:
type: array
items:
$ref: '#/components/schemas/Card'
bookingId:
type: int32
customers:
type: array
items:
$ref: '#/components/schemas/Customer'
msisdn:
type: string
showId:
type: string
goggleCount:
type: int32
totalFee:
type: int32
adultTicketCount:
type: int32
childTicketCount:
type: int32
pensionerTicketCount:
type: int32
plusAndVipTicketCount:
type: int32
totalPlusAndVipTicketCost:
type: int32
SpendingPoint:
properties:
expireDate:
type: date
amount:
type: int32
ProfileMovies:
properties:
movies:
type: array
items:
string
OSType:
properties:
ProfileCinemas:
properties:
cinemas:
type: array
items:
string
LockSeatsUnnumbered:
properties:
auditoriumSys99Code:
type: string
dateTime:
type: int64
nrOfSeats:
type: int32
TicketType:
properties:
EasyPayment:
properties:
panHash:
type: string
truncPan:
type: string
userAccept:
type: boolean
The indentation of paths is wrong:
paths:
/buildinfo: # <-----
get:
It should be:
paths:
/buildinfo:
get:
Your spec also has many other errors, such as missing schema for parameters, missing responses in operations, wrong type values in schemas, etc. Follow the hints in the Swagger Editor to fix the errors.
But I still get error I don't understand. "Schema error at paths" "should be array"
parameters:
name: LBPATH
in: header
schema:
type: string
style: simple
parameters is an array of parameters. In YAML, array items are formatted with the leading -. Also style is a parameter attribute, not schema attribute.
parameters:
- name: LBPATH
in: header
schema:
type: string
style: simple
To learn more about OpenAPI 3.0 syntax and how to format things, check out this guide: https://swagger.io/docs/specification/basic-structure/
I was wondering if there is any way to pass an array of objects as extra param of model.save method ?
For simple types params seem to work.
Ext.define('RightGridModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'rightText', type: 'string'},
{name: 'digit',type:'int'}
]
});
var mod = Ext.create('RightGridModel');
mod.set('rightText', 'some text');
mod.save({
url: "Home/Insert",
params: {
par: 'additional parameter'
}
});
However if I want to send and array as an extra param,(of course I changed server side function to be approperiate ) par variable is an empty list. Here is a code I use to send an model and array
mod.save({
url: "Home/Insert",
params: {
par: Ext.encode(array)
}
});
Is there any way to send a model and an array as extra parameter ?? What is the best way to achieve that ?
Check out getParams function of Proxy class. You can just subclass existing proxy classes into your own and use it while communicating with your backend.