Swagger inspector is a great tool that create openapi documentation just by giving an URL.
But it creates a yaml file and I would like to get it in PHP attributes because I mostly use PHP attributes in my application.
I'd like to be able to generate it in PHP attributes, or be able to convert the yaml to PHP attributes.
What I get:
openapi: 3.0.1
info:
title: defaultTitle
description: defaultDescription
version: '0.1'
servers:
- url: http://localhost.fr:8002
paths:
/api/package:
post:
description: Auto generated using Swagger Inspector
requestBody:
content:
application/json:
schema:
type: object
properties:
software:
type: array
items:
type: object
properties:
package:
type: string
version:
type: string
...
What I'd like:
<?php
use OpenApi\Attributes as OA;
#[OA\Post(
path: '/api/package',
requestBody: new OA\RequestBody(
description: 'Add a new package',
required: true,
content: new OA\MediaType(
mediaType: 'multipart/form-data',
schema: new OA\Schema(
properties: [
new OA\Property(
property: 'package',
type: 'string',
),
new OA\Property(
property: 'version',
type: 'string',
),
]
)
)
)
)]
class AddPackage
{
}
I am writing a load test for my application.
I would like to simulate the following steps:
login
visit several pages
submit a form within the website
I first wrote the login and visit several pages and run them successfully (no errors). When I added the code to submit form, I was getting '404/Not Found error' for the Submit Abstract transaction.
I am grateful to anyone who can provide me direction on how to solve this.
I wrote this test script using ruby then execute to convert it to .jmx file which I use to run headless test in cli.
code for login and visit several pages:
require 'ruby-jmeter'
test do
threads count: 100, rampup: 60, loops: 10, duration: 120 do
defaults domain: 'myapp.herokuapp.com', protocol: 'https'
cookies policy: 'rfc2109', clear_each_iteration: true
transaction 'Page Load Tests' do
user_defined_variables [{name: 'email', value: 'example#example.com'}, {name: 'password', value: 'Pass_w0rd'}]
visit name: 'Visit Login', url: '/users/sign_in' do
extract name: 'csrf-token', xpath: "//meta[#name='csrf-token']/#content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[#name='csrf-param']/#content", tolerant: true
extract name: 'authenticity_token', regex: 'name="authenticity_token" value="(.+?)"'
end
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit login', url: '/users/sign_in',
fill_in: {
'${csrf-param}' => '${csrf-token}',
'user[email]' => '${email}',
'user[password]' => '${password}',
'authenticity_token' => '${authenticity_token}'
}
visit name: 'Welcome Page', url: '/static_pages/welcome'
visit name: 'New Abstract Page', url: '/users/2/abstracts/new'
visit name: 'My Profile Page', url:'/users/2/participations/1/profile'
visit name: 'My Own Abstract Page', url:'/users/2/participations/1/abstracts/1'
view_results_in_table
aggregate_report
end.jmx
code for login, visit pages and submit form:
require 'ruby-jmeter'
test do
threads count: 100, rampup: 60, loops: 10, duration: 120 do
defaults domain: 'myapp.herokuapp.com', protocol: 'https'
cookies policy: 'rfc2109', clear_each_iteration: true
transaction 'Page Load Tests' do
user_defined_variables [{name: 'email', value: 'example#example.com'}, {name: 'password', value: 'Pass_w0rd'}]
visit name: 'Visit Login', url: '/users/sign_in' do
extract name: 'csrf-token', xpath: "//meta[#name='csrf-token']/#content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[#name='csrf-param']/#content", tolerant: true
extract name: 'authenticity_token', regex: 'name="authenticity_token" value="(.+?)"'
end
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit login', url: '/users/sign_in',
fill_in: {
'${csrf-param}' => '${csrf-token}',
'user[email]' => '${email}',
'user[password]' => '${password}',
'authenticity_token' => '${authenticity_token}'
}
visit name: 'Welcome Page', url: '/static_pages/welcome'
visit name: 'New Abstract Page', url: '/users/2/abstracts/new'
visit name: 'My Profile Page', url:'/users/2/participations/1/profile'
visit name: 'My Own Abstract Page', url:'/users/2/participations/1/abstracts/1'
transaction 'Submit Abstract' do
visit name: 'New Abstract Page', url: '/users/2/abstracts/new' do
extract name: 'csrf-token', xpath: "//meta[#name='csrf-token']/#content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[#name='csrf-param']/#content", tolerant: true
extract name: 'authenticity_token', regex: 'name="authenticity_token" value="(.+?)"'
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit Abstract', url: '/users/2/abstracts/new',
fill_in: {
'${csrf-param}' => '${csrf-token}',
'abstract[title]' => 'Lorem Ipsum',
'abstract[main_author]' => '2',
'abstract[co_authors][]' => ["", "1", "3"],
'abstract[corresponding_author_email]' => '${email}',
'abstract[keywords]' => 'word, words',
'abstract[body]' => 'The test directive is a root point, where all the magic starts. Then, using threads method we are telling JMeter what number of users we want to use. The defaults command allows us to specify default options for all our http requests. And, finally,cookies indicates that we need to store cookies and send them with each request.',
'abstract[references]' => '1\r\n2\r\n3',
'authenticity_token' => '${authenticity_token}'
} do
assert 'contains' => 'Abstract submission completed.'
assert 'contains' => 'Lorem Ipsum'
end
end
end
view_results_in_table
aggregate_report
end.jmx
UPDATE PER #DMITRI T SUGGESTION:
EDITED TEST
REQUEST HEADER:
Browser:
Jmeter:
REQUEST BODY:
Browser:
Jmeter:
RESULT: STILL 404 error for the Submit Abstract Transaction
HTTP Status 404 means that the server cannot find the requested resource so most probably your URL is wrong.
So double check that the URL of https://myapp.herokuapp.com/users/2/abstracts/new returns a valid response for the logged in user and if it does - capture the request for creating the new "abstract" using your browser developer tools
Then in JMeter GUI:
Change number of threads, ramp-up period and loop count to 1 in the https://jmeter.apache.org/usermanual/component_reference.html#Thread_Group
Add Debug Post-Processor to your Test Plan (it will allow you to see the values of JMeter Variables)
Add View Results Tree listener to your Test Plan (it will allow to see the request and response details)
Run your test in JMeter GUI, inspect Submit Abstract request details and cross-check it with what you see in the browser developer tools - the requests must be absolutely the same (apart from dynamic parameters)
Fix your JMeter configuration so it would send exactly the same request and it should resolve your issue.
I can create a new stripe connect account with
require 'stripe'
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
Stripe::Account.create({
type: 'express',
country: 'US',
email: 'jenny.rosen#example.com',
capabilities: {
card_payments: {requested: true},
transfers: {requested: true},
},
})
I understand I can provide that account with a test address using a 'token' called address_full_match. But I have no idea what that 'token' is nor how to use it in ruby code, that is, I do not know what ruby code to write to use this 'token'
I tried the obvious to generate/access a token:
Stripe::address_full_match
NoMethodError: undefined method `address_full_match' for Stripe:Module
from (pry):10:in `__pry__'
How can I use this 'token' in ruby code (specifically, in Stripe::Account.create()) ?
Further attempts
Attempt 1
If we search the documentation for any instances of enabled": true it returns zero results, but if we search for instances of enabled": false we get 16 results. So the documentation doesn't provide a single example creating an account with either charges_enabled: true, nor with payouts_enabled: true, which is surprising since that's predominantly what developers want to do - create account functional accounts (not dysfunctional ones)
Attempt 2
I tried placing address_full_match in the 'Address line 1' field of the web UI. But it still results in payments_enabled: false
You will get it from StripeCheckout JS client
you have to include js script from stripe
<script src="https://checkout.stripe.com/checkout.js"></script>
Again create a script and In the js script you have to write like
StripeCheckout.configure({
key: "<%= Rails.configuration.stripe[:publishable_key] %>",
locale: "auto",
name: "XYZ",
description: "XYZ Description",
email: "<%= current_user.email %>",
billingAddress: true,
zipCode: true,
token: function(token) {
console.log("Stripe Token : " + token.id)
}
});
Screenshot of Swagger Editor & code
Hi, I am new to API testing and Swagger and am getting this parser error message in the Swagger Editor and I am having problems locating the problem.
Bellow is a copy paste of the code.
The error message is "bad indentation of a mapping entry" and is displayed where --> in: "path".
I followed this YouTube Tutorial --> https://www.youtube.com/watch?v=CoUl9_NWdqQ
swagger: '2.0'
info:
version: 'v1.0'
title: 'Random'
# Added by API Auto Mocking Plugin
host: virtserver.swaggerhub.com
basePath: /GroovySalmon/DOITNOW/v1.0
schemes:
- https
paths:
/vehicles/{id}/data_request/drive_state:
get:
operationId: "drive_state"
description: "Returns the driving and position state of the vehicle"
parameters:
**-name: "id"**
in: "path"
description: "The ID number of the car"
required: true
type: "String"
responses:
200:
description: "Success"
schema:
properties:
shift_state:
type: "String"
example: "sport"
speed:
type: "number"
format: "double"
example: 94.5
latitude:
description: "degrees north of the equator"
type: "number"
format: "double"
example: 37.345
longitude:
description: "degrees west of the prime meridian"
type: "number"
format: "double"
example: 122.1243
heading:
description: "integer compass heading"
type: "integer"
format: "int32"
minimum: 0
maximum: 359
example: 4
gps_as_of:
description: "unix timestamp of gps fix"
example: "1234934991232"
Change
type: "String"
to
type: "string"
Note the lowercase "s" in "string".
All OpenAPI type values are lowercase and case-sensitive.
Also, make sure there are spaces after - in parameter definitions (and in YAML lists in general), and that the indentation is correct:
- name: "id"
in: "path"
...
This question already has answers here:
Post a json body with swagger
(1 answer)
How to describe this POST JSON request body in OpenAPI (Swagger)?
(3 answers)
Closed 2 years ago.
swagger: "2.0"
info:
version: "1.0.0"
title: "CCA API"
host: localhost:1337
basePath: /v1
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/user/login:
post:
description: Access a user account
summary: User Account Access
operationId: loginAccount
parameters:
- name: email
dataType: string
in: body
required: true
description: Your email
- name: password
dataType: string
in: body
required: true
description: Your password
responses:
"200":
description: Successfully signed in
schema:
type: object
properties:
email:
type: string
firstName:
type: string
lastName:
type: string
token:
type: string
userType:
type: string
401:
description: Invalid email or password.
Which is a correct way to write yaml file?
I have this error: "Not a valid parameter definition"
in each declaration of the parameters...
I would also like to know the correct way to integrate Sails JS with Swagger?
As Vantroys said dataType is not the correct key. It's type.
But in this case you try to define an post method and need to define some type of input data, like in the example below.
Have look at the pet store example from swagger itself:
https://editor.swagger.io/
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
Concerning your parameters : I think you have to use "type", and not "dataType" :
parameters:
- name: email
type: string
in: body
required: true
description: Your email
- name: password
type: string
in: body
required: true
description: Your password