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
Related
I'm trying to use Strict-Transport-Security header with API Gateway on swagger definition, but I keep getting Invalid mapping expression parameter specified: method.response.header.Strict-Transport-Security when I use:
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Strict-Transport-Security: "'max-age=31536000; includeSubdomains; preload'"
Full definition below:
openapi: 3.0.1
info:
title:APIs
version: 1.0.1
servers:
- url: "http://localhost:9001"
security:
- ApiGateway: []
paths:
/user/{id}:
get:
summary: Get user
parameters:
- in: path
name: id
required: true
schema:
type: string
format: uuid
description: return user by ID
responses:
"200":
description: user returned successfully
content:
application/json:
schema:
$ref: "#/components/schemas/User"
"400":
description: Validation failure
"500":
description: Something went wrong
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${apiLambda.Arn}/invocations
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Strict-Transport-Security: "'max-age=31536000; includeSubdomains; preload'"
passthroughBehavior: "never"
httpMethod: "POST"
type: "aws_proxy"
/user:
post:
summary: Create user
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/User"
responses:
"200":
description: User created successfully
"400":
description: Validation failure
"500":
description: Something went wrong
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${apiLambda.Arn}/invocations
responses:
default:
statusCode: "200"
passthroughBehavior: "never"
httpMethod: "POST"
type: "aws_proxy"
components:
securitySchemes:
ApiGateway:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
User:
type: object
required:
- id
- name
properties:
id:
type: string
format: uuid
example: "317d0a1d-1a44-4a47-b2d8-cbe64665591c"
description: "user ID"
name:
type: string
example: "Josiah Morrow"
description: "User name"
minimum: 1
maximum: 50
Unable to put integration response on 'GET' for resource at path '/user/{id}': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.response.header.Strict-Transport-Security]
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
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 have two API calls Login and Logout.
First call (Login) is to generate Token based on user name and password.
Second call needs token generated by first call.
How I set that token for second call using Swagger 3.0 ?
I have this yaml short code line as a starting point, if you have any welcome ideas
/auth/credential/login:
post:
tags:
- Credintial login
summary: Logs in and returns the authentication cookie
description: This can only be done by the logged in user.
operationId: createUser
security: []
responses:
'200':
description: >-
Successfully authenticated.
headers:
X-RateLimit-Limit:
schema:
type: integer
description: Request limit per hour.
Set-Cookie:
schema:
type: string
description: Get token value
content:
application/json:
schema:
$ref: '#/components/schemas/Login'
x-forwarded-for:
schema:
$ref: '#/components/schemas/Login'
'202':
description: Life is hard
content:
application/json:
schema:
$ref: '#/components/schemas/LoginRespons'
x-forwarded-for:
schema:
$ref: '#/components/schemas/LoginRespons'
'405':
description: Invalid Login
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Login'
description: Created auth object
required: true
/auth/logout:
post:
tags:
- Logout
summary: Logout a user
description: ''
responses:
'200':
description: Success
content:
'*/*':
schema:
$ref: '#/components/schemas/Logout'
'202':
description: Success Logout!
content:
'*/*':
schema:
$ref: '#/components/schemas/LogoutResponse'
'405':
description: Invalid Logout
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Logout'
description: description
I am new to right API documentation using RAML.In one example i saw a code like
resourceTypes:
- base:
get?:
responses: &standardResponses
put?:
responses: *standardResponses
post?:
responses: *standardResponses
delete?:
responses: *standardResponses
- collection:
type: base
get:
is: [showActive]
responses:
200:
body:
application/json:
schema: <<schema>>
post:
body:
application/json:
schema: <<schema>>
responses:
200:
body:
application/json:
schema: <<schema>>
So what is difference between &standardResponses and *standardResponses ?
And why we used Question mark(?) after http methods and what is the meaning when we use type: base?
&{name} - declare a block
*{name} - use the block
Simple example:
/customers:
get:
responses:
200:
headers: &commonResponseHeaders
Server-Transaction-Id:
description: Transaction id in the middleware. Can be used for debugging.
type: string
required: true
body:
example: !include examples/customers.json
schema: !include schemas/customers.json
/{customerId}:
get:
responses:
200:
description: The request was successful and a customer was found
headers: *commonResponseHeaders
404:
description: Customer was not found with `customerId = {customerId}`
headers: *commonResponseHeaders
So you don't need repeat in every response same headers.